@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,277 @@
1
+ (function (global, factory) {
2
+ if (typeof define === "function" && define.amd) {
3
+ define(["exports", "./binary", "./column", "./expr", "./insert", "./interval", "./util"], factory);
4
+ } else if (typeof exports !== "undefined") {
5
+ factory(exports, require("./binary"), require("./column"), require("./expr"), require("./insert"), require("./interval"), require("./util"));
6
+ } else {
7
+ var mod = {
8
+ exports: {}
9
+ };
10
+ factory(mod.exports, global.binary, global.column, global.expr, global.insert, global.interval, global.util);
11
+ global.tables = mod.exports;
12
+ }
13
+ })(typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : this, function (_exports, _binary, _column, _expr, _insert, _interval, _util) {
14
+ "use strict";
15
+
16
+ Object.defineProperty(_exports, "__esModule", {
17
+ value: true
18
+ });
19
+ _exports.operatorToSQL = operatorToSQL;
20
+ _exports.tableHintToSQL = tableHintToSQL;
21
+ _exports.tableOptionToSQL = tableOptionToSQL;
22
+ _exports.tableToSQL = tableToSQL;
23
+ _exports.tableTumbleToSQL = tableTumbleToSQL;
24
+ _exports.tablesToSQL = tablesToSQL;
25
+ _exports.unnestToSQL = unnestToSQL;
26
+ function unnestToSQL(unnestExpr) {
27
+ const {
28
+ type,
29
+ as,
30
+ expr,
31
+ with_offset: withOffset
32
+ } = unnestExpr;
33
+ const result = [`${(0, _util.toUpper)(type)}(${expr && (0, _expr.exprToSQL)(expr) || ''})`, (0, _util.commonOptionConnector)('AS', typeof as === 'string' ? _util.identifierToSql : _expr.exprToSQL, as), (0, _util.commonOptionConnector)((0, _util.toUpper)(withOffset && withOffset.keyword), _util.identifierToSql, withOffset && withOffset.as)];
34
+ return result.filter(_util.hasVal).join(' ');
35
+ }
36
+ function pivotOperatorToSQL(operator) {
37
+ const {
38
+ as,
39
+ column,
40
+ expr,
41
+ in_expr,
42
+ type
43
+ } = operator;
44
+ const result = [(0, _expr.exprToSQL)(expr), 'FOR', (0, _column.columnRefToSQL)(column), (0, _binary.binaryToSQL)(in_expr)];
45
+ const sql = [`${(0, _util.toUpper)(type)}(${result.join(' ')})`];
46
+ if (as) sql.push('AS', (0, _util.identifierToSql)(as));
47
+ return sql.join(' ');
48
+ }
49
+ function operatorToSQL(operator) {
50
+ if (!operator) return;
51
+ const {
52
+ type
53
+ } = operator;
54
+ switch (type) {
55
+ case 'pivot':
56
+ case 'unpivot':
57
+ return pivotOperatorToSQL(operator);
58
+ default:
59
+ return '';
60
+ }
61
+ }
62
+ function tableHintToSQL(tableHintExpr) {
63
+ if (!tableHintExpr) return;
64
+ const {
65
+ keyword,
66
+ expr,
67
+ index,
68
+ index_columns,
69
+ parentheses,
70
+ prefix
71
+ } = tableHintExpr;
72
+ const result = [];
73
+ switch (keyword.toLowerCase()) {
74
+ case 'forceseek':
75
+ result.push((0, _util.toUpper)(keyword), `(${(0, _util.identifierToSql)(index)}`, `(${index_columns.map(_expr.exprToSQL).filter(_util.hasVal).join(', ')}))`);
76
+ break;
77
+ case 'spatial_window_max_cells':
78
+ result.push((0, _util.toUpper)(keyword), '=', (0, _expr.exprToSQL)(expr));
79
+ break;
80
+ case 'index':
81
+ result.push((0, _util.toUpper)(prefix), (0, _util.toUpper)(keyword), parentheses ? `(${expr.map(_util.identifierToSql).join(', ')})` : `= ${(0, _util.identifierToSql)(expr)}`);
82
+ break;
83
+ default:
84
+ result.push((0, _expr.exprToSQL)(expr));
85
+ }
86
+ return result.filter(_util.hasVal).join(' ');
87
+ }
88
+ function tableTumbleArgsToSQL(param, expr) {
89
+ const {
90
+ name,
91
+ symbol
92
+ } = param;
93
+ return [(0, _util.toUpper)(name), symbol, expr].filter(_util.hasVal).join(' ');
94
+ }
95
+ function tableTumbleToSQL(tumble) {
96
+ if (!tumble) return '';
97
+ const {
98
+ data: tableInfo,
99
+ timecol,
100
+ offset,
101
+ size
102
+ } = tumble;
103
+ const fullTableName = [(0, _util.identifierToSql)(tableInfo.expr.db), (0, _util.identifierToSql)(tableInfo.expr.schema), (0, _util.identifierToSql)(tableInfo.expr.table)].filter(_util.hasVal).join('.');
104
+ const timeColSQL = `DESCRIPTOR(${(0, _column.columnRefToSQL)(timecol.expr)})`;
105
+ const result = [`TABLE(TUMBLE(TABLE ${tableTumbleArgsToSQL(tableInfo, fullTableName)}`, tableTumbleArgsToSQL(timecol, timeColSQL)];
106
+ const sizeSQL = tableTumbleArgsToSQL(size, (0, _interval.intervalToSQL)(size.expr));
107
+ if (offset && offset.expr) result.push(sizeSQL, `${tableTumbleArgsToSQL(offset, (0, _interval.intervalToSQL)(offset.expr))}))`);else result.push(`${sizeSQL}))`);
108
+ return result.filter(_util.hasVal).join(', ');
109
+ }
110
+ function temporalTableOptionToSQL(stmt) {
111
+ const {
112
+ keyword
113
+ } = stmt;
114
+ const result = [];
115
+ switch (keyword) {
116
+ case 'as':
117
+ result.push('AS', 'OF', (0, _expr.exprToSQL)(stmt.of));
118
+ break;
119
+ case 'from_to':
120
+ result.push('FROM', (0, _expr.exprToSQL)(stmt.from), 'TO', (0, _expr.exprToSQL)(stmt.to));
121
+ break;
122
+ case 'between_and':
123
+ result.push('BETWEEN', (0, _expr.exprToSQL)(stmt.between), 'AND', (0, _expr.exprToSQL)(stmt.and));
124
+ break;
125
+ case 'contained':
126
+ result.push('CONTAINED', 'IN', (0, _expr.exprToSQL)(stmt.in));
127
+ break;
128
+ }
129
+ return result.filter(_util.hasVal).join(' ');
130
+ }
131
+ function temporalTableToSQL(stmt) {
132
+ if (!stmt) return;
133
+ const {
134
+ keyword,
135
+ expr
136
+ } = stmt;
137
+ return [(0, _util.toUpper)(keyword), temporalTableOptionToSQL(expr)].filter(_util.hasVal).join(' ');
138
+ }
139
+ function generateVirtualTable(stmt) {
140
+ const {
141
+ keyword,
142
+ type,
143
+ generators
144
+ } = stmt;
145
+ const generatorSQL = generators.map(generator => (0, _util.commonTypeValue)(generator).join(' ')).join(', ');
146
+ return `${(0, _util.toUpper)(keyword)}(${(0, _util.toUpper)(type)}(${generatorSQL}))`;
147
+ }
148
+ function tableToSQL(tableInfo) {
149
+ if ((0, _util.toUpper)(tableInfo.type) === 'UNNEST') return unnestToSQL(tableInfo);
150
+ const {
151
+ table,
152
+ db,
153
+ as,
154
+ expr,
155
+ operator,
156
+ prefix: prefixStr,
157
+ schema,
158
+ server,
159
+ suffix,
160
+ tablesample,
161
+ temporal_table,
162
+ table_hint
163
+ } = tableInfo;
164
+ const serverName = (0, _util.identifierToSql)(server);
165
+ const database = (0, _util.identifierToSql)(db);
166
+ const schemaStr = (0, _util.identifierToSql)(schema);
167
+ let tableName = table && (0, _util.identifierToSql)(table);
168
+ if (expr) {
169
+ const exprType = expr.type;
170
+ switch (exprType) {
171
+ case 'values':
172
+ const {
173
+ parentheses,
174
+ values,
175
+ prefix
176
+ } = expr;
177
+ const valueSQL = [parentheses && '(', '', parentheses && ')'];
178
+ let valuesExpr = (0, _insert.valuesToSQL)(values);
179
+ if (prefix) valuesExpr = valuesExpr.split('(').slice(1).map(val => `${(0, _util.toUpper)(prefix)}(${val}`).join('');
180
+ valueSQL[1] = `VALUES ${valuesExpr}`;
181
+ tableName = valueSQL.filter(_util.hasVal).join('');
182
+ break;
183
+ case 'tumble':
184
+ tableName = tableTumbleToSQL(expr);
185
+ break;
186
+ case 'generator':
187
+ tableName = generateVirtualTable(expr);
188
+ break;
189
+ default:
190
+ tableName = (0, _expr.exprToSQL)(expr);
191
+ }
192
+ }
193
+ tableName = [(0, _util.toUpper)(prefixStr), tableName, (0, _util.toUpper)(suffix)].filter(_util.hasVal).join(' ');
194
+ const str = [serverName, database, schemaStr, tableName].filter(_util.hasVal).join('.');
195
+ const result = [str];
196
+ if (tablesample) {
197
+ const tableSampleSQL = ['TABLESAMPLE', (0, _expr.exprToSQL)(tablesample.expr), (0, _util.literalToSQL)(tablesample.repeatable)].filter(_util.hasVal).join(' ');
198
+ result.push(tableSampleSQL);
199
+ }
200
+ result.push(temporalTableToSQL(temporal_table), (0, _util.commonOptionConnector)('AS', typeof as === 'string' ? _util.identifierToSql : _expr.exprToSQL, as), operatorToSQL(operator));
201
+ if (table_hint) result.push((0, _util.toUpper)(table_hint.keyword), `(${table_hint.expr.map(tableHintToSQL).filter(_util.hasVal).join(', ')})`);
202
+ const tableSQL = result.filter(_util.hasVal).join(' ');
203
+ return tableInfo.parentheses ? `(${tableSQL})` : tableSQL;
204
+ }
205
+
206
+ /**
207
+ * @param {Array} tables
208
+ * @return {string}
209
+ */
210
+ function tablesToSQL(tables) {
211
+ if (!tables) return '';
212
+ if (!Array.isArray(tables)) {
213
+ const {
214
+ expr,
215
+ parentheses,
216
+ joins
217
+ } = tables;
218
+ const sql = tablesToSQL(expr);
219
+ if (parentheses) {
220
+ const leftParentheses = [];
221
+ const rightParentheses = [];
222
+ const parenthesesNumber = parentheses === true ? 1 : parentheses.length;
223
+ let i = 0;
224
+ while (i++ < parenthesesNumber) {
225
+ leftParentheses.push('(');
226
+ rightParentheses.push(')');
227
+ }
228
+ const joinsSQL = joins && joins.length > 0 ? tablesToSQL(['', ...joins]) : '';
229
+ return leftParentheses.join('') + sql + rightParentheses.join('') + joinsSQL;
230
+ }
231
+ return sql;
232
+ }
233
+ const baseTable = tables[0];
234
+ const clauses = [];
235
+ if (baseTable.type === 'dual') return 'DUAL';
236
+ clauses.push(tableToSQL(baseTable));
237
+ for (let i = 1; i < tables.length; ++i) {
238
+ const joinExpr = tables[i];
239
+ const {
240
+ on,
241
+ using,
242
+ join
243
+ } = joinExpr;
244
+ const str = [];
245
+ str.push(join ? ` ${(0, _util.toUpper)(join)}` : ',');
246
+ str.push(tableToSQL(joinExpr));
247
+ str.push((0, _util.commonOptionConnector)('ON', _expr.exprToSQL, on));
248
+ if (using) str.push(`USING (${using.map(_util.literalToSQL).join(', ')})`);
249
+ clauses.push(str.filter(_util.hasVal).join(' '));
250
+ }
251
+ return clauses.filter(_util.hasVal).join('');
252
+ }
253
+ function tableOptionToSQL(tableOption) {
254
+ const {
255
+ keyword,
256
+ symbol,
257
+ value
258
+ } = tableOption;
259
+ const sql = [keyword.toUpperCase()];
260
+ if (symbol) sql.push(symbol);
261
+ let val = (0, _util.literalToSQL)(value);
262
+ switch (keyword) {
263
+ case 'partition by':
264
+ case 'default collate':
265
+ val = (0, _expr.exprToSQL)(value);
266
+ break;
267
+ case 'options':
268
+ val = `(${value.map(tableOptionItem => [tableOptionItem.keyword, tableOptionItem.symbol, (0, _expr.exprToSQL)(tableOptionItem.value)].join(' ')).join(', ')})`;
269
+ break;
270
+ case 'cluster by':
271
+ val = value.map(_expr.exprToSQL).join(', ');
272
+ break;
273
+ }
274
+ sql.push(val);
275
+ return sql.filter(_util.hasVal).join(' ');
276
+ }
277
+ });
@@ -0,0 +1,32 @@
1
+ (function (global, factory) {
2
+ if (typeof define === "function" && define.amd) {
3
+ define(["exports", "./util"], factory);
4
+ } else if (typeof exports !== "undefined") {
5
+ factory(exports, require("./util"));
6
+ } else {
7
+ var mod = {
8
+ exports: {}
9
+ };
10
+ factory(mod.exports, global.util);
11
+ global.transaction = mod.exports;
12
+ }
13
+ })(typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : this, function (_exports, _util) {
14
+ "use strict";
15
+
16
+ Object.defineProperty(_exports, "__esModule", {
17
+ value: true
18
+ });
19
+ _exports.transactionToSQL = transactionToSQL;
20
+ function transactionToSQL(stmt) {
21
+ const {
22
+ expr: {
23
+ action,
24
+ keyword,
25
+ modes
26
+ }
27
+ } = stmt;
28
+ const result = [(0, _util.literalToSQL)(action), (0, _util.toUpper)(keyword)];
29
+ if (modes) result.push(modes.map(_util.literalToSQL).join(', '));
30
+ return result.filter(_util.hasVal).join(' ');
31
+ }
32
+ });
@@ -0,0 +1,83 @@
1
+ (function (global, factory) {
2
+ if (typeof define === "function" && define.amd) {
3
+ define(["exports", "./alter", "./analyze", "./create", "./comment", "./explain", "./select", "./delete", "./update", "./insert", "./command", "./exec", "./expr", "./limit", "./proc", "./transaction", "./show", "./util"], factory);
4
+ } else if (typeof exports !== "undefined") {
5
+ factory(exports, require("./alter"), require("./analyze"), require("./create"), require("./comment"), require("./explain"), require("./select"), require("./delete"), require("./update"), require("./insert"), require("./command"), require("./exec"), require("./expr"), require("./limit"), require("./proc"), require("./transaction"), require("./show"), require("./util"));
6
+ } else {
7
+ var mod = {
8
+ exports: {}
9
+ };
10
+ factory(mod.exports, global.alter, global.analyze, global.create, global.comment, global.explain, global.select, global._delete, global.update, global.insert, global.command, global.exec, global.expr, global.limit, global.proc, global.transaction, global.show, global.util);
11
+ global.union = mod.exports;
12
+ }
13
+ })(typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : this, function (_exports, _alter, _analyze, _create, _comment, _explain, _select, _delete, _update, _insert, _command, _exec, _expr, _limit2, _proc, _transaction, _show, _util) {
14
+ "use strict";
15
+
16
+ Object.defineProperty(_exports, "__esModule", {
17
+ value: true
18
+ });
19
+ _exports.multipleToSQL = multipleToSQL;
20
+ _exports.unionToSQL = unionToSQL;
21
+ const typeToSQLFn = {
22
+ alter: _alter.alterToSQL,
23
+ analyze: _analyze.analyzeToSQL,
24
+ attach: _analyze.attachToSQL,
25
+ create: _create.createToSQL,
26
+ comment: _comment.commentOnToSQL,
27
+ select: _select.selectToSQL,
28
+ deallocate: _command.deallocateToSQL,
29
+ delete: _delete.deleteToSQL,
30
+ exec: _exec.execToSQL,
31
+ execute: _command.executeToSQL,
32
+ explain: _explain.explainToSQL,
33
+ for: _command.forLoopToSQL,
34
+ update: _update.updateToSQL,
35
+ if: _command.ifToSQL,
36
+ insert: _insert.insertToSQL,
37
+ drop: _command.commonCmdToSQL,
38
+ truncate: _command.commonCmdToSQL,
39
+ replace: _insert.insertToSQL,
40
+ declare: _command.declareToSQL,
41
+ use: _command.useToSQL,
42
+ rename: _command.renameToSQL,
43
+ call: _command.callToSQL,
44
+ desc: _command.descToSQL,
45
+ set: _command.setVarToSQL,
46
+ lock: _command.lockUnlockToSQL,
47
+ unlock: _command.lockUnlockToSQL,
48
+ show: _show.showToSQL,
49
+ grant: _command.grantAndRevokeToSQL,
50
+ revoke: _command.grantAndRevokeToSQL,
51
+ proc: _proc.procToSQL,
52
+ raise: _command.raiseToSQL,
53
+ transaction: _transaction.transactionToSQL
54
+ };
55
+ function unionToSQL(stmt) {
56
+ if (!stmt) return '';
57
+ const fun = typeToSQLFn[stmt.type];
58
+ const {
59
+ _parentheses,
60
+ _orderby,
61
+ _limit
62
+ } = stmt;
63
+ const res = [_parentheses && '(', fun(stmt)];
64
+ while (stmt._next) {
65
+ const nextFun = typeToSQLFn[stmt._next.type];
66
+ const unionKeyword = (0, _util.toUpper)(stmt.set_op);
67
+ res.push(unionKeyword, nextFun(stmt._next));
68
+ stmt = stmt._next;
69
+ }
70
+ res.push(_parentheses && ')', (0, _expr.orderOrPartitionByToSQL)(_orderby, 'order by'), (0, _limit2.limitToSQL)(_limit));
71
+ return res.filter(_util.hasVal).join(' ');
72
+ }
73
+ function multipleToSQL(stmt) {
74
+ const res = [];
75
+ for (let i = 0, len = stmt.length; i < len; ++i) {
76
+ const astInfo = stmt[i] && stmt[i].ast ? stmt[i].ast : stmt[i];
77
+ let sql = unionToSQL(astInfo);
78
+ if (i === len - 1 && astInfo.type === 'transaction') sql = `${sql} ;`;
79
+ res.push(sql);
80
+ }
81
+ return res.join(' ; ');
82
+ }
83
+ });
@@ -0,0 +1,62 @@
1
+ (function (global, factory) {
2
+ if (typeof define === "function" && define.amd) {
3
+ define(["exports", "./tables", "./expr", "./column", "./limit", "./util", "./with"], factory);
4
+ } else if (typeof exports !== "undefined") {
5
+ factory(exports, require("./tables"), require("./expr"), require("./column"), require("./limit"), require("./util"), require("./with"));
6
+ } else {
7
+ var mod = {
8
+ exports: {}
9
+ };
10
+ factory(mod.exports, global.tables, global.expr, global.column, global.limit, global.util, global._with);
11
+ global.update = mod.exports;
12
+ }
13
+ })(typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : this, function (_exports, _tables, _expr, _column, _limit, _util, _with) {
14
+ "use strict";
15
+
16
+ Object.defineProperty(_exports, "__esModule", {
17
+ value: true
18
+ });
19
+ _exports.setToSQL = setToSQL;
20
+ _exports.updateToSQL = updateToSQL;
21
+ /**
22
+ * @param {Array} sets
23
+ * @return {string}
24
+ */
25
+ function setToSQL(sets) {
26
+ if (!sets || sets.length === 0) return '';
27
+ const clauses = [];
28
+ for (const set of sets) {
29
+ const column = {};
30
+ const {
31
+ value
32
+ } = set;
33
+ for (const key in set) {
34
+ if (key === 'value' || key === 'keyword') continue;
35
+ column[key] = set[key];
36
+ }
37
+ const str = (0, _column.columnRefToSQL)(column);
38
+ const setItem = [str];
39
+ let val = '';
40
+ if (value) {
41
+ val = (0, _expr.exprToSQL)(value);
42
+ setItem.push('=', val);
43
+ }
44
+ clauses.push(setItem.filter(_util.hasVal).join(' '));
45
+ }
46
+ return clauses.join(', ');
47
+ }
48
+ function updateToSQL(stmt) {
49
+ const {
50
+ from,
51
+ table,
52
+ set,
53
+ where,
54
+ orderby,
55
+ with: withInfo,
56
+ limit,
57
+ returning
58
+ } = stmt;
59
+ const clauses = [(0, _with.withToSQL)(withInfo), 'UPDATE', (0, _tables.tablesToSQL)(table), (0, _util.commonOptionConnector)('SET', setToSQL, set), (0, _util.commonOptionConnector)('FROM', _tables.tablesToSQL, from), (0, _util.commonOptionConnector)('WHERE', _expr.exprToSQL, where), (0, _expr.orderOrPartitionByToSQL)(orderby, 'order by'), (0, _limit.limitToSQL)(limit), (0, _util.returningToSQL)(returning)];
60
+ return clauses.filter(_util.hasVal).join(' ');
61
+ }
62
+ });