Skip to content

Commit 939ca5e

Browse files
committed
Merge commit 'refs/pull/31/head' of https://github.com/hackolade/PostgreSQL
2 parents 714b4d0 + ad20a99 commit 939ca5e

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

forward_engineering/helpers/columnDefinitionHelper.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ module.exports = ({ _, wrap, assignTemplates, templates, commentIfDeactivated, w
7979
const decorateDefault = (type, defaultValue) => {
8080
const constantsValues = ['current_timestamp', 'null'];
8181
if ((isString(type) || isDateTime(type)) && !constantsValues.includes(_.toLower(defaultValue))) {
82-
return wrap(defaultValue, '$$', '$$');
82+
return wrapComment(defaultValue);
8383
} else {
8484
return defaultValue;
8585
}

forward_engineering/helpers/general.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ const POSTGRES_RESERVED_WORDS = [
9696
'WITH',
9797
];
9898

99+
const MUST_BE_ESCAPED = /\t|\n|'|\f|\r/gm;
100+
99101
module.exports = ({ _, divideIntoActivatedAndDeactivated, commentIfDeactivated }) => {
100102
const getFunctionArguments = functionArguments => {
101103
return _.map(functionArguments, arg => {
@@ -177,7 +179,11 @@ module.exports = ({ _, divideIntoActivatedAndDeactivated, commentIfDeactivated }
177179
);
178180
};
179181

180-
const wrapComment = comment => `$$${comment}$$`;
182+
const prepareComment = (comment = '') =>
183+
comment.replace(MUST_BE_ESCAPED, character => `${'\\'}${character}`);
184+
185+
186+
const wrapComment = comment => `E'${prepareComment(JSON.stringify(comment)).slice(1, -1)}'`;
181187

182188
return {
183189
getFunctionArguments,

0 commit comments

Comments
 (0)