@tachybase/module-collection 1.6.25 → 1.6.26

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (110) hide show
  1. package/dist/externalVersion.js +2 -2
  2. package/{LICENSE → dist/node_modules/node-sql-parser/LICENSE} +3 -3
  3. package/dist/node_modules/node-sql-parser/ast/postgresql.ts +2063 -0
  4. package/dist/node_modules/node-sql-parser/build/athena.d.ts +1 -0
  5. package/dist/node_modules/node-sql-parser/build/athena.js +2 -0
  6. package/dist/node_modules/node-sql-parser/build/bigquery.d.ts +1 -0
  7. package/dist/node_modules/node-sql-parser/build/bigquery.js +2 -0
  8. package/dist/node_modules/node-sql-parser/build/db2.d.ts +1 -0
  9. package/dist/node_modules/node-sql-parser/build/db2.js +2 -0
  10. package/dist/node_modules/node-sql-parser/build/flinksql.d.ts +1 -0
  11. package/dist/node_modules/node-sql-parser/build/flinksql.js +2 -0
  12. package/dist/node_modules/node-sql-parser/build/hive.d.ts +1 -0
  13. package/dist/node_modules/node-sql-parser/build/hive.js +2 -0
  14. package/dist/node_modules/node-sql-parser/build/mariadb.d.ts +1 -0
  15. package/dist/node_modules/node-sql-parser/build/mariadb.js +2 -0
  16. package/dist/node_modules/node-sql-parser/build/mysql.d.ts +1 -0
  17. package/dist/node_modules/node-sql-parser/build/mysql.js +2 -0
  18. package/dist/node_modules/node-sql-parser/build/noql.d.ts +1 -0
  19. package/dist/node_modules/node-sql-parser/build/noql.js +2 -0
  20. package/dist/node_modules/node-sql-parser/build/postgresql.d.ts +1 -0
  21. package/dist/node_modules/node-sql-parser/build/postgresql.js +2 -0
  22. package/dist/node_modules/node-sql-parser/build/redshift.d.ts +1 -0
  23. package/dist/node_modules/node-sql-parser/build/redshift.js +2 -0
  24. package/dist/node_modules/node-sql-parser/build/snowflake.d.ts +1 -0
  25. package/dist/node_modules/node-sql-parser/build/snowflake.js +2 -0
  26. package/dist/node_modules/node-sql-parser/build/sqlite.d.ts +1 -0
  27. package/dist/node_modules/node-sql-parser/build/sqlite.js +2 -0
  28. package/dist/node_modules/node-sql-parser/build/transactsql.d.ts +1 -0
  29. package/dist/node_modules/node-sql-parser/build/transactsql.js +2 -0
  30. package/dist/node_modules/node-sql-parser/build/trino.d.ts +1 -0
  31. package/dist/node_modules/node-sql-parser/build/trino.js +2 -0
  32. package/dist/node_modules/node-sql-parser/index.d.ts +1 -0
  33. package/dist/node_modules/node-sql-parser/index.js +1 -0
  34. package/dist/node_modules/node-sql-parser/lib/aggregation.js +42 -0
  35. package/dist/node_modules/node-sql-parser/lib/alter.js +211 -0
  36. package/dist/node_modules/node-sql-parser/lib/analyze.js +40 -0
  37. package/dist/node_modules/node-sql-parser/lib/array-struct.js +60 -0
  38. package/dist/node_modules/node-sql-parser/lib/assign.js +33 -0
  39. package/dist/node_modules/node-sql-parser/lib/binary.js +48 -0
  40. package/dist/node_modules/node-sql-parser/lib/case.js +39 -0
  41. package/dist/node_modules/node-sql-parser/lib/collate.js +37 -0
  42. package/dist/node_modules/node-sql-parser/lib/column.js +259 -0
  43. package/dist/node_modules/node-sql-parser/lib/command.js +306 -0
  44. package/dist/node_modules/node-sql-parser/lib/comment.js +53 -0
  45. package/dist/node_modules/node-sql-parser/lib/constrain.js +49 -0
  46. package/dist/node_modules/node-sql-parser/lib/create.js +496 -0
  47. package/dist/node_modules/node-sql-parser/lib/delete.js +44 -0
  48. package/dist/node_modules/node-sql-parser/lib/exec.js +37 -0
  49. package/dist/node_modules/node-sql-parser/lib/explain.js +27 -0
  50. package/dist/node_modules/node-sql-parser/lib/expr.js +147 -0
  51. package/dist/node_modules/node-sql-parser/lib/func.js +231 -0
  52. package/dist/node_modules/node-sql-parser/lib/index-definition.js +106 -0
  53. package/dist/node_modules/node-sql-parser/lib/insert.js +112 -0
  54. package/dist/node_modules/node-sql-parser/lib/interval.js +29 -0
  55. package/dist/node_modules/node-sql-parser/lib/json.js +36 -0
  56. package/dist/node_modules/node-sql-parser/lib/limit.js +45 -0
  57. package/dist/node_modules/node-sql-parser/lib/over.js +39 -0
  58. package/dist/node_modules/node-sql-parser/lib/parser.all.js +36 -0
  59. package/dist/node_modules/node-sql-parser/lib/parser.js +88 -0
  60. package/dist/node_modules/node-sql-parser/lib/parser.single.js +23 -0
  61. package/dist/node_modules/node-sql-parser/lib/proc.js +39 -0
  62. package/dist/node_modules/node-sql-parser/lib/select.js +138 -0
  63. package/dist/node_modules/node-sql-parser/lib/show.js +89 -0
  64. package/dist/node_modules/node-sql-parser/lib/sql.js +43 -0
  65. package/dist/node_modules/node-sql-parser/lib/tables.js +277 -0
  66. package/dist/node_modules/node-sql-parser/lib/transaction.js +32 -0
  67. package/dist/node_modules/node-sql-parser/lib/union.js +83 -0
  68. package/dist/node_modules/node-sql-parser/lib/update.js +62 -0
  69. package/dist/node_modules/node-sql-parser/lib/util.js +458 -0
  70. package/dist/node_modules/node-sql-parser/lib/window.js +84 -0
  71. package/dist/node_modules/node-sql-parser/lib/with.js +37 -0
  72. package/dist/node_modules/node-sql-parser/package.json +1 -0
  73. package/dist/node_modules/node-sql-parser/types.d.ts +555 -0
  74. package/dist/node_modules/node-sql-parser/umd/athena.umd.d.ts +1 -0
  75. package/dist/node_modules/node-sql-parser/umd/athena.umd.js +2 -0
  76. package/dist/node_modules/node-sql-parser/umd/bigquery.umd.d.ts +1 -0
  77. package/dist/node_modules/node-sql-parser/umd/bigquery.umd.js +2 -0
  78. package/dist/node_modules/node-sql-parser/umd/db2.umd.d.ts +1 -0
  79. package/dist/node_modules/node-sql-parser/umd/db2.umd.js +2 -0
  80. package/dist/node_modules/node-sql-parser/umd/flinksql.umd.d.ts +1 -0
  81. package/dist/node_modules/node-sql-parser/umd/flinksql.umd.js +2 -0
  82. package/dist/node_modules/node-sql-parser/umd/hive.umd.d.ts +1 -0
  83. package/dist/node_modules/node-sql-parser/umd/hive.umd.js +2 -0
  84. package/dist/node_modules/node-sql-parser/umd/index.umd.d.ts +1 -0
  85. package/dist/node_modules/node-sql-parser/umd/index.umd.js +2 -0
  86. package/dist/node_modules/node-sql-parser/umd/mariadb.umd.d.ts +1 -0
  87. package/dist/node_modules/node-sql-parser/umd/mariadb.umd.js +2 -0
  88. package/dist/node_modules/node-sql-parser/umd/mysql.umd.d.ts +1 -0
  89. package/dist/node_modules/node-sql-parser/umd/mysql.umd.js +2 -0
  90. package/dist/node_modules/node-sql-parser/umd/noql.umd.d.ts +1 -0
  91. package/dist/node_modules/node-sql-parser/umd/noql.umd.js +2 -0
  92. package/dist/node_modules/node-sql-parser/umd/postgresql.umd.d.ts +1 -0
  93. package/dist/node_modules/node-sql-parser/umd/postgresql.umd.js +2 -0
  94. package/dist/node_modules/node-sql-parser/umd/redshift.umd.d.ts +1 -0
  95. package/dist/node_modules/node-sql-parser/umd/redshift.umd.js +2 -0
  96. package/dist/node_modules/node-sql-parser/umd/snowflake.umd.d.ts +1 -0
  97. package/dist/node_modules/node-sql-parser/umd/snowflake.umd.js +2 -0
  98. package/dist/node_modules/node-sql-parser/umd/sqlite.umd.d.ts +1 -0
  99. package/dist/node_modules/node-sql-parser/umd/sqlite.umd.js +2 -0
  100. package/dist/node_modules/node-sql-parser/umd/transactsql.umd.d.ts +1 -0
  101. package/dist/node_modules/node-sql-parser/umd/transactsql.umd.js +2 -0
  102. package/dist/node_modules/node-sql-parser/umd/trino.umd.d.ts +1 -0
  103. package/dist/node_modules/node-sql-parser/umd/trino.umd.js +2 -0
  104. package/dist/server/repositories/collection-repository.d.ts +3 -0
  105. package/dist/server/repositories/collection-repository.js +7 -1
  106. package/dist/server/resourcers/sql.d.ts +28 -1
  107. package/dist/server/resourcers/sql.js +121 -4
  108. package/dist/server/resourcers/views.d.ts +14 -0
  109. package/dist/server/server.d.ts +3 -0
  110. package/package.json +6 -4
