@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,496 @@
1
+ (function (global, factory) {
2
+ if (typeof define === "function" && define.amd) {
3
+ define(["exports", "./alter", "./expr", "./index-definition", "./column", "./command", "./constrain", "./func", "./tables", "./update", "./union", "./util"], factory);
4
+ } else if (typeof exports !== "undefined") {
5
+ factory(exports, require("./alter"), require("./expr"), require("./index-definition"), require("./column"), require("./command"), require("./constrain"), require("./func"), require("./tables"), require("./update"), require("./union"), require("./util"));
6
+ } else {
7
+ var mod = {
8
+ exports: {}
9
+ };
10
+ factory(mod.exports, global.alter, global.expr, global.indexDefinition, global.column, global.command, global.constrain, global.func, global.tables, global.update, global.union, global.util);
11
+ global.create = mod.exports;
12
+ }
13
+ })(typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : this, function (_exports, _alter, _expr, _indexDefinition, _column, _command, _constrain, _func, _tables, _update, _union, _util) {
14
+ "use strict";
15
+
16
+ Object.defineProperty(_exports, "__esModule", {
17
+ value: true
18
+ });
19
+ _exports.createDefinitionToSQL = createDefinitionToSQL;
20
+ _exports.createToSQL = createToSQL;
21
+ function createDefinitionToSQL(definition) {
22
+ if (!definition) return [];
23
+ const {
24
+ resource
25
+ } = definition;
26
+ switch (resource) {
27
+ case 'column':
28
+ return (0, _column.columnDefinitionToSQL)(definition);
29
+ case 'index':
30
+ return (0, _indexDefinition.indexDefinitionToSQL)(definition);
31
+ case 'constraint':
32
+ return (0, _constrain.constraintDefinitionToSQL)(definition);
33
+ case 'sequence':
34
+ return [(0, _util.toUpper)(definition.prefix), (0, _expr.exprToSQL)(definition.value)].filter(_util.hasVal).join(' ');
35
+ default:
36
+ throw new Error(`unknown resource = ${resource} type`);
37
+ }
38
+ }
39
+ function forValueItemToSQL(stmt) {
40
+ const {
41
+ keyword
42
+ } = stmt;
43
+ const result = [];
44
+ switch (keyword) {
45
+ case 'from':
46
+ result.push('FROM', `(${(0, _util.literalToSQL)(stmt.from)})`, 'TO', `(${(0, _util.literalToSQL)(stmt.to)})`);
47
+ break;
48
+ case 'in':
49
+ result.push('IN', `(${(0, _expr.exprToSQL)(stmt.in)})`);
50
+ break;
51
+ case 'with':
52
+ result.push('WITH', `(MODULUS ${(0, _util.literalToSQL)(stmt.modulus)}, REMAINDER ${(0, _util.literalToSQL)(stmt.remainder)})`);
53
+ break;
54
+ }
55
+ return result.filter(_util.hasVal).join(' ');
56
+ }
57
+ function createTablePartitionOfToSQL(stmt) {
58
+ const {
59
+ keyword,
60
+ table,
61
+ for_values: forValues,
62
+ tablespace
63
+ } = stmt;
64
+ const result = [(0, _util.toUpper)(keyword), (0, _tables.tableToSQL)(table), (0, _util.toUpper)(forValues.keyword), forValueItemToSQL(forValues.expr)];
65
+ if (tablespace) result.push('TABLESPACE', (0, _util.literalToSQL)(tablespace));
66
+ return result.filter(_util.hasVal).join(' ');
67
+ }
68
+ function createTableToSQL(stmt) {
69
+ const {
70
+ type,
71
+ keyword,
72
+ table,
73
+ like,
74
+ as,
75
+ temporary,
76
+ if_not_exists: ifNotExists,
77
+ create_definitions: createDefinition,
78
+ table_options: tableOptions,
79
+ ignore_replace: ignoreReplace,
80
+ replace: orReplace,
81
+ partition_of: partitionOf,
82
+ query_expr: queryExpr,
83
+ unlogged: unLogged,
84
+ with: withExpr
85
+ } = stmt;
86
+ const sql = [(0, _util.toUpper)(type), (0, _util.toUpper)(orReplace), (0, _util.toUpper)(temporary), (0, _util.toUpper)(unLogged), (0, _util.toUpper)(keyword), (0, _util.toUpper)(ifNotExists), (0, _tables.tablesToSQL)(table)];
87
+ if (like) {
88
+ const {
89
+ type: likeType,
90
+ table: likeTable
91
+ } = like;
92
+ const likeTableName = (0, _tables.tablesToSQL)(likeTable);
93
+ sql.push((0, _util.toUpper)(likeType), likeTableName);
94
+ return sql.filter(_util.hasVal).join(' ');
95
+ }
96
+ if (partitionOf) return sql.concat([createTablePartitionOfToSQL(partitionOf)]).filter(_util.hasVal).join(' ');
97
+ if (createDefinition) sql.push(`(${createDefinition.map(createDefinitionToSQL).join(', ')})`);
98
+ if (tableOptions) {
99
+ const {
100
+ database
101
+ } = (0, _util.getParserOpt)();
102
+ const symbol = database && database.toLowerCase() === 'sqlite' ? ', ' : ' ';
103
+ sql.push(tableOptions.map(_tables.tableOptionToSQL).join(symbol));
104
+ }
105
+ if (withExpr) {
106
+ const withSQL = withExpr.map(withExprItem => [(0, _util.literalToSQL)(withExprItem.keyword), (0, _util.toUpper)(withExprItem.symbol), (0, _util.literalToSQL)(withExprItem.value)].join(' ')).join(', ');
107
+ sql.push(`WITH (${withSQL})`);
108
+ }
109
+ sql.push((0, _util.toUpper)(ignoreReplace), (0, _util.toUpper)(as));
110
+ if (queryExpr) sql.push((0, _union.unionToSQL)(queryExpr));
111
+ return sql.filter(_util.hasVal).join(' ');
112
+ }
113
+ function createTriggerToSQL(stmt) {
114
+ const {
115
+ definer,
116
+ for_each: forEach,
117
+ keyword,
118
+ execute: triggerBody,
119
+ type,
120
+ table,
121
+ if_not_exists: ife,
122
+ temporary,
123
+ trigger,
124
+ events: triggerEvents,
125
+ order: triggerOrder,
126
+ time: triggerTime,
127
+ when
128
+ } = stmt;
129
+ const sql = [(0, _util.toUpper)(type), (0, _util.toUpper)(temporary), (0, _expr.exprToSQL)(definer), (0, _util.toUpper)(keyword), (0, _util.toUpper)(ife), (0, _tables.tableToSQL)(trigger), (0, _util.toUpper)(triggerTime), triggerEvents.map(event => {
130
+ const eventStr = [(0, _util.toUpper)(event.keyword)];
131
+ const {
132
+ args
133
+ } = event;
134
+ if (args) eventStr.push((0, _util.toUpper)(args.keyword), args.columns.map(_column.columnRefToSQL).join(', '));
135
+ return eventStr.join(' ');
136
+ }), 'ON', (0, _tables.tableToSQL)(table), (0, _util.toUpper)(forEach && forEach.keyword), (0, _util.toUpper)(forEach && forEach.args), triggerOrder && `${(0, _util.toUpper)(triggerOrder.keyword)} ${(0, _util.identifierToSql)(triggerOrder.trigger)}`, (0, _util.commonOptionConnector)('WHEN', _expr.exprToSQL, when), (0, _util.toUpper)(triggerBody.prefix)];
137
+ switch (triggerBody.type) {
138
+ case 'set':
139
+ sql.push((0, _util.commonOptionConnector)('SET', _update.setToSQL, triggerBody.expr));
140
+ break;
141
+ case 'multiple':
142
+ sql.push((0, _union.multipleToSQL)(triggerBody.expr.ast));
143
+ break;
144
+ }
145
+ sql.push((0, _util.toUpper)(triggerBody.suffix));
146
+ return sql.filter(_util.hasVal).join(' ');
147
+ }
148
+ function createConstraintTriggerToSQL(stmt) {
149
+ const {
150
+ constraint,
151
+ constraint_kw: constraintKw,
152
+ deferrable,
153
+ events,
154
+ execute,
155
+ for_each: forEach,
156
+ from,
157
+ location,
158
+ keyword,
159
+ or,
160
+ type,
161
+ table,
162
+ when
163
+ } = stmt;
164
+ const sql = [(0, _util.toUpper)(type), (0, _util.toUpper)(or), (0, _util.toUpper)(constraintKw), (0, _util.toUpper)(keyword), (0, _util.identifierToSql)(constraint), (0, _util.toUpper)(location)];
165
+ const event = (0, _util.triggerEventToSQL)(events);
166
+ sql.push(event, 'ON', (0, _tables.tableToSQL)(table));
167
+ if (from) sql.push('FROM', (0, _tables.tableToSQL)(from));
168
+ sql.push(...(0, _util.commonKeywordArgsToSQL)(deferrable), ...(0, _util.commonKeywordArgsToSQL)(forEach));
169
+ if (when) sql.push((0, _util.toUpper)(when.type), (0, _expr.exprToSQL)(when.cond));
170
+ sql.push((0, _util.toUpper)(execute.keyword), (0, _func.funcToSQL)(execute.expr));
171
+ return sql.filter(_util.hasVal).join(' ');
172
+ }
173
+ function createExtensionToSQL(stmt) {
174
+ const {
175
+ extension,
176
+ from,
177
+ if_not_exists: ifNotExists,
178
+ keyword,
179
+ schema,
180
+ type,
181
+ with: withName,
182
+ version
183
+ } = stmt;
184
+ const sql = [(0, _util.toUpper)(type), (0, _util.toUpper)(keyword), (0, _util.toUpper)(ifNotExists), (0, _util.literalToSQL)(extension), (0, _util.toUpper)(withName), (0, _util.commonOptionConnector)('SCHEMA', _util.literalToSQL, schema), (0, _util.commonOptionConnector)('VERSION', _util.literalToSQL, version), (0, _util.commonOptionConnector)('FROM', _util.literalToSQL, from)];
185
+ return sql.filter(_util.hasVal).join(' ');
186
+ }
187
+ function createIndexToSQL(stmt) {
188
+ const {
189
+ concurrently,
190
+ filestream_on: fileStream,
191
+ keyword,
192
+ if_not_exists: ifNotExists,
193
+ include,
194
+ index_columns: indexColumns,
195
+ index_type: indexType,
196
+ index_using: indexUsing,
197
+ index,
198
+ on,
199
+ index_options: indexOpt,
200
+ algorithm_option: algorithmOpt,
201
+ lock_option: lockOpt,
202
+ on_kw: onKw,
203
+ table,
204
+ tablespace,
205
+ type,
206
+ where,
207
+ with: withExpr,
208
+ with_before_where: withBeforeWhere
209
+ } = stmt;
210
+ const withIndexOpt = withExpr && `WITH (${(0, _indexDefinition.indexOptionListToSQL)(withExpr).join(', ')})`;
211
+ const includeColumns = include && `${(0, _util.toUpper)(include.keyword)} (${include.columns.map(col => typeof col === 'string' ? (0, _util.identifierToSql)(col) : (0, _expr.exprToSQL)(col)).join(', ')})`;
212
+ let indexName = index;
213
+ if (index) {
214
+ indexName = typeof index === 'string' ? (0, _util.identifierToSql)(index) : [(0, _util.identifierToSql)(index.schema), (0, _util.identifierToSql)(index.name)].filter(_util.hasVal).join('.');
215
+ }
216
+ const sql = [(0, _util.toUpper)(type), (0, _util.toUpper)(indexType), (0, _util.toUpper)(keyword), (0, _util.toUpper)(ifNotExists), (0, _util.toUpper)(concurrently), indexName, (0, _util.toUpper)(onKw), (0, _tables.tableToSQL)(table), ...(0, _indexDefinition.indexTypeToSQL)(indexUsing), `(${(0, _util.columnOrderListToSQL)(indexColumns)})`, includeColumns, (0, _indexDefinition.indexOptionListToSQL)(indexOpt).join(' '), (0, _alter.alterExprToSQL)(algorithmOpt), (0, _alter.alterExprToSQL)(lockOpt), (0, _util.commonOptionConnector)('TABLESPACE', _util.literalToSQL, tablespace)];
217
+ if (withBeforeWhere) {
218
+ sql.push(withIndexOpt, (0, _util.commonOptionConnector)('WHERE', _expr.exprToSQL, where));
219
+ } else {
220
+ sql.push((0, _util.commonOptionConnector)('WHERE', _expr.exprToSQL, where), withIndexOpt);
221
+ }
222
+ sql.push((0, _util.commonOptionConnector)('ON', _expr.exprToSQL, on), (0, _util.commonOptionConnector)('FILESTREAM_ON', _util.literalToSQL, fileStream));
223
+ return sql.filter(_util.hasVal).join(' ');
224
+ }
225
+ function createSequenceToSQL(stmt) {
226
+ const {
227
+ type,
228
+ keyword,
229
+ sequence,
230
+ temporary,
231
+ if_not_exists: ifNotExists,
232
+ create_definitions: createDefinition
233
+ } = stmt;
234
+ const sql = [(0, _util.toUpper)(type), (0, _util.toUpper)(temporary), (0, _util.toUpper)(keyword), (0, _util.toUpper)(ifNotExists), (0, _tables.tablesToSQL)(sequence)];
235
+ if (createDefinition) sql.push(createDefinition.map(createDefinitionToSQL).join(' '));
236
+ return sql.filter(_util.hasVal).join(' ');
237
+ }
238
+ function createDatabaseOrSchemaToSQL(stmt) {
239
+ const {
240
+ type,
241
+ keyword,
242
+ replace,
243
+ if_not_exists: ifNotExists,
244
+ create_definitions: createDefinition
245
+ } = stmt;
246
+ const {
247
+ db,
248
+ schema
249
+ } = stmt[keyword];
250
+ const name = [(0, _util.literalToSQL)(db), schema.map(_util.literalToSQL).join('.')].filter(_util.hasVal).join('.');
251
+ const sql = [(0, _util.toUpper)(type), (0, _util.toUpper)(replace), (0, _util.toUpper)(keyword), (0, _util.toUpper)(ifNotExists), name];
252
+ if (createDefinition) sql.push(createDefinition.map(_tables.tableOptionToSQL).join(' '));
253
+ return sql.filter(_util.hasVal).join(' ');
254
+ }
255
+ function createViewToSQL(stmt) {
256
+ const {
257
+ algorithm,
258
+ columns,
259
+ definer,
260
+ if_not_exists: ifNotExists,
261
+ keyword,
262
+ recursive,
263
+ replace,
264
+ select,
265
+ sql_security: sqlSecurity,
266
+ temporary,
267
+ type,
268
+ view,
269
+ with: withClause,
270
+ with_options: withOptions
271
+ } = stmt;
272
+ const {
273
+ db,
274
+ schema,
275
+ view: name
276
+ } = view;
277
+ const viewName = [(0, _util.identifierToSql)(db), (0, _util.identifierToSql)(schema), (0, _util.identifierToSql)(name)].filter(_util.hasVal).join('.');
278
+ const sql = [(0, _util.toUpper)(type), (0, _util.toUpper)(replace), (0, _util.toUpper)(temporary), (0, _util.toUpper)(recursive), algorithm && `ALGORITHM = ${(0, _util.toUpper)(algorithm)}`, (0, _expr.exprToSQL)(definer), sqlSecurity && `SQL SECURITY ${(0, _util.toUpper)(sqlSecurity)}`, (0, _util.toUpper)(keyword), (0, _util.toUpper)(ifNotExists), viewName, columns && `(${columns.map(_util.columnIdentifierToSql).join(', ')})`, withOptions && ['WITH', `(${withOptions.map(withOpt => (0, _util.commonTypeValue)(withOpt).join(' ')).join(', ')})`].join(' '), 'AS', (0, _union.unionToSQL)(select), (0, _util.toUpper)(withClause)];
279
+ return sql.filter(_util.hasVal).join(' ');
280
+ }
281
+ function createDomainToSQL(stmt) {
282
+ const {
283
+ as,
284
+ domain,
285
+ type,
286
+ keyword,
287
+ target,
288
+ create_definitions: createDefinition
289
+ } = stmt;
290
+ const sql = [(0, _util.toUpper)(type), (0, _util.toUpper)(keyword), [(0, _util.identifierToSql)(domain.schema), (0, _util.identifierToSql)(domain.name)].filter(_util.hasVal).join('.'), (0, _util.toUpper)(as), (0, _util.dataTypeToSQL)(target)];
291
+ if (createDefinition && createDefinition.length > 0) {
292
+ const definitionSQL = [];
293
+ for (const definition of createDefinition) {
294
+ const definitionType = definition.type;
295
+ switch (definitionType) {
296
+ case 'collate':
297
+ definitionSQL.push((0, _expr.exprToSQL)(definition));
298
+ break;
299
+ case 'default':
300
+ definitionSQL.push((0, _util.toUpper)(definitionType), (0, _expr.exprToSQL)(definition.value));
301
+ break;
302
+ case 'constraint':
303
+ definitionSQL.push((0, _constrain.constraintDefinitionToSQL)(definition));
304
+ break;
305
+ }
306
+ }
307
+ sql.push(definitionSQL.filter(_util.hasVal).join(' '));
308
+ }
309
+ return sql.filter(_util.hasVal).join(' ');
310
+ }
311
+ function createTypeToSQL(stmt) {
312
+ const {
313
+ as,
314
+ create_definitions: createDefinition,
315
+ keyword,
316
+ name,
317
+ resource,
318
+ type
319
+ } = stmt;
320
+ const sql = [(0, _util.toUpper)(type), (0, _util.toUpper)(keyword), [(0, _util.identifierToSql)(name.schema), (0, _util.identifierToSql)(name.name)].filter(_util.hasVal).join('.'), (0, _util.toUpper)(as), (0, _util.toUpper)(resource)];
321
+ if (createDefinition) {
322
+ const definitionSQL = [];
323
+ switch (resource) {
324
+ case 'enum':
325
+ case 'range':
326
+ definitionSQL.push((0, _expr.exprToSQL)(createDefinition));
327
+ break;
328
+ default:
329
+ definitionSQL.push(`(${createDefinition.map(createDefinitionToSQL).join(', ')})`);
330
+ break;
331
+ }
332
+ sql.push(definitionSQL.filter(_util.hasVal).join(' '));
333
+ }
334
+ return sql.filter(_util.hasVal).join(' ');
335
+ }
336
+ function createFunctionReturnsOptToSQL(stmt) {
337
+ if (stmt.dataType) return (0, _util.dataTypeToSQL)(stmt);
338
+ return [(0, _util.identifierToSql)(stmt.db), (0, _util.identifierToSql)(stmt.schema), (0, _util.identifierToSql)(stmt.table)].filter(_util.hasVal).join('.');
339
+ }
340
+ function createFunctionReturnsToSQL(stmt) {
341
+ const {
342
+ type,
343
+ keyword,
344
+ expr
345
+ } = stmt;
346
+ const sql = [(0, _util.toUpper)(type), (0, _util.toUpper)(keyword), Array.isArray(expr) ? `(${expr.map(_column.columnDefinitionToSQL).join(', ')})` : createFunctionReturnsOptToSQL(expr)];
347
+ return sql.filter(_util.hasVal).join(' ');
348
+ }
349
+ function createFunctionOptionToSQL(stmt) {
350
+ const {
351
+ type
352
+ } = stmt;
353
+ switch (type) {
354
+ case 'as':
355
+ return [(0, _util.toUpper)(type), stmt.symbol, (0, _union.unionToSQL)(stmt.declare), (0, _util.toUpper)(stmt.begin), (0, _union.multipleToSQL)(stmt.expr), (0, _util.toUpper)(stmt.end), stmt.symbol].filter(_util.hasVal).join(' ');
356
+ case 'set':
357
+ return [(0, _util.toUpper)(type), stmt.parameter, (0, _util.toUpper)(stmt.value && stmt.value.prefix), stmt.value && stmt.value.expr.map(_expr.exprToSQL).join(', ')].filter(_util.hasVal).join(' ');
358
+ case 'return':
359
+ return [(0, _util.toUpper)(type), (0, _expr.exprToSQL)(stmt.expr)].filter(_util.hasVal).join(' ');
360
+ default:
361
+ return (0, _expr.exprToSQL)(stmt);
362
+ }
363
+ }
364
+ function createFunctionToSQL(stmt) {
365
+ const {
366
+ type,
367
+ replace,
368
+ keyword,
369
+ name,
370
+ args,
371
+ returns,
372
+ options,
373
+ last
374
+ } = stmt;
375
+ const sql = [(0, _util.toUpper)(type), (0, _util.toUpper)(replace), (0, _util.toUpper)(keyword)];
376
+ const functionName = [(0, _util.literalToSQL)(name.schema), name.name.map(_util.literalToSQL).join('.')].filter(_util.hasVal).join('.');
377
+ const argsSQL = args.map(_alter.alterArgsToSQL).filter(_util.hasVal).join(', ');
378
+ sql.push(`${functionName}(${argsSQL})`, createFunctionReturnsToSQL(returns), options.map(createFunctionOptionToSQL).join(' '), last);
379
+ return sql.filter(_util.hasVal).join(' ');
380
+ }
381
+ function aggregateOptionToSQL(stmt) {
382
+ const {
383
+ type,
384
+ symbol,
385
+ value
386
+ } = stmt;
387
+ const sql = [(0, _util.toUpper)(type), symbol];
388
+ switch ((0, _util.toUpper)(type)) {
389
+ case 'SFUNC':
390
+ sql.push([(0, _util.identifierToSql)(value.schema), value.name].filter(_util.hasVal).join('.'));
391
+ break;
392
+ case 'STYPE':
393
+ case 'MSTYPE':
394
+ sql.push((0, _util.dataTypeToSQL)(value));
395
+ break;
396
+ default:
397
+ sql.push((0, _expr.exprToSQL)(value));
398
+ break;
399
+ }
400
+ return sql.filter(_util.hasVal).join(' ');
401
+ }
402
+ function createAggregateToSQL(stmt) {
403
+ const {
404
+ type,
405
+ replace,
406
+ keyword,
407
+ name,
408
+ args,
409
+ options
410
+ } = stmt;
411
+ const sql = [(0, _util.toUpper)(type), (0, _util.toUpper)(replace), (0, _util.toUpper)(keyword)];
412
+ const functionName = [(0, _util.identifierToSql)(name.schema), name.name].filter(_util.hasVal).join('.');
413
+ const argsSQL = `${args.expr.map(_alter.alterArgsToSQL).join(', ')}${args.orderby ? [' ORDER', 'BY', args.orderby.map(_alter.alterArgsToSQL).join(', ')].join(' ') : ''}`;
414
+ sql.push(`${functionName}(${argsSQL})`, `(${options.map(aggregateOptionToSQL).join(', ')})`);
415
+ return sql.filter(_util.hasVal).join(' ');
416
+ }
417
+ function createUserToSQL(stmt) {
418
+ const {
419
+ attribute,
420
+ comment,
421
+ default_role: defaultRole,
422
+ if_not_exists: ifNotExists,
423
+ keyword,
424
+ lock_option: lockOption,
425
+ password_options: passwordOptions,
426
+ require: requireOption,
427
+ resource_options: resourceOptions,
428
+ type,
429
+ user
430
+ } = stmt;
431
+ const userAuthOptions = user.map(userAuthOption => {
432
+ const {
433
+ user: userInfo,
434
+ auth_option
435
+ } = userAuthOption;
436
+ const result = [(0, _command.grantUserOrRoleToSQL)(userInfo)];
437
+ if (auth_option) result.push((0, _util.toUpper)(auth_option.keyword), auth_option.auth_plugin, (0, _util.literalToSQL)(auth_option.value));
438
+ return result.filter(_util.hasVal).join(' ');
439
+ }).join(', ');
440
+ const sql = [(0, _util.toUpper)(type), (0, _util.toUpper)(keyword), (0, _util.toUpper)(ifNotExists), userAuthOptions];
441
+ if (defaultRole) sql.push((0, _util.toUpper)(defaultRole.keyword), defaultRole.value.map(_command.grantUserOrRoleToSQL).join(', '));
442
+ sql.push((0, _util.commonOptionConnector)(requireOption && requireOption.keyword, _expr.exprToSQL, requireOption && requireOption.value));
443
+ if (resourceOptions) sql.push((0, _util.toUpper)(resourceOptions.keyword), resourceOptions.value.map(resourceOption => (0, _expr.exprToSQL)(resourceOption)).join(' '));
444
+ if (passwordOptions) passwordOptions.forEach(passwordOption => sql.push((0, _util.commonOptionConnector)(passwordOption.keyword, _expr.exprToSQL, passwordOption.value)));
445
+ sql.push((0, _util.literalToSQL)(lockOption), (0, _util.commentToSQL)(comment), (0, _util.literalToSQL)(attribute));
446
+ return sql.filter(_util.hasVal).join(' ');
447
+ }
448
+ function createToSQL(stmt) {
449
+ const {
450
+ keyword
451
+ } = stmt;
452
+ let sql = '';
453
+ switch (keyword.toLowerCase()) {
454
+ case 'aggregate':
455
+ sql = createAggregateToSQL(stmt);
456
+ break;
457
+ case 'table':
458
+ sql = createTableToSQL(stmt);
459
+ break;
460
+ case 'trigger':
461
+ sql = stmt.resource === 'constraint' ? createConstraintTriggerToSQL(stmt) : createTriggerToSQL(stmt);
462
+ break;
463
+ case 'extension':
464
+ sql = createExtensionToSQL(stmt);
465
+ break;
466
+ case 'function':
467
+ sql = createFunctionToSQL(stmt);
468
+ break;
469
+ case 'index':
470
+ sql = createIndexToSQL(stmt);
471
+ break;
472
+ case 'sequence':
473
+ sql = createSequenceToSQL(stmt);
474
+ break;
475
+ case 'database':
476
+ case 'schema':
477
+ sql = createDatabaseOrSchemaToSQL(stmt);
478
+ break;
479
+ case 'view':
480
+ sql = createViewToSQL(stmt);
481
+ break;
482
+ case 'domain':
483
+ sql = createDomainToSQL(stmt);
484
+ break;
485
+ case 'type':
486
+ sql = createTypeToSQL(stmt);
487
+ break;
488
+ case 'user':
489
+ sql = createUserToSQL(stmt);
490
+ break;
491
+ default:
492
+ throw new Error(`unknown create resource ${keyword}`);
493
+ }
494
+ return sql;
495
+ }
496
+ });
@@ -0,0 +1,44 @@
1
+ (function (global, factory) {
2
+ if (typeof define === "function" && define.amd) {
3
+ define(["exports", "./column", "./expr", "./limit", "./tables", "./util", "./with"], factory);
4
+ } else if (typeof exports !== "undefined") {
5
+ factory(exports, require("./column"), require("./expr"), require("./limit"), require("./tables"), require("./util"), require("./with"));
6
+ } else {
7
+ var mod = {
8
+ exports: {}
9
+ };
10
+ factory(mod.exports, global.column, global.expr, global.limit, global.tables, global.util, global._with);
11
+ global._delete = mod.exports;
12
+ }
13
+ })(typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : this, function (_exports, _column, _expr, _limit, _tables, _util, _with) {
14
+ "use strict";
15
+
16
+ Object.defineProperty(_exports, "__esModule", {
17
+ value: true
18
+ });
19
+ _exports.deleteToSQL = deleteToSQL;
20
+ function deleteToSQL(stmt) {
21
+ const {
22
+ columns,
23
+ from,
24
+ table,
25
+ where,
26
+ orderby,
27
+ with: withInfo,
28
+ limit,
29
+ returning
30
+ } = stmt;
31
+ const clauses = [(0, _with.withToSQL)(withInfo), 'DELETE'];
32
+ const columnInfo = (0, _column.columnsToSQL)(columns, from);
33
+ clauses.push(columnInfo);
34
+ if (Array.isArray(table)) {
35
+ if (!(table.length === 1 && table[0].addition === true)) clauses.push((0, _tables.tablesToSQL)(table));
36
+ }
37
+ clauses.push((0, _util.commonOptionConnector)('FROM', _tables.tablesToSQL, from));
38
+ clauses.push((0, _util.commonOptionConnector)('WHERE', _expr.exprToSQL, where));
39
+ clauses.push((0, _expr.orderOrPartitionByToSQL)(orderby, 'order by'));
40
+ clauses.push((0, _limit.limitToSQL)(limit));
41
+ clauses.push((0, _util.returningToSQL)(returning));
42
+ return clauses.filter(_util.hasVal).join(' ');
43
+ }
44
+ });
@@ -0,0 +1,37 @@
1
+ (function (global, factory) {
2
+ if (typeof define === "function" && define.amd) {
3
+ define(["exports", "./expr", "./tables", "./util"], factory);
4
+ } else if (typeof exports !== "undefined") {
5
+ factory(exports, require("./expr"), require("./tables"), require("./util"));
6
+ } else {
7
+ var mod = {
8
+ exports: {}
9
+ };
10
+ factory(mod.exports, global.expr, global.tables, global.util);
11
+ global.exec = mod.exports;
12
+ }
13
+ })(typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : this, function (_exports, _expr, _tables, _util) {
14
+ "use strict";
15
+
16
+ Object.defineProperty(_exports, "__esModule", {
17
+ value: true
18
+ });
19
+ _exports.execToSQL = execToSQL;
20
+ function execVariablesToSQL(stmt) {
21
+ const {
22
+ name,
23
+ value
24
+ } = stmt;
25
+ const result = [`@${name}`, '=', (0, _expr.exprToSQL)(value)];
26
+ return result.filter(_util.hasVal).join(' ');
27
+ }
28
+ function execToSQL(stmt) {
29
+ const {
30
+ keyword,
31
+ module,
32
+ parameters
33
+ } = stmt;
34
+ const result = [(0, _util.toUpper)(keyword), (0, _tables.tableToSQL)(module), (parameters || []).map(execVariablesToSQL).filter(_util.hasVal).join(', ')];
35
+ return result.filter(_util.hasVal).join(' ');
36
+ }
37
+ });
@@ -0,0 +1,27 @@
1
+ (function (global, factory) {
2
+ if (typeof define === "function" && define.amd) {
3
+ define(["exports", "./select", "./util"], factory);
4
+ } else if (typeof exports !== "undefined") {
5
+ factory(exports, require("./select"), require("./util"));
6
+ } else {
7
+ var mod = {
8
+ exports: {}
9
+ };
10
+ factory(mod.exports, global.select, global.util);
11
+ global.explain = mod.exports;
12
+ }
13
+ })(typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : this, function (_exports, _select, _util) {
14
+ "use strict";
15
+
16
+ Object.defineProperty(_exports, "__esModule", {
17
+ value: true
18
+ });
19
+ _exports.explainToSQL = explainToSQL;
20
+ function explainToSQL(stmt) {
21
+ const {
22
+ type,
23
+ expr
24
+ } = stmt;
25
+ return [(0, _util.toUpper)(type), (0, _select.selectToSQL)(expr)].join(' ');
26
+ }
27
+ });