diff --git a/forward_engineering/ddlProvider/ddlHelpers/indexHelper.js b/forward_engineering/ddlProvider/ddlHelpers/indexHelper.js index 25f6563..04c922b 100644 --- a/forward_engineering/ddlProvider/ddlHelpers/indexHelper.js +++ b/forward_engineering/ddlProvider/ddlHelpers/indexHelper.js @@ -1,37 +1,56 @@ -module.exports = ({ _, wrapInQuotes }) => { +module.exports = ({_, wrapInQuotes}) => { const getIndexType = (indexType) => { return indexType ? ` ${_.toUpper(indexType)}` : ''; }; + /** + * @param indxKey {Array | undefined} + * @param column_expression {string | undefined} + * @return {string} + * */ const getIndexKeys = ({ - indxKey, - column_expression, - }) => { + indxKey, + column_expression, + }) => { + const { escapeSingleQuote } = require('../../utils/general')(); + + if (column_expression) { + const ddlColumnExpression = escapeSingleQuote(column_expression); + return `\n(\n\t${ddlColumnExpression}\n)\n\t`; + } if (_.isArray(indxKey) && !_.isEmpty(indxKey)) { - return `\n(\n\t${_.map(indxKey, ({name, type}) => `${wrapInQuotes(name)} ${_.toUpper(type)}`).join(',\n\t')}\n)\n\t`; + const indexedColumnsClause = _.map( + indxKey, + ({ + name, + type + }) => `${wrapInQuotes(name)} ${_.toUpper(type)}` + ) + .join(',\n\t'); + return `\n(\n\t${indexedColumnsClause}\n)\n\t`; } - return _.isEmpty(column_expression) ? '' : `(${_.map(column_expression, expr => expr.value)})`; + return ''; }; const getIndexOptions = ({ - indxDescription, - comments, - tablespace, - index_properties, - index_attributes, - index_compression, - logging_clause, - indxKey, - column_expression, - }) => { + indxDescription, + comments, + tablespace, + index_properties, + index_attributes, + index_compression, + logging_clause, + indxKey, + column_expression, + }) => { let options = `${logging_clause ? ` ${_.toUpper(logging_clause)}` : ''}` + - `${tablespace ? ` TABLESPACE ${tablespace}` : ''}` + - `${index_compression ? ` ${index_compression}` : ''}` + `${tablespace ? ` TABLESPACE ${tablespace}` : ''}` + + `${index_compression ? ` ${index_compression}` : ''}` if (index_properties) { - options = ` ${index_properties}`; + options = ` ${index_properties}`; } else if (index_attributes) { - options = ` ${index_attributes}`; + options = ` ${index_attributes}`; } const isKeysEmpty = _.isEmpty(indxKey) && _.isEmpty(column_expression); diff --git a/forward_engineering/ddlProvider/ddlProvider.js b/forward_engineering/ddlProvider/ddlProvider.js index 136d943..98fe0cf 100644 --- a/forward_engineering/ddlProvider/ddlProvider.js +++ b/forward_engineering/ddlProvider/ddlProvider.js @@ -97,8 +97,11 @@ module.exports = (baseProvider, options, app) => { const wrapIfNotExists = (statement, ifNotExist, errorCode = 955) => { if (ifNotExist) { - const ddlToWrap = _.trim(tab(tab(statement))); - return assignTemplates(templates.ifNotExists, {statement: ddlToWrap, errorCode}) + const tabbedStatement = tab(tab(statement)); + const trimmedStatement = _.trim(tabbedStatement); + const statementWithNoTrailingDelimiter = trimmedStatement.replace(/;$/, ''); + + return assignTemplates(templates.ifNotExists, {statement: statementWithNoTrailingDelimiter, errorCode}) } return statement + ';'; }; @@ -446,7 +449,7 @@ module.exports = (baseProvider, options, app) => { const name = getIndexName(index.indxName); const indexType = getIndexType(index.indxType); const keys = getIndexKeys(index); - const indexOptions = getIndexOptions(index, isParentActivated); + const indexOptions = getIndexOptions(index); const dbVersion = options.dbVersion || ''; const usingTryCatchWrapper = shouldUseTryCatchIfNotExistsWrapper(dbVersion); const statement = assignTemplates(templates.createIndex, { diff --git a/forward_engineering/ddlProvider/templates.js b/forward_engineering/ddlProvider/templates.js index 830b4a1..2dacd9b 100644 --- a/forward_engineering/ddlProvider/templates.js +++ b/forward_engineering/ddlProvider/templates.js @@ -22,7 +22,7 @@ module.exports = { createForeignKey: 'ALTER TABLE ${foreignTable} ADD CONSTRAINT ${name} FOREIGN KEY (${foreignKey}) REFERENCES ${primaryTable} (${primaryKey})${onDelete};', - createIndex: `CREATE$\{indexType} INDEX$\{ifNotExists}$\{name} ON $\{tableName}$\{keys}$\{options};`, + createIndex: `CREATE$\{indexType} INDEX$\{ifNotExists}$\{name} ON $\{tableName}$\{keys}$\{options};\n`, createView: 'CREATE${orReplace}${force}${viewType}${materialized} VIEW${ifNotExists} ${name} ${sharing}${viewProperties}\n\tAS ${selectStatement}', diff --git a/forward_engineering/utils/general.js b/forward_engineering/utils/general.js index 9312cd9..1ea4d6d 100644 --- a/forward_engineering/utils/general.js +++ b/forward_engineering/utils/general.js @@ -165,6 +165,14 @@ module.exports = _ => { : ' (' + columns.map(mapColumn).join(', ') + ')'; }; + /** + * @param str {string} + * @return {string} + * */ + const escapeSingleQuote = str => { + return str.replaceAll("'", "''"); + }; + return { getDbName, getBucketName, @@ -187,5 +195,6 @@ module.exports = _ => { getNamePrefixedWithSchemaName, checkFieldPropertiesChanged, getColumnsList, + escapeSingleQuote, }; }; diff --git a/properties_pane/entity_level/entityLevelConfig.json b/properties_pane/entity_level/entityLevelConfig.json index e69efd4..c9e221b 100644 --- a/properties_pane/entity_level/entityLevelConfig.json +++ b/properties_pane/entity_level/entityLevelConfig.json @@ -2,9 +2,9 @@ * Copyright © 2016-2020 by IntegrIT S.A. dba Hackolade. All rights reserved. * * The copyright to the computer software herein is the property of IntegrIT S.A. -* The software may be used and/or copied only with the written permission of -* IntegrIT S.A. or in accordance with the terms and conditions stipulated in -* the agreement/contract under which the software has been supplied. +* The software may be used and/or copied only with the written permission of +* IntegrIT S.A. or in accordance with the terms and conditions stipulated in +* the agreement/contract under which the software has been supplied. In order to define custom properties for any object's properties pane, you may copy/paste from the following, making sure that you maintain a proper JSON format. @@ -70,8 +70,8 @@ making sure that you maintain a proper JSON format. ] }, // “groupInput” can have the following states - 0 items, 1 item, and many items. -// “blockInput” has only 2 states - 0 items or 1 item. -// This gives us an easy way to represent it as an object and not as an array internally which is beneficial for processing +// “blockInput” has only 2 states - 0 items or 1 item. +// This gives us an easy way to represent it as an object and not as an array internally which is beneficial for processing // and forward-engineering in particular. { "propertyName": "Block", @@ -99,7 +99,7 @@ making sure that you maintain a proper JSON format. "propertyKeyword": "keyList", "propertyType": "fieldList", "template": "orderedList" - }, + }, { "propertyName": "List with attribute", "propertyKeyword": "keyListOrder", @@ -910,7 +910,7 @@ making sure that you maintain a proper JSON format. } ] } - }, + }, { "tooltip": "Remove or update the existing composite primary key definition prior to unlock the possibility to create a new composite primary key definition for this table", "dependency": { @@ -971,7 +971,7 @@ making sure that you maintain a proper JSON format. "propertyType": "primaryKeySetter", "abbr": "pk" }] - }, + }, { "propertyName": "Unique key", "propertyType": "group", @@ -1034,14 +1034,54 @@ making sure that you maintain a proper JSON format. "attributeList": [ "asc", "desc" - ] + ], + "dependency": { + "type": "or", + "values": [ + { + "key": "column_expression", + "exist": false + }, + { + "key": "column_expression", + "value": "" + } + ] + } + }, + { + "propertyName": "Conditional function", + "propertyKeyword": "column_expression", + "propertyTooltip": "Enter conditional function for a function-based index", + "propertyType": "details", + "markdown": false, + "template": "codeEditor", + "templateOptions": { + "editorDialect": "sql" + }, + "dependency": { + "type": "or", + "values": [ + { + "key": "indxKey", + "exist": false + }, + { + "key": "indxKey", + "isEmpty": true + } + ] + } }, { "propertyName": "Description", "propertyKeyword": "indxDescription", "propertyTooltip": "description", "propertyType": "details", - "template": "textarea" + "template": "codeEditor", + "templateOptions": { + "editorDialect": "markdown" + } }, { "propertyName": "Tablespace", @@ -1049,37 +1089,38 @@ making sure that you maintain a proper JSON format. "propertyTooltip": "Specify the tablespace in which Oracle Database creates the table. If you omit TABLESPACE, then the database creates that item in the default tablespace of the owner of the schema containing the table.", "propertyType": "text" }, - { - "propertyName": "Expression", - "propertyKeyword": "column_expression", - "propertyTooltip": "For function-based index. Specify an expression built from columns of table, constants, SQL functions, and user-defined functions. ", - "propertyType": "details", - "template": "textarea", - "markdown": false - }, { "propertyName": "Properties", "propertyKeyword": "index_properties", "propertyTooltip": "Specify the optional index attributes.", "propertyType": "details", - "template": "textarea", - "markdown": false + "markdown": false, + "template": "codeEditor", + "templateOptions": { + "editorDialect": "sql" + } }, { "propertyName": "Attributes", "propertyKeyword": "index_attributes", "propertyTooltip": "Specify the optional index attributes.", "propertyType": "details", - "template": "textarea", - "markdown": false + "markdown": false, + "template": "codeEditor", + "templateOptions": { + "editorDialect": "sql" + } }, { "propertyName": "Compression", "propertyKeyword": "index_compression", "propertyTooltip": "If you want to use compression for a partitioned index, then you must create the index with compression enabled at the index level. You can subsequently enable and disable the compression setting for individual partitions of such a partitioned index. ", "propertyType": "details", - "template": "textarea", - "markdown": false + "markdown": false, + "template": "codeEditor", + "templateOptions": { + "editorDialect": "sql" + } }, { "propertyName": "Logging", @@ -1099,7 +1140,10 @@ making sure that you maintain a proper JSON format. "propertyTooltip": "comments", "addTimestampButton": false, "propertyType": "details", - "template": "textarea" + "template": "codeEditor", + "templateOptions": { + "editorDialect": "markdown" + } } ] }] diff --git a/properties_pane/view_level/viewLevelConfig.json b/properties_pane/view_level/viewLevelConfig.json index 2258513..2e5d66a 100644 --- a/properties_pane/view_level/viewLevelConfig.json +++ b/properties_pane/view_level/viewLevelConfig.json @@ -562,7 +562,47 @@ "propertyKeyword": "indxKey", "propertyType": "fieldList", "template": "orderedList", - "attributeList": ["asc", "desc"] + "attributeList": [ + "asc", + "desc" + ], + "dependency": { + "type": "or", + "values": [ + { + "key": "column_expression", + "exist": false + }, + { + "key": "column_expression", + "value": "" + } + ] + } + }, + { + "propertyName": "Conditional function", + "propertyKeyword": "column_expression", + "propertyTooltip": "Enter conditional function for a function-based index", + "propertyType": "details", + "markdown": false, + "template": "codeEditor", + "templateOptions": { + "editorDialect": "sql" + }, + "dependency": { + "type": "or", + "values": [ + { + "key": "indxKey", + "exist": false + }, + { + "key": "indxKey", + "isEmpty": true + } + ] + } }, { "propertyName": "Description", @@ -577,14 +617,6 @@ "propertyTooltip": "Specify the tablespace in which Oracle Database creates the table. If you omit TABLESPACE, then the database creates that item in the default tablespace of the owner of the schema containing the table.", "propertyType": "text" }, - { - "propertyName": "Expression", - "propertyKeyword": "column_expression", - "propertyTooltip": "For function-based index. Specify an expression built from columns of table, constants, SQL functions, and user-defined functions. ", - "propertyType": "details", - "template": "textarea", - "markdown": false - }, { "propertyName": "Properties", "propertyKeyword": "index_properties",