@@ -0,0 +1,259 @@
1
+ (function (global, factory) {
2
+ if (typeof define === "function" && define.amd) {
3
+ define(["exports", "./collate", "./constrain", "./expr", "./func", "./tables", "./util"], factory);
4
+ } else if (typeof exports !== "undefined") {
5
+ factory(exports, require("./collate"), require("./constrain"), require("./expr"), require("./func"), require("./tables"), require("./util"));
6
+ } else {
7
+ var mod = {
8
+ exports: {}
9
+ };
10
+ factory(mod.exports, global.collate, global.constrain, global.expr, global.func, global.tables, global.util);
11
+ global.column = mod.exports;
12
+ }
13
+ })(typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : this, function (_exports, _collate, _constrain, _expr, _func, _tables, _util) {
14
+ "use strict";
15
+
16
+ Object.defineProperty(_exports, "__esModule", {
17
+ value: true
18
+ });
19
+ _exports.arrayIndexToSQL = arrayIndexToSQL;
20
+ _exports.asToSQL = asToSQL;
21
+ _exports.columnDataType = columnDataType;
22
+ _exports.columnDefinitionToSQL = columnDefinitionToSQL;
23
+ _exports.columnOffsetToSQL = columnOffsetToSQL;
24
+ _exports.columnOrderToSQL = columnOrderToSQL;
25
+ _exports.columnRefToSQL = columnRefToSQL;
26
+ _exports.columnReferenceDefinitionToSQL = columnReferenceDefinitionToSQL;
27
+ _exports.columnToSQL = columnToSQL;
28
+ _exports.columnsToSQL = columnsToSQL;
29
+ _exports.fullTextSearchToSQL = fullTextSearchToSQL;
30
+ _exports.getDual = getDual;
31
+ function columnOffsetToSQL(column, isDual) {
32
+ if (typeof column === 'string') return (0, _util.identifierToSql)(column, isDual);
33
+ const {
34
+ expr,
35
+ offset,
36
+ suffix
37
+ } = column;
38
+ const offsetExpr = offset && offset.map(offsetItem => ['[', offsetItem.name, `${offsetItem.name ? '(' : ''}`, (0, _util.literalToSQL)(offsetItem.value), `${offsetItem.name ? ')' : ''}`, ']'].filter(_util.hasVal).join('')).join('');
39
+ const result = [(0, _expr.exprToSQL)(expr), offsetExpr, suffix].filter(_util.hasVal).join('');
40
+ return result;
41
+ }
42
+ function arrayIndexToSQL(arrayIndexList) {
43
+ if (!arrayIndexList || arrayIndexList.length === 0) return '';
44
+ const result = [];
45
+ for (const arrayIndex of arrayIndexList) {
46
+ let arrayIndexStr = arrayIndex.brackets ? `[${(0, _util.literalToSQL)(arrayIndex.index)}]` : `${arrayIndex.notation}${(0, _util.literalToSQL)(arrayIndex.index)}`;
47
+ if (arrayIndex.property) arrayIndexStr = `${arrayIndexStr}.${(0, _util.literalToSQL)(arrayIndex.property)}`;
48
+ result.push(arrayIndexStr);
49
+ }
50
+ return result.join('');
51
+ }
52
+ function columnRefToSQL(expr) {
53
+ const {
54
+ array_index,
55
+ as,
56
+ column,
57
+ collate,
58
+ db,
59
+ isDual,
60
+ notations = [],
61
+ options,
62
+ schema,
63
+ table,
64
+ parentheses,
65
+ suffix,
66
+ order_by,
67
+ subFields = []
68
+ } = expr;
69
+ let str = column === '*' ? '*' : columnOffsetToSQL(column, isDual);
70
+ const prefix = [db, schema, table].filter(_util.hasVal).map(val => `${typeof val === 'string' ? (0, _util.identifierToSql)(val) : (0, _expr.exprToSQL)(val)}`);
71
+ let prefixStr = prefix[0];
72
+ if (prefixStr) {
73
+ let i = 1;
74
+ for (; i < prefix.length; ++i) {
75
+ prefixStr = `${prefixStr}${notations[i] || '.'}${prefix[i]}`;
76
+ }
77
+ str = `${prefixStr}${notations[i] || '.'}${str}`;
78
+ }
79
+ str = [`${str}${arrayIndexToSQL(array_index)}`, ...subFields].join('.');
80
+ const result = [str, (0, _collate.collateToSQL)(collate), (0, _expr.exprToSQL)(options), (0, _util.commonOptionConnector)('AS', _expr.exprToSQL, as)];
81
+ result.push(typeof suffix === 'string' ? (0, _util.toUpper)(suffix) : (0, _expr.exprToSQL)(suffix));
82
+ result.push((0, _util.toUpper)(order_by));
83
+ const sql = result.filter(_util.hasVal).join(' ');
84
+ return parentheses ? `(${sql})` : sql;
85
+ }
86
+ function columnDataType(definition) {
87
+ if (!definition) return;
88
+ const {
89
+ dataType,
90
+ length,
91
+ suffix,
92
+ scale,
93
+ expr
94
+ } = definition;
95
+ const parentheses = length != null && true || false;
96
+ let result = (0, _util.dataTypeToSQL)({
97
+ dataType,
98
+ length,
99
+ suffix,
100
+ scale,
101
+ parentheses
102
+ });
103
+ if (expr) result += (0, _expr.exprToSQL)(expr);
104
+ if (definition.array) {
105
+ const arrayExpr = (0, _func.arrayDimensionToSymbol)(definition);
106
+ const space = /^\[.*\]$/.test(arrayExpr) ? '' : ' ';
107
+ result += [space, arrayExpr].join('');
108
+ }
109
+ return result;
110
+ }
111
+ function columnReferenceDefinitionToSQL(referenceDefinition) {
112
+ const reference = [];
113
+ if (!referenceDefinition) return reference;
114
+ const {
115
+ definition,
116
+ keyword,
117
+ match,
118
+ table,
119
+ on_action: onAction
120
+ } = referenceDefinition;
121
+ reference.push((0, _util.toUpper)(keyword));
122
+ reference.push((0, _tables.tablesToSQL)(table));
123
+ reference.push(definition && `(${definition.map(col => (0, _expr.exprToSQL)(col)).join(', ')})`);
124
+ reference.push((0, _util.toUpper)(match));
125
+ onAction.map(onRef => reference.push((0, _util.toUpper)(onRef.type), (0, _expr.exprToSQL)(onRef.value)));
126
+ return reference.filter(_util.hasVal);
127
+ }
128
+ function generatedExpressionToSQL(generated) {
129
+ if (!generated) return;
130
+ const result = [(0, _util.toUpper)(generated.value), `(${(0, _expr.exprToSQL)(generated.expr)})`, (0, _util.toUpper)(generated.storage_type)];
131
+ return result.filter(_util.hasVal).join(' ');
132
+ }
133
+ function columnOption(definition) {
134
+ const columnOpt = [];
135
+ const {
136
+ nullable,
137
+ character_set: characterSet,
138
+ check,
139
+ comment,
140
+ constraint,
141
+ collate,
142
+ storage,
143
+ using,
144
+ default_val: defaultOpt,
145
+ generated,
146
+ auto_increment: autoIncrement,
147
+ unique: uniqueKey,
148
+ primary_key: primaryKey,
149
+ column_format: columnFormat,
150
+ reference_definition: referenceDefinition
151
+ } = definition;
152
+ const nullSQL = [(0, _util.toUpper)(nullable && nullable.action), (0, _util.toUpper)(nullable && nullable.value)].filter(_util.hasVal).join(' ');
153
+ if (!generated) columnOpt.push(nullSQL);
154
+ if (defaultOpt) {
155
+ const {
156
+ type,
157
+ value
158
+ } = defaultOpt;
159
+ columnOpt.push(type.toUpperCase(), (0, _expr.exprToSQL)(value));
160
+ }
161
+ const {
162
+ database
163
+ } = (0, _util.getParserOpt)();
164
+ if (constraint) columnOpt.push((0, _util.toUpper)(constraint.keyword), (0, _util.literalToSQL)(constraint.constraint));
165
+ columnOpt.push((0, _constrain.constraintDefinitionToSQL)(check));
166
+ columnOpt.push(generatedExpressionToSQL(generated));
167
+ if (generated) columnOpt.push(nullSQL);
168
+ columnOpt.push((0, _util.autoIncrementToSQL)(autoIncrement), (0, _util.toUpper)(primaryKey), (0, _util.toUpper)(uniqueKey), (0, _util.commentToSQL)(comment));
169
+ columnOpt.push(...(0, _util.commonTypeValue)(characterSet));
170
+ if (database.toLowerCase() !== 'sqlite') columnOpt.push((0, _expr.exprToSQL)(collate));
171
+ columnOpt.push(...(0, _util.commonTypeValue)(columnFormat));
172
+ columnOpt.push(...(0, _util.commonTypeValue)(storage));
173
+ columnOpt.push(...columnReferenceDefinitionToSQL(referenceDefinition));
174
+ columnOpt.push((0, _util.commonOptionConnector)('USING', _expr.exprToSQL, using));
175
+ return columnOpt.filter(_util.hasVal).join(' ');
176
+ }
177
+ function columnOrderToSQL(columnOrder) {
178
+ const {
179
+ column,
180
+ collate,
181
+ nulls,
182
+ opclass,
183
+ order_by
184
+ } = columnOrder;
185
+ const columnExpr = typeof column === 'string' ? {
186
+ type: 'column_ref',
187
+ table: columnOrder.table,
188
+ column
189
+ } : columnOrder;
190
+ columnExpr.collate = null;
191
+ const result = [(0, _expr.exprToSQL)(columnExpr), (0, _expr.exprToSQL)(collate), opclass, (0, _util.toUpper)(order_by), (0, _util.toUpper)(nulls)];
192
+ return result.filter(_util.hasVal).join(' ');
193
+ }
194
+ function columnDefinitionToSQL(columnDefinition) {
195
+ const column = [];
196
+ const name = columnRefToSQL(columnDefinition.column);
197
+ const dataType = columnDataType(columnDefinition.definition);
198
+ column.push(name);
199
+ column.push(dataType);
200
+ column.push(columnOption(columnDefinition));
201
+ return column.filter(_util.hasVal).join(' ');
202
+ }
203
+ function asToSQL(asStr) {
204
+ if (!asStr) return '';
205
+ if (typeof asStr === 'object') return ['AS', (0, _expr.exprToSQL)(asStr)].join(' ');
206
+ return ['AS', /^(`?)[a-z_][0-9a-z_]*(`?)$/i.test(asStr) ? (0, _util.identifierToSql)(asStr) : (0, _util.columnIdentifierToSql)(asStr)].join(' ');
207
+ }
208
+ function fullTextSearchToSQL(expr) {
209
+ const {
210
+ against,
211
+ as,
212
+ columns,
213
+ match,
214
+ mode
215
+ } = expr;
216
+ const matchExpr = [(0, _util.toUpper)(match), `(${columns.map(col => columnRefToSQL(col)).join(', ')})`].join(' ');
217
+ const againstExpr = [(0, _util.toUpper)(against), ['(', (0, _expr.exprToSQL)(expr.expr), mode && ` ${(0, _util.literalToSQL)(mode)}`, ')'].filter(_util.hasVal).join('')].join(' ');
218
+ return [matchExpr, againstExpr, asToSQL(as)].filter(_util.hasVal).join(' ');
219
+ }
220
+ function columnToSQL(column, isDual) {
221
+ const {
222
+ expr,
223
+ type
224
+ } = column;
225
+ if (type === 'cast') return (0, _func.castToSQL)(column);
226
+ if (isDual) expr.isDual = isDual;
227
+ let str = (0, _expr.exprToSQL)(expr);
228
+ const {
229
+ expr_list: exprList
230
+ } = column;
231
+ if (exprList) {
232
+ const result = [str];
233
+ const columnsStr = exprList.map(col => columnToSQL(col, isDual)).join(', ');
234
+ result.push([(0, _util.toUpper)(type), type && '(', columnsStr, type && ')'].filter(_util.hasVal).join(''));
235
+ return result.filter(_util.hasVal).join(' ');
236
+ }
237
+ if (expr.parentheses && Reflect.has(expr, 'array_index') && expr.type !== 'cast') str = `(${str})`;
238
+ if (expr.array_index && expr.type !== 'column_ref') {
239
+ str = `${str}${arrayIndexToSQL(expr.array_index)}`;
240
+ }
241
+ return [str, asToSQL(column.as)].filter(_util.hasVal).join(' ');
242
+ }
243
+ function getDual(tables) {
244
+ const baseTable = Array.isArray(tables) && tables[0];
245
+ if (baseTable && baseTable.type === 'dual') return true;
246
+ return false;
247
+ }
248
+ /**
249
+ * Stringify column expressions
250
+ *
251
+ * @param {Array} columns
252
+ * @return {string}
253
+ */
254
+ function columnsToSQL(columns, tables) {
255
+ if (!columns || columns === '*') return columns;
256
+ const isDual = getDual(tables);
257
+ return columns.map(col => columnToSQL(col, isDual)).join(', ');
258
+ }
259
+ });
@@ -0,0 +1,306 @@
1
+ (function (global, factory) {
2
+ if (typeof define === "function" && define.amd) {
3
+ define(["exports", "./column", "./create", "./util", "./expr", "./tables", "./sql", "./union"], factory);
4
+ } else if (typeof exports !== "undefined") {
5
+ factory(exports, require("./column"), require("./create"), require("./util"), require("./expr"), require("./tables"), require("./sql"), require("./union"));
6
+ } else {
7
+ var mod = {
8
+ exports: {}
9
+ };
10
+ factory(mod.exports, global.column, global.create, global.util, global.expr, global.tables, global.sql, global.union);
11
+ global.command = mod.exports;
12
+ }
13
+ })(typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : this, function (_exports, _column, _create, _util, _expr, _tables, _sql, _union) {
14
+ "use strict";
15
+
16
+ Object.defineProperty(_exports, "__esModule", {
17
+ value: true
18
+ });
19
+ _exports.callToSQL = callToSQL;
20
+ _exports.commonCmdToSQL = commonCmdToSQL;
21
+ _exports.deallocateToSQL = deallocateToSQL;
22
+ _exports.declareToSQL = declareToSQL;
23
+ _exports.descToSQL = descToSQL;
24
+ _exports.executeToSQL = executeToSQL;
25
+ _exports.forLoopToSQL = forLoopToSQL;
26
+ _exports.grantAndRevokeToSQL = grantAndRevokeToSQL;
27
+ _exports.grantUserOrRoleToSQL = grantUserOrRoleToSQL;
28
+ _exports.ifToSQL = ifToSQL;
29
+ _exports.lockUnlockToSQL = lockUnlockToSQL;
30
+ _exports.raiseToSQL = raiseToSQL;
31
+ _exports.renameToSQL = renameToSQL;
32
+ _exports.setVarToSQL = setVarToSQL;
33
+ _exports.useToSQL = useToSQL;
34
+ _sql = _interopRequireDefault(_sql);
35
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
36
+ function callToSQL(stmt) {
37
+ const type = 'CALL';
38
+ const storeProcessCall = (0, _expr.exprToSQL)(stmt.expr);
39
+ return `${type} ${storeProcessCall}`;
40
+ }
41
+ function commonCmdToSQL(stmt) {
42
+ const {
43
+ type,
44
+ keyword,
45
+ name,
46
+ prefix,
47
+ suffix
48
+ } = stmt;
49
+ const clauses = [(0, _util.toUpper)(type), (0, _util.toUpper)(keyword), (0, _util.toUpper)(prefix)];
50
+ switch (keyword) {
51
+ case 'table':
52
+ clauses.push((0, _tables.tablesToSQL)(name));
53
+ break;
54
+ case 'trigger':
55
+ clauses.push([name[0].schema ? `${(0, _util.identifierToSql)(name[0].schema)}.` : '', (0, _util.identifierToSql)(name[0].trigger)].filter(_util.hasVal).join(''));
56
+ break;
57
+ case 'database':
58
+ case 'schema':
59
+ case 'procedure':
60
+ clauses.push((0, _util.identifierToSql)(name));
61
+ break;
62
+ case 'view':
63
+ clauses.push((0, _tables.tablesToSQL)(name), stmt.options && stmt.options.map(_expr.exprToSQL).filter(_util.hasVal).join(' '));
64
+ break;
65
+ case 'index':
66
+ clauses.push((0, _column.columnRefToSQL)(name), ...(stmt.table ? ['ON', (0, _tables.tableToSQL)(stmt.table)] : []), stmt.options && stmt.options.map(_expr.exprToSQL).filter(_util.hasVal).join(' '));
67
+ break;
68
+ case 'type':
69
+ clauses.push(name.map(_column.columnRefToSQL).join(', '), stmt.options && stmt.options.map(_expr.exprToSQL).filter(_util.hasVal).join(' '));
70
+ break;
71
+ default:
72
+ break;
73
+ }
74
+ if (suffix) clauses.push(suffix.map(_expr.exprToSQL).filter(_util.hasVal).join(' '));
75
+ return clauses.filter(_util.hasVal).join(' ');
76
+ }
77
+ function descToSQL(stmt) {
78
+ const {
79
+ type,
80
+ table
81
+ } = stmt;
82
+ const action = (0, _util.toUpper)(type);
83
+ return `${action} ${(0, _util.identifierToSql)(table)}`;
84
+ }
85
+ function executeToSQL(stmt) {
86
+ const {
87
+ type,
88
+ name,
89
+ args
90
+ } = stmt;
91
+ const sql = [(0, _util.toUpper)(type)];
92
+ const nameWithArgs = [name];
93
+ if (args) nameWithArgs.push(`(${(0, _expr.exprToSQL)(args).join(', ')})`);
94
+ sql.push(nameWithArgs.join(''));
95
+ return sql.filter(_util.hasVal).join(' ');
96
+ }
97
+ function forLoopToSQL(stmt) {
98
+ const {
99
+ type,
100
+ label,
101
+ target,
102
+ query,
103
+ stmts
104
+ } = stmt;
105
+ const sql = [label, (0, _util.toUpper)(type), target, 'IN', (0, _union.multipleToSQL)([query]), 'LOOP', (0, _union.multipleToSQL)(stmts), 'END LOOP', label];
106
+ return sql.filter(_util.hasVal).join(' ');
107
+ }
108
+ function raiseToSQL(stmt) {
109
+ const {
110
+ type,
111
+ level,
112
+ raise,
113
+ using
114
+ } = stmt;
115
+ const sql = [(0, _util.toUpper)(type), (0, _util.toUpper)(level)];
116
+ if (raise) sql.push([(0, _util.literalToSQL)(raise.keyword), raise.type === 'format' && raise.expr.length > 0 && ','].filter(_util.hasVal).join(''), raise.expr.map(exprInfo => (0, _expr.exprToSQL)(exprInfo)).join(', '));
117
+ if (using) sql.push((0, _util.toUpper)(using.type), (0, _util.toUpper)(using.option), using.symbol, using.expr.map(exprInfo => (0, _expr.exprToSQL)(exprInfo)).join(', '));
118
+ return sql.filter(_util.hasVal).join(' ');
119
+ }
120
+ function renameToSQL(stmt) {
121
+ const {
122
+ type,
123
+ table
124
+ } = stmt;
125
+ const clauses = [];
126
+ const prefix = `${type && type.toUpperCase()} TABLE`;
127
+ if (table) {
128
+ for (const tables of table) {
129
+ const renameInfo = tables.map(_tables.tableToSQL);
130
+ clauses.push(renameInfo.join(' TO '));
131
+ }
132
+ }
133
+ return `${prefix} ${clauses.join(', ')}`;
134
+ }
135
+ function useToSQL(stmt) {
136
+ const {
137
+ type,
138
+ db
139
+ } = stmt;
140
+ const action = (0, _util.toUpper)(type);
141
+ const database = (0, _util.identifierToSql)(db);
142
+ return `${action} ${database}`;
143
+ }
144
+ function setVarToSQL(stmt) {
145
+ const {
146
+ type,
147
+ expr,
148
+ keyword
149
+ } = stmt;
150
+ const action = (0, _util.toUpper)(type);
151
+ const setItems = expr.map(_expr.exprToSQL).join(', ');
152
+ return [action, (0, _util.toUpper)(keyword), setItems].filter(_util.hasVal).join(' ');
153
+ }
154
+ function pgLock(stmt) {
155
+ const {
156
+ lock_mode: lockMode,
157
+ nowait
158
+ } = stmt;
159
+ const lockInfo = [];
160
+ if (lockMode) {
161
+ const {
162
+ mode
163
+ } = lockMode;
164
+ lockInfo.push(mode.toUpperCase());
165
+ }
166
+ if (nowait) lockInfo.push(nowait.toUpperCase());
167
+ return lockInfo;
168
+ }
169
+ function lockUnlockToSQL(stmt) {
170
+ const {
171
+ type,
172
+ keyword,
173
+ tables
174
+ } = stmt;
175
+ const result = [type.toUpperCase(), (0, _util.toUpper)(keyword)];
176
+ if (type.toUpperCase() === 'UNLOCK') return result.join(' ');
177
+ const tableStmt = [];
178
+ for (const tableInfo of tables) {
179
+ const {
180
+ table,
181
+ lock_type: lockType
182
+ } = tableInfo;
183
+ const tableInfoTemp = [(0, _tables.tableToSQL)(table)];
184
+ if (lockType) {
185
+ const lockKeyList = ['prefix', 'type', 'suffix'];
186
+ tableInfoTemp.push(lockKeyList.map(key => (0, _util.toUpper)(lockType[key])).filter(_util.hasVal).join(' '));
187
+ }
188
+ tableStmt.push(tableInfoTemp.join(' '));
189
+ }
190
+ result.push(tableStmt.join(', '), ...pgLock(stmt));
191
+ return result.filter(_util.hasVal).join(' ');
192
+ }
193
+ function deallocateToSQL(stmt) {
194
+ const {
195
+ type,
196
+ keyword,
197
+ expr
198
+ } = stmt;
199
+ return [(0, _util.toUpper)(type), (0, _util.toUpper)(keyword), (0, _expr.exprToSQL)(expr)].filter(_util.hasVal).join(' ');
200
+ }
201
+ function declareToSQL(stmt) {
202
+ const {
203
+ type,
204
+ declare,
205
+ symbol
206
+ } = stmt;
207
+ const result = [(0, _util.toUpper)(type)];
208
+ const info = declare.map(dec => {
209
+ const {
210
+ at,
211
+ name,
212
+ as,
213
+ constant,
214
+ datatype,
215
+ not_null,
216
+ prefix,
217
+ definition,
218
+ keyword
219
+ } = dec;
220
+ const declareInfo = [[at, name].filter(_util.hasVal).join(''), (0, _util.toUpper)(as), (0, _util.toUpper)(constant)];
221
+ switch (keyword) {
222
+ case 'variable':
223
+ declareInfo.push((0, _column.columnDataType)(datatype), (0, _expr.exprToSQL)(dec.collate), (0, _util.toUpper)(not_null));
224
+ if (definition) declareInfo.push((0, _util.toUpper)(definition.keyword), (0, _expr.exprToSQL)(definition.value));
225
+ break;
226
+ case 'cursor':
227
+ declareInfo.push((0, _util.toUpper)(prefix));
228
+ break;
229
+ case 'table':
230
+ declareInfo.push((0, _util.toUpper)(prefix), `(${definition.map(_create.createDefinitionToSQL).join(', ')})`);
231
+ break;
232
+ default:
233
+ break;
234
+ }
235
+ return declareInfo.filter(_util.hasVal).join(' ');
236
+ }).join(`${symbol} `);
237
+ result.push(info);
238
+ return result.join(' ');
239
+ }
240
+ function ifToSQL(stmt) {
241
+ const {
242
+ boolean_expr: boolExpr,
243
+ else_expr: elseExpr,
244
+ elseif_expr: elseifExpr,
245
+ if_expr: ifExpr,
246
+ prefix,
247
+ go,
248
+ semicolons,
249
+ suffix,
250
+ type
251
+ } = stmt;
252
+ const result = [(0, _util.toUpper)(type), (0, _expr.exprToSQL)(boolExpr), (0, _util.literalToSQL)(prefix), `${(0, _sql.default)(ifExpr.ast || ifExpr)}${semicolons[0]}`, (0, _util.toUpper)(go)];
253
+ if (elseifExpr) {
254
+ result.push(elseifExpr.map(elseif => [(0, _util.toUpper)(elseif.type), (0, _expr.exprToSQL)(elseif.boolean_expr), 'THEN', (0, _sql.default)(elseif.then.ast || elseif.then), elseif.semicolon].filter(_util.hasVal).join(' ')).join(' '));
255
+ }
256
+ if (elseExpr) result.push('ELSE', `${(0, _sql.default)(elseExpr.ast || elseExpr)}${semicolons[1]}`);
257
+ result.push((0, _util.literalToSQL)(suffix));
258
+ return result.filter(_util.hasVal).join(' ');
259
+ }
260
+ function grantUserOrRoleToSQL(stmt) {
261
+ const {
262
+ name,
263
+ host
264
+ } = stmt;
265
+ const result = [(0, _util.literalToSQL)(name)];
266
+ if (host) result.push('@', (0, _util.literalToSQL)(host));
267
+ return result.join('');
268
+ }
269
+ function grantAndRevokeToSQL(stmt) {
270
+ const {
271
+ type,
272
+ grant_option_for,
273
+ keyword,
274
+ objects,
275
+ on,
276
+ to_from,
277
+ user_or_roles,
278
+ with: withOpt
279
+ } = stmt;
280
+ const result = [(0, _util.toUpper)(type), (0, _util.literalToSQL)(grant_option_for)];
281
+ const objStr = objects.map(obj => {
282
+ const {
283
+ priv,
284
+ columns
285
+ } = obj;
286
+ const privSQL = [(0, _expr.exprToSQL)(priv)];
287
+ if (columns) privSQL.push(`(${columns.map(_column.columnRefToSQL).join(', ')})`);
288
+ return privSQL.join(' ');
289
+ }).join(', ');
290
+ result.push(objStr);
291
+ if (on) {
292
+ result.push('ON');
293
+ switch (keyword) {
294
+ case 'priv':
295
+ result.push((0, _util.literalToSQL)(on.object_type), on.priv_level.map(privLevel => [(0, _util.identifierToSql)(privLevel.prefix), (0, _util.identifierToSql)(privLevel.name)].filter(_util.hasVal).join('.')).join(', '));
296
+ break;
297
+ case 'proxy':
298
+ result.push(grantUserOrRoleToSQL(on));
299
+ break;
300
+ }
301
+ }
302
+ result.push((0, _util.toUpper)(to_from), user_or_roles.map(grantUserOrRoleToSQL).join(', '));
303
+ result.push((0, _util.literalToSQL)(withOpt));
304
+ return result.filter(_util.hasVal).join(' ');
305
+ }
306
+ });
@@ -0,0 +1,53 @@
1
+ (function (global, factory) {
2
+ if (typeof define === "function" && define.amd) {
3
+ define(["exports", "./column", "./util"], factory);
4
+ } else if (typeof exports !== "undefined") {
5
+ factory(exports, require("./column"), require("./util"));
6
+ } else {
7
+ var mod = {
8
+ exports: {}
9
+ };
10
+ factory(mod.exports, global.column, global.util);
11
+ global.comment = mod.exports;
12
+ }
13
+ })(typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : this, function (_exports, _column, _util) {
14
+ "use strict";
15
+
16
+ Object.defineProperty(_exports, "__esModule", {
17
+ value: true
18
+ });
19
+ _exports.commentOnToSQL = commentOnToSQL;
20
+ function commentOptionToSQL(stmt) {
21
+ const {
22
+ name,
23
+ type
24
+ } = stmt;
25
+ switch (type) {
26
+ case 'table':
27
+ case 'view':
28
+ const fullTableName = [(0, _util.identifierToSql)(name.db), (0, _util.identifierToSql)(name.table)].filter(_util.hasVal).join('.');
29
+ return `${(0, _util.toUpper)(type)} ${fullTableName}`;
30
+ case 'column':
31
+ return `COLUMN ${(0, _column.columnRefToSQL)(name)}`;
32
+ default:
33
+ return `${(0, _util.toUpper)(type)} ${(0, _util.literalToSQL)(name)}`;
34
+ }
35
+ }
36
+ function commentIsExprToSQL(stmt) {
37
+ const {
38
+ keyword,
39
+ expr
40
+ } = stmt;
41
+ return [(0, _util.toUpper)(keyword), (0, _util.literalToSQL)(expr)].filter(_util.hasVal).join(' ');
42
+ }
43
+ function commentOnToSQL(stmt) {
44
+ const {
45
+ expr,
46
+ keyword,
47
+ target,
48
+ type
49
+ } = stmt;
50
+ const result = [(0, _util.toUpper)(type), (0, _util.toUpper)(keyword), commentOptionToSQL(target), commentIsExprToSQL(expr)];
51
+ return result.filter(_util.hasVal).join(' ');
52
+ }
53
+ });
@@ -0,0 +1,49 @@
1
+ (function (global, factory) {
2
+ if (typeof define === "function" && define.amd) {
3
+ define(["exports", "./util", "./index-definition", "./column"], factory);
4
+ } else if (typeof exports !== "undefined") {
5
+ factory(exports, require("./util"), require("./index-definition"), require("./column"));
6
+ } else {
7
+ var mod = {
8
+ exports: {}
9
+ };
10
+ factory(mod.exports, global.util, global.indexDefinition, global.column);
11
+ global.constrain = mod.exports;
12
+ }
13
+ })(typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : this, function (_exports, _util, _indexDefinition, _column) {
14
+ "use strict";
15
+
16
+ Object.defineProperty(_exports, "__esModule", {
17
+ value: true
18
+ });
19
+ _exports.constraintDefinitionToSQL = constraintDefinitionToSQL;
20
+ function constraintDefinitionToSQL(constraintDefinition) {
21
+ if (!constraintDefinition) return;
22
+ const {
23
+ constraint,
24
+ constraint_type: constraintType,
25
+ enforced,
26
+ index,
27
+ keyword,
28
+ reference_definition: referenceDefinition,
29
+ for: forColumn,
30
+ with_values: withValues
31
+ } = constraintDefinition;
32
+ const constraintSQL = [];
33
+ const {
34
+ database
35
+ } = (0, _util.getParserOpt)();
36
+ constraintSQL.push((0, _util.toUpper)(keyword));
37
+ constraintSQL.push((0, _util.identifierToSql)(constraint));
38
+ let constraintTypeStr = (0, _util.toUpper)(constraintType);
39
+ if (database.toLowerCase() === 'sqlite' && constraintTypeStr === 'UNIQUE KEY') constraintTypeStr = 'UNIQUE';
40
+ constraintSQL.push(constraintTypeStr);
41
+ constraintSQL.push(database.toLowerCase() !== 'sqlite' && (0, _util.identifierToSql)(index));
42
+ constraintSQL.push(...(0, _indexDefinition.indexTypeAndOptionToSQL)(constraintDefinition));
43
+ constraintSQL.push(...(0, _column.columnReferenceDefinitionToSQL)(referenceDefinition));
44
+ constraintSQL.push((0, _util.toUpper)(enforced));
45
+ constraintSQL.push((0, _util.commonOptionConnector)('FOR', _util.identifierToSql, forColumn));
46
+ constraintSQL.push((0, _util.literalToSQL)(withValues));
47
+ return constraintSQL.filter(_util.hasVal).join(' ');
48
+ }
49
+ });