Skip to content

Commit

Permalink
Merge branch 'develop' into Fix/HCK-6077-HCK-6074-db2-unsupported-col…
Browse files Browse the repository at this point in the history
…umn-options
  • Loading branch information
serhii-filonenko authored Jun 3, 2024
2 parents b8cc252 + a316c57 commit 296af91
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 11 deletions.
13 changes: 13 additions & 0 deletions constants/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,23 @@ const DATA_TYPES_WITH_PRECISION = [DATA_TYPE.decimal, DATA_TYPE.float, DATA_TYPE

const DATA_TYPES_WITH_IDENTITY = [DATA_TYPE.integer, DATA_TYPE.smallint, DATA_TYPE.bigint, DATA_TYPE.decimal];

const STRING_DATA_TYPES = [
DATA_TYPE.char,
DATA_TYPE.varchar,
DATA_TYPE.nchar,
DATA_TYPE.nvarchar,
DATA_TYPE.clob,
DATA_TYPE.graphic,
DATA_TYPE.vargraphic,
DATA_TYPE.dbclob,
DATA_TYPE.blob,
];

module.exports = {
DATA_TYPE,
DATA_TYPES_WITH_BYTE,
DATA_TYPES_WITH_LENGTH,
DATA_TYPES_WITH_PRECISION,
DATA_TYPES_WITH_IDENTITY,
STRING_DATA_TYPES,
};
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { toUpper } = require('lodash');
const { wrapInQuotes } = require('../../../utils/general');
const { DATA_TYPES_WITH_IDENTITY } = require('../../../../constants/types');
const { wrapInSingleQuotes } = require('../../../utils/general');
const { DATA_TYPES_WITH_IDENTITY, STRING_DATA_TYPES } = require('../../../../constants/types');

/**
* @typedef {string | number} DefaultValue
Expand Down Expand Up @@ -36,13 +36,13 @@ const getIdentityOptions = ({ start, increment, minValue, maxValue, cycle }) =>
};

/**
* @param {{ defaultValue: DefaultValue }}
* @param {{ defaultValue: DefaultValue, type: string }}
* @returns {DefaultValue}
*/
const wrapInQuotesDefaultValue = ({ defaultValue }) => {
const doesContainSpaces = /\s+/g.test(defaultValue);
const wrapInQuotesDefaultValue = ({ defaultValue, type }) => {
const isStringDataType = STRING_DATA_TYPES.includes(toUpper(type));

return doesContainSpaces ? wrapInQuotes({ name: defaultValue }) : defaultValue;
return isStringDataType ? wrapInSingleQuotes({ name: defaultValue }) : defaultValue;
};

/**
Expand All @@ -59,7 +59,7 @@ const getColumnDefault = ({ default: defaultValue, identity, type }) => {
}

if (defaultValue || defaultValue === 0) {
const value = wrapInQuotesDefaultValue({ defaultValue });
const value = wrapInQuotesDefaultValue({ defaultValue, type });

return ` WITH DEFAULT ${value}`;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const { trim } = require('lodash');
const templates = require('../../templates');
const { assignTemplates } = require('../../../utils/assignTemplates');
const { wrapInQuotes, commentIfDeactivated } = require('../../../utils/general');
const { wrapInQuotes, commentIfDeactivated, wrapInSingleQuotes } = require('../../../utils/general');

/**
* @enum {string}
Expand All @@ -12,8 +12,6 @@ const OBJECT_TYPE = {
index: 'INDEX',
};

const wrapComment = comment => `'${comment}'`;

/**
* @param {{ objectName: string, objectType: OBJECT_TYPE, description?: string }}
* @returns {string}
Expand All @@ -25,7 +23,7 @@ const getCommentStatement = ({ objectName, objectType, description }) => {

return assignTemplates({
template: templates.comment,
templateData: { objectType, objectName: trim(objectName), comment: wrapComment(description) },
templateData: { objectType, objectName: trim(objectName), comment: wrapInSingleQuotes({ name: description }) },
});
};

Expand Down
7 changes: 7 additions & 0 deletions forward_engineering/utils/general.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ const commentIfDeactivated = (statement, { isActivated, isPartOfLine, inlineComm
*/
const wrapInQuotes = ({ name }) => `"${name}"`;

/**
* @param {{ name: string }}
* @returns {string}
*/
const wrapInSingleQuotes = ({ name }) => `'${name}'`;

/**
* @param {{ name: string, schemaName?: string }}
* @returns {string}
Expand Down Expand Up @@ -117,6 +123,7 @@ module.exports = {
divideIntoActivatedAndDeactivated,
commentIfDeactivated,
wrapInQuotes,
wrapInSingleQuotes,
getNamePrefixedWithSchemaName,
getColumnsList,
toArray,
Expand Down

0 comments on commit 296af91

Please sign in to comment.