diff --git a/forward_engineering/api.js b/forward_engineering/api.js index d783370..0a6db79 100644 --- a/forward_engineering/api.js +++ b/forward_engineering/api.js @@ -2,9 +2,9 @@ const { GlueClient, CreateDatabaseCommand, CreateTableCommand, GetDatabasesCommand } = require('@aws-sdk/client-glue'); const { hckFetchAwsSdkHttpHandler } = require('@hackolade/fetch'); -const { getApiStatements } = require('./helpers/awsCliScriptHelpers/applyToInstanceHelper'); -const { generateScript } = require('./helpers/generateScript'); -const { generateContainerScript } = require('./helpers/generateContainerScript'); +const { getApiStatements } = require('./awsCliScriptHelpers/applyToInstanceHelper'); +const { generateScript } = require('./generateScript'); +const { generateContainerScript } = require('./generateContainerScript'); module.exports = { generateScript, diff --git a/forward_engineering/helpers/awsCliScriptHelpers/applyToInstanceHelper.js b/forward_engineering/awsCliScriptHelpers/applyToInstanceHelper.js similarity index 100% rename from forward_engineering/helpers/awsCliScriptHelpers/applyToInstanceHelper.js rename to forward_engineering/awsCliScriptHelpers/applyToInstanceHelper.js diff --git a/forward_engineering/helpers/awsScriptHelper.js b/forward_engineering/awsCliScriptHelpers/awsScriptHelper.js similarity index 82% rename from forward_engineering/helpers/awsScriptHelper.js rename to forward_engineering/awsCliScriptHelpers/awsScriptHelper.js index b0d8266..7d77c56 100644 --- a/forward_engineering/helpers/awsScriptHelper.js +++ b/forward_engineering/awsCliScriptHelpers/awsScriptHelper.js @@ -1,6 +1,6 @@ const { get } = require('lodash'); -const { getGlueDatabaseCreateStatement } = require('./awsCliScriptHelpers/glueDatabaseHeleper'); -const { getGlueTableCreateStatement } = require('./awsCliScriptHelpers/glueTableHelper'); +const { getGlueDatabaseCreateStatement } = require('./glueDatabaseHeleper'); +const { getGlueTableCreateStatement } = require('./glueTableHelper'); const buildAWSCLIScript = (containerData, tableSchema) => { const dbStatement = getGlueDatabaseCreateStatement(containerData[0]); diff --git a/forward_engineering/helpers/awsCliScriptHelpers/cliConstants.js b/forward_engineering/awsCliScriptHelpers/cliConstants.js similarity index 100% rename from forward_engineering/helpers/awsCliScriptHelpers/cliConstants.js rename to forward_engineering/awsCliScriptHelpers/cliConstants.js diff --git a/forward_engineering/helpers/awsCliScriptHelpers/glueColumnHelper.js b/forward_engineering/awsCliScriptHelpers/glueColumnHelper.js similarity index 84% rename from forward_engineering/helpers/awsCliScriptHelpers/glueColumnHelper.js rename to forward_engineering/awsCliScriptHelpers/glueColumnHelper.js index ec5ae29..a98e057 100644 --- a/forward_engineering/helpers/awsCliScriptHelpers/glueColumnHelper.js +++ b/forward_engineering/awsCliScriptHelpers/glueColumnHelper.js @@ -1,6 +1,6 @@ -const { getTypeByProperty, getUnionFromAllOf, getUnionFromOneOf } = require('../columnHelper'); +const { getTypeByProperty, getUnionFromAllOf, getUnionFromOneOf } = require('../hiveHelpers/helpers/columnHelper'); -const getGlueTableColumns = (properties = {}, oneOf, allOf) => { +const getGlueTableColumns = (properties = {}, oneOf = null, allOf = null) => { const unionColumns = getUnionColumns(allOf, oneOf); const columns = Object.entries(properties) .filter(([key, value]) => !value.compositePartitionKey) @@ -23,7 +23,7 @@ const getGlueTableClusteringKeyColumns = (properties = {}) => { const getGlueTableSortingColumns = (sortingItems = [], properties = {}) => { return sortingItems.map(item => { const property = Object.entries(properties).find(([key, value]) => value.GUID === item.keyId); - const propertyName = property && property[0]; + const propertyName = property?.[0]; return { Column: propertyName, SortOrder: item.type === 'ascending' ? 1 : 0, @@ -34,7 +34,7 @@ const getGlueTableSortingColumns = (sortingItems = [], properties = {}) => { const mapColumn = (name, data) => { return { Name: name, - Type: getTypeByProperty(data), + Type: getTypeByProperty()(data), Comment: data.comments, }; }; @@ -43,7 +43,7 @@ const getUnionColumns = (allOf, oneOf) => { let columns = []; if (Array.isArray(oneOf)) { - const unions = getUnionFromOneOf(getTypeByProperty)({ oneOf }); + const unions = getUnionFromOneOf(getTypeByProperty())({ oneOf }); const oneOfColumns = Object.keys(unions).reduce((acc, typeName) => { acc = [...acc, { Name: typeName, Type: unions[typeName] }]; return acc; @@ -52,7 +52,7 @@ const getUnionColumns = (allOf, oneOf) => { } if (Array.isArray(allOf)) { - const unions = getUnionFromAllOf(getTypeByProperty)({ allOf }); + const unions = getUnionFromAllOf(getTypeByProperty())({ allOf }); const allOfColumns = Object.keys(unions).reduce((acc, typeName) => { acc = [...acc, { Name: typeName, Type: unions[typeName] }]; diff --git a/forward_engineering/helpers/awsCliScriptHelpers/glueDatabaseHeleper.js b/forward_engineering/awsCliScriptHelpers/glueDatabaseHeleper.js similarity index 100% rename from forward_engineering/helpers/awsCliScriptHelpers/glueDatabaseHeleper.js rename to forward_engineering/awsCliScriptHelpers/glueDatabaseHeleper.js diff --git a/forward_engineering/helpers/awsCliScriptHelpers/glueTableHelper.js b/forward_engineering/awsCliScriptHelpers/glueTableHelper.js similarity index 94% rename from forward_engineering/helpers/awsCliScriptHelpers/glueTableHelper.js rename to forward_engineering/awsCliScriptHelpers/glueTableHelper.js index d85988c..db81089 100644 --- a/forward_engineering/helpers/awsCliScriptHelpers/glueTableHelper.js +++ b/forward_engineering/awsCliScriptHelpers/glueTableHelper.js @@ -1,5 +1,5 @@ const { CLI, CREATE_TABLE } = require('./cliConstants'); -const { TABLE_FORMAT } = require('../../../shared/constants'); +const { TABLE_FORMAT } = require('../../shared/constants'); const { getGlueTableColumns, getGluePartitionKeyTableColumns, @@ -47,7 +47,7 @@ const mapSerdeInfo = tableSchema => { const serDeParameters = getSerDeParams(tableSchema.serDeParameters); return { SerializationLibrary: tableSchema.serDeLibrary, - Parameters: Object.assign({}, { paths }, serDeParameters), + Parameters: { paths, ...serDeParameters }, }; }; @@ -55,7 +55,7 @@ const getSerdePathParams = (parameterPaths = [], properties = {}) => { return parameterPaths .map(({ keyId }) => { const property = Object.entries(properties).find(([key, value]) => value.GUID === keyId); - const propertyName = property && property[0]; + const propertyName = property?.[0]; return propertyName; }) .join(','); @@ -78,7 +78,7 @@ const mapTableParameters = tableSchema => { props.classification = tableSchema.classification.toLowerCase(); } return props; - } catch (err) { + } catch { return {}; } }; diff --git a/forward_engineering/config.json b/forward_engineering/config.json index df5c049..64cc51b 100644 --- a/forward_engineering/config.json +++ b/forward_engineering/config.json @@ -16,7 +16,8 @@ "label": "application/txt", "value": "txt" } - ] + ], + "disableScriptGenerationOptions": true }, { "name": "HiveQL Script", @@ -39,5 +40,418 @@ "name": "Minify", "targetFEKeywords": ["hiveQl"] } + ], + "scriptGenerationOptions": [ + { + "keyword": "primaryKeys", + "label": "FE_SCRIPT_GENERATION_OPTIONS___PRIMARY_KEYS", + "disabled": false, + "value": { + "inline": { + "default": true, + "disabled": false, + "disabledLabel": "" + }, + "separate": { + "default": false, + "disabled": false, + "disabledLabel": "" + }, + "ignore": { + "default": false, + "disabled": false, + "disabledLabel": "" + } + }, + "adapters": [ + { + "dependency": { + "key": "primaryKey", + "valueType": "array" + }, + "defaultValue": { + "primaryKey": [] + } + }, + { + "dependency": { + "type": "or", + "values": [ + { + "key": "primaryKey", + "value": true + }, + { + "key": "compositePrimaryKey", + "value": true + } + ] + }, + "defaultValue": { + "primaryKey": false, + "compositePrimaryKey": false, + "required": false + } + } + ] + }, + { + "keyword": "foreignKeys", + "label": "FE_SCRIPT_GENERATION_OPTIONS___FOREIGN_KEYS", + "disabled": false, + "value": { + "inline": { + "default": true, + "disabled": false, + "disabledLabel": "" + }, + "separate": { + "default": false, + "disabled": false, + "disabledLabel": "" + }, + "ignore": { + "default": false, + "disabled": false, + "disabledLabel": "" + } + } + }, + { + "keyword": "uniqueConstraints", + "label": "FE_SCRIPT_GENERATION_OPTIONS___UNIQUE_KEYS", + "disabled": false, + "value": { + "inline": { + "default": true, + "disabled": false, + "disabledLabel": "" + }, + "separate": { + "default": false, + "disabled": false, + "disabledLabel": "" + }, + "ignore": { + "default": false, + "disabled": false, + "disabledLabel": "" + } + }, + "adapters": [ + { + "dependency": { + "key": "uniqueKey", + "valueType": "array" + }, + "defaultValue": { + "uniqueKey": [] + } + }, + { + "dependency": { + "key": "uniqueKey", + "valueType": "object" + }, + "defaultValue": { + "uniqueKey": {} + } + }, + { + "dependency": { + "type": "or", + "values": [ + { + "key": "unique", + "value": true + }, + { + "key": "compositeUniqueKey", + "value": true + }, + { + "key": "compMode", + "exist": true + } + ] + }, + "defaultValue": { + "unique": false, + "compositeUniqueKey": false + } + } + ] + }, + { + "keyword": "columnNotNullConstraints", + "label": "FE_SCRIPT_GENERATION_OPTIONS___COLUMN_NOT_NULL", + "disabled": false, + "value": { + "inline": { + "default": true, + "disabled": false, + "disabledLabel": "" + }, + "separate": { + "default": false, + "disabled": false, + "disabledLabel": "" + }, + "ignore": { + "default": false, + "disabled": false, + "disabledLabel": "" + } + }, + "adapters": [ + { + "dependency": { + "key": "required", + "value": true + }, + "defaultValue": { + "required": false + } + } + ] + }, + { + "keyword": "checkConstraints", + "label": "FE_SCRIPT_GENERATION_OPTIONS___CHECK_CONSTRAINTS", + "disabled": false, + "value": { + "inline": { + "default": true, + "disabled": false, + "disabledLabel": "" + }, + "separate": { + "default": false, + "disabled": false, + "disabledLabel": "" + }, + "ignore": { + "default": false, + "disabled": false, + "disabledLabel": "" + } + }, + "adapters": [ + { + "dependency": { + "key": "check", + "exist": true + }, + "defaultValue": { + "check": "" + } + }, + { + "dependency": { + "key": "chkConstr", + "valueType": "array" + }, + "defaultValue": { + "chkConstr": [] + } + } + ] + }, + { + "keyword": "columnDefaultValues", + "label": "FE_SCRIPT_GENERATION_OPTIONS___COLUMN_DEFAULT_VALUES", + "disabled": false, + "value": { + "inline": { + "default": true, + "disabled": false, + "disabledLabel": "" + }, + "separate": { + "default": false, + "disabled": false, + "disabledLabel": "" + }, + "ignore": { + "default": false, + "disabled": false, + "disabledLabel": "" + } + }, + "adapters": [ + { + "dependency": { + "key": "default", + "exist": true + }, + "defaultValue": { + "default": "" + } + } + ] + }, + { + "keyword": "schemaComments", + "label": "FE_SCRIPT_GENERATION_OPTIONS___SCHEMA_COMMENTS", + "disabled": false, + "value": { + "inline": { + "default": true, + "disabled": false, + "disabledLabel": "" + }, + "separate": { + "default": false, + "disabled": false, + "disabledLabel": "" + }, + "ignore": { + "default": false, + "disabled": false, + "disabledLabel": "" + } + }, + "adapters": [ + { + "dependency": { + "key": "type", + "value": "bucket" + }, + "defaultValue": { + "description": "" + } + } + ] + }, + { + "keyword": "tableComments", + "label": "FE_SCRIPT_GENERATION_OPTIONS___TABLE_COMMENTS", + "disabled": false, + "value": { + "inline": { + "default": true, + "disabled": false, + "disabledLabel": "" + }, + "separate": { + "default": false, + "disabled": false, + "disabledLabel": "" + }, + "ignore": { + "default": false, + "disabled": false, + "disabledLabel": "" + } + }, + "adapters": [ + { + "dependency": { + "type": "and", + "values": [ + { + "key": "collectionName", + "exist": true + }, + { + "key": "description", + "exist": true + } + ] + }, + "defaultValue": { + "description": "" + } + } + ] + }, + { + "keyword": "viewComments", + "label": "FE_SCRIPT_GENERATION_OPTIONS___VIEW_COMMENTS", + "disabled": false, + "value": { + "inline": { + "default": true, + "disabled": false, + "disabledLabel": "" + }, + "separate": { + "default": false, + "disabled": false, + "disabledLabel": "" + }, + "ignore": { + "default": false, + "disabled": false, + "disabledLabel": "" + } + }, + "adapters": [ + { + "dependency": { + "key": "viewOn", + "exist": true + }, + "defaultValue": { + "description": "" + } + } + ] + }, + { + "keyword": "columnComments", + "label": "FE_SCRIPT_GENERATION_OPTIONS___COLUMN_COMMENTS", + "disabled": false, + "value": { + "inline": { + "default": true, + "disabled": false, + "disabledLabel": "" + }, + "separate": { + "default": false, + "disabled": false, + "disabledLabel": "" + }, + "ignore": { + "default": false, + "disabled": false, + "disabledLabel": "" + } + }, + "adapters": [ + { + "dependency": { + "type": "and", + "values": [ + { + "type": "not", + "values": [ + { + "key": "type", + "value": "bucket" + } + ] + }, + { + "key": "collectionName", + "exist": false + }, + { + "key": "viewOn", + "exist": false + }, + { + "key": "comments", + "exist": true + } + ] + }, + "defaultValue": { + "comments": "" + } + } + ] + } ] } diff --git a/forward_engineering/custom_modules/sql-formatter/LICENSE b/forward_engineering/custom_modules/sql-formatter/LICENSE deleted file mode 100644 index 9bdb35e..0000000 --- a/forward_engineering/custom_modules/sql-formatter/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -The MIT License (MIT) - -Copyright (c) 2016-present ZeroTurnaround LLC - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/forward_engineering/custom_modules/sql-formatter/README.md b/forward_engineering/custom_modules/sql-formatter/README.md deleted file mode 100644 index dec1977..0000000 --- a/forward_engineering/custom_modules/sql-formatter/README.md +++ /dev/null @@ -1,97 +0,0 @@ -# SQL Formatter [![NPM version](https://img.shields.io/npm/v/sql-formatter.svg)](https://npmjs.com/package/sql-formatter) [![Build Status](https://travis-ci.org/zeroturnaround/sql-formatter.svg?branch=master)](https://travis-ci.org/zeroturnaround/sql-formatter) [![Coverage Status](https://coveralls.io/repos/github/zeroturnaround/sql-formatter/badge.svg?branch=master)](https://coveralls.io/github/zeroturnaround/sql-formatter?branch=master) - -**SQL Formatter** is a JavaScript library for pretty-printing SQL queries. -It started as a port of a [PHP Library][], but has since considerably diverged. -It supports [Standard SQL][], [Couchbase N1QL][], [IBM DB2][] and [Oracle PL/SQL][] dialects. - -→ [Try the demo.](https://zeroturnaround.github.io/sql-formatter/) - -## Install - -Get the latest version from NPM: - -``` -npm install sql-formatter -``` - -## Usage - -```js -import sqlFormatter from "sql-formatter"; - -console.log(sqlFormatter.format("SELECT * FROM table1")); -``` - -This will output: - -``` -SELECT - * -FROM - table1 -``` - -You can also pass in configuration options: - -```js -sqlFormatter.format("SELECT *", { - language: "n1ql", // Defaults to "sql" - indent: " " // Defaults to two spaces -}); -``` - -Currently just four SQL dialects are supported: - -- **sql** - [Standard SQL][] -- **n1ql** - [Couchbase N1QL][] -- **db2** - [IBM DB2][] -- **pl/sql** - [Oracle PL/SQL][] - -### Placeholders replacement - -```js -// Named placeholders -sqlFormatter.format("SELECT * FROM tbl WHERE foo = @foo", { - params: {foo: "'bar'"} -})); - -// Indexed placeholders -sqlFormatter.format("SELECT * FROM tbl WHERE foo = ?", { - params: ["'bar'"] -})); -``` - -Both result in: - -``` -SELECT - * -FROM - tbl -WHERE - foo = 'bar' -``` - -## Usage without NPM - -If you don't use a module bundler, clone the repository, run `npm install` and grab a file from `/dist` directory to use inside a `