@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,147 @@
1
+ (function (global, factory) {
2
+ if (typeof define === "function" && define.amd) {
3
+ define(["exports", "./util", "./alter", "./aggregation", "./assign", "./binary", "./case", "./collate", "./column", "./func", "./interval", "./json", "./select", "./show", "./array-struct", "./tables", "./union", "./window"], factory);
4
+ } else if (typeof exports !== "undefined") {
5
+ factory(exports, require("./util"), require("./alter"), require("./aggregation"), require("./assign"), require("./binary"), require("./case"), require("./collate"), require("./column"), require("./func"), require("./interval"), require("./json"), require("./select"), require("./show"), require("./array-struct"), require("./tables"), require("./union"), require("./window"));
6
+ } else {
7
+ var mod = {
8
+ exports: {}
9
+ };
10
+ factory(mod.exports, global.util, global.alter, global.aggregation, global.assign, global.binary, global._case, global.collate, global.column, global.func, global.interval, global.json, global.select, global.show, global.arrayStruct, global.tables, global.union, global.window);
11
+ global.expr = mod.exports;
12
+ }
13
+ })(typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : this, function (_exports, _util, _alter, _aggregation, _assign, _binary, _case, _collate, _column, _func, _interval, _json, _select, _show, _arrayStruct, _tables, _union, _window) {
14
+ "use strict";
15
+
16
+ Object.defineProperty(_exports, "__esModule", {
17
+ value: true
18
+ });
19
+ _exports.exprToSQL = exprToSQL;
20
+ _exports.exprToSQLConvertFn = void 0;
21
+ _exports.getExprListSQL = getExprListSQL;
22
+ _exports.orderOrPartitionByToSQL = orderOrPartitionByToSQL;
23
+ _exports.varToSQL = varToSQL;
24
+ const exprToSQLConvertFn = _exports.exprToSQLConvertFn = {
25
+ alter: _alter.alterExprToSQL,
26
+ aggr_func: _aggregation.aggrToSQL,
27
+ any_value: _func.anyValueFuncToSQL,
28
+ window_func: _window.windowFuncToSQL,
29
+ 'array': _arrayStruct.arrayStructExprToSQL,
30
+ assign: _assign.assignToSQL,
31
+ binary_expr: _binary.binaryToSQL,
32
+ case: _case.caseToSQL,
33
+ cast: _func.castToSQL,
34
+ collate: _collate.collateToSQL,
35
+ column_ref: _column.columnRefToSQL,
36
+ column_definition: _column.columnDefinitionToSQL,
37
+ datatype: _util.dataTypeToSQL,
38
+ extract: _func.extractFunToSQL,
39
+ flatten: _func.flattenFunToSQL,
40
+ fulltext_search: _column.fullTextSearchToSQL,
41
+ function: _func.funcToSQL,
42
+ lambda: _func.lambdaToSQL,
43
+ insert: _union.unionToSQL,
44
+ interval: _interval.intervalToSQL,
45
+ json: _json.jsonExprToSQL,
46
+ json_object_arg: _func.jsonObjectArgToSQL,
47
+ json_visitor: _json.jsonVisitorExprToSQL,
48
+ func_arg: _func.funcArgToSQL,
49
+ show: _show.showToSQL,
50
+ struct: _arrayStruct.arrayStructExprToSQL,
51
+ tablefunc: _func.tablefuncFunToSQL,
52
+ tables: _tables.tablesToSQL,
53
+ unnest: _tables.unnestToSQL,
54
+ 'window': _window.namedWindowExprListToSQL
55
+ };
56
+ function varToSQL(expr) {
57
+ const {
58
+ prefix = '@',
59
+ name,
60
+ members,
61
+ quoted,
62
+ suffix
63
+ } = expr;
64
+ const val = [];
65
+ const varName = members && members.length > 0 ? `${name}.${members.join('.')}` : name;
66
+ let result = `${prefix || ''}${varName}`;
67
+ if (suffix) result += suffix;
68
+ val.push(result);
69
+ return [quoted, val.join(' '), quoted].filter(_util.hasVal).join('');
70
+ }
71
+ exprToSQLConvertFn.var = varToSQL;
72
+ function exprToSQL(exprOrigin) {
73
+ if (!exprOrigin) return;
74
+ const expr = exprOrigin;
75
+ if (exprOrigin.ast) {
76
+ const {
77
+ ast
78
+ } = expr;
79
+ Reflect.deleteProperty(expr, ast);
80
+ for (const key of Object.keys(ast)) {
81
+ expr[key] = ast[key];
82
+ }
83
+ }
84
+ const {
85
+ type
86
+ } = expr;
87
+ if (type === 'expr') return exprToSQL(expr.expr);
88
+ return exprToSQLConvertFn[type] ? exprToSQLConvertFn[type](expr) : (0, _util.literalToSQL)(expr);
89
+ }
90
+ function unaryToSQL(unarExpr) {
91
+ const {
92
+ operator,
93
+ parentheses,
94
+ expr
95
+ } = unarExpr;
96
+ const space = operator === '-' || operator === '+' || operator === '~' || operator === '!' ? '' : ' ';
97
+ const str = `${operator}${space}${exprToSQL(expr)}`;
98
+ return parentheses ? `(${str})` : str;
99
+ }
100
+ function getExprListSQL(exprList) {
101
+ if (!exprList) return [];
102
+ if (!Array.isArray(exprList)) exprList = [exprList];
103
+ return exprList.map(exprToSQL);
104
+ }
105
+ exprToSQLConvertFn.expr_list = expr => {
106
+ const result = getExprListSQL(expr.value);
107
+ const {
108
+ parentheses,
109
+ separator
110
+ } = expr;
111
+ if (!parentheses && !separator) return result;
112
+ const joinSymbol = separator || ', ';
113
+ const str = result.join(joinSymbol);
114
+ return parentheses ? `(${str})` : str;
115
+ };
116
+ exprToSQLConvertFn.select = expr => {
117
+ const str = typeof expr._next === 'object' ? (0, _union.unionToSQL)(expr) : (0, _select.selectToSQL)(expr);
118
+ return expr.parentheses ? `(${str})` : str;
119
+ };
120
+ exprToSQLConvertFn.unary_expr = unaryToSQL;
121
+ function mapObjectToSQL(mapExpr) {
122
+ const {
123
+ keyword,
124
+ expr
125
+ } = mapExpr;
126
+ const exprStr = expr.map(exprItem => [(0, _util.literalToSQL)(exprItem.key), (0, _util.literalToSQL)(exprItem.value)].join(', ')).join(', ');
127
+ return [(0, _util.toUpper)(keyword), `[${exprStr}]`].join('');
128
+ }
129
+ exprToSQLConvertFn.map_object = mapObjectToSQL;
130
+ function orderOrPartitionByToSQL(expr, prefix) {
131
+ if (!Array.isArray(expr)) return '';
132
+ let expressions = [];
133
+ const upperPrefix = (0, _util.toUpper)(prefix);
134
+ switch (upperPrefix) {
135
+ case 'ORDER BY':
136
+ expressions = expr.map(info => [exprToSQL(info.expr), info.type || 'ASC', (0, _util.toUpper)(info.nulls)].filter(_util.hasVal).join(' '));
137
+ break;
138
+ case 'PARTITION BY':
139
+ expressions = expr.map(info => exprToSQL(info.expr));
140
+ break;
141
+ default:
142
+ expressions = expr.map(info => exprToSQL(info.expr));
143
+ break;
144
+ }
145
+ return (0, _util.connector)(upperPrefix, expressions.join(', '));
146
+ }
147
+ });
@@ -0,0 +1,231 @@
1
+ (function (global, factory) {
2
+ if (typeof define === "function" && define.amd) {
3
+ define(["exports", "./column", "./expr", "./util", "./over"], factory);
4
+ } else if (typeof exports !== "undefined") {
5
+ factory(exports, require("./column"), require("./expr"), require("./util"), require("./over"));
6
+ } else {
7
+ var mod = {
8
+ exports: {}
9
+ };
10
+ factory(mod.exports, global.column, global.expr, global.util, global.over);
11
+ global.func = mod.exports;
12
+ }
13
+ })(typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : this, function (_exports, _column, _expr, _util, _over) {
14
+ "use strict";
15
+
16
+ Object.defineProperty(_exports, "__esModule", {
17
+ value: true
18
+ });
19
+ _exports.anyValueFuncToSQL = anyValueFuncToSQL;
20
+ _exports.arrayDimensionToSymbol = arrayDimensionToSymbol;
21
+ _exports.castToSQL = castToSQL;
22
+ _exports.extractFunToSQL = extractFunToSQL;
23
+ _exports.flattenFunToSQL = flattenFunToSQL;
24
+ _exports.funcArgToSQL = funcArgToSQL;
25
+ _exports.funcToSQL = funcToSQL;
26
+ _exports.jsonObjectArgToSQL = jsonObjectArgToSQL;
27
+ _exports.lambdaToSQL = lambdaToSQL;
28
+ _exports.tablefuncFunToSQL = tablefuncFunToSQL;
29
+ function anyValueFuncToSQL(stmt) {
30
+ const {
31
+ args,
32
+ type,
33
+ over
34
+ } = stmt;
35
+ const {
36
+ expr,
37
+ having
38
+ } = args;
39
+ let sql = `${(0, _util.toUpper)(type)}(${(0, _expr.exprToSQL)(expr)}`;
40
+ if (having) sql = `${sql} HAVING ${(0, _util.toUpper)(having.prefix)} ${(0, _expr.exprToSQL)(having.expr)}`;
41
+ sql = `${sql})`;
42
+ const overStr = (0, _over.overToSQL)(over);
43
+ return [sql, overStr].filter(_util.hasVal).join(' ');
44
+ }
45
+ function arrayDimensionToSymbol(target) {
46
+ if (!target || !target.array) return '';
47
+ const {
48
+ keyword
49
+ } = target.array;
50
+ if (keyword) return (0, _util.toUpper)(keyword);
51
+ const {
52
+ dimension,
53
+ length
54
+ } = target.array;
55
+ const result = [];
56
+ for (let i = 0; i < dimension; i++) {
57
+ result.push('[');
58
+ if (length && length[i]) result.push((0, _util.literalToSQL)(length[i]));
59
+ result.push(']');
60
+ }
61
+ return result.join('');
62
+ }
63
+ function castToSQL(expr) {
64
+ const {
65
+ target: targets,
66
+ expr: expression,
67
+ keyword,
68
+ symbol,
69
+ as: alias,
70
+ offset,
71
+ parentheses: outParentheses
72
+ } = expr;
73
+ let prefix = (0, _column.columnOffsetToSQL)({
74
+ expr: expression,
75
+ offset
76
+ });
77
+ const result = [];
78
+ for (let i = 0, len = targets.length; i < len; ++i) {
79
+ const target = targets[i];
80
+ const {
81
+ angle_brackets: angleBrackets,
82
+ length,
83
+ dataType,
84
+ parentheses,
85
+ quoted,
86
+ scale,
87
+ suffix: dataTypeSuffix,
88
+ expr: targetExpr
89
+ } = target;
90
+ let str = targetExpr ? (0, _expr.exprToSQL)(targetExpr) : '';
91
+ if (length != null) str = scale ? `${length}, ${scale}` : length;
92
+ if (parentheses) str = `(${str})`;
93
+ if (angleBrackets) str = `<${str}>`;
94
+ if (dataTypeSuffix && dataTypeSuffix.length) str += ` ${dataTypeSuffix.map(_util.literalToSQL).join(' ')}`;
95
+ let symbolChar = '::';
96
+ let suffix = '';
97
+ const targetResult = [];
98
+ if (symbol === 'as') {
99
+ if (i === 0) prefix = `${(0, _util.toUpper)(keyword)}(${prefix}`;
100
+ suffix = ')';
101
+ symbolChar = ` ${symbol.toUpperCase()} `;
102
+ }
103
+ if (i === 0) targetResult.push(prefix);
104
+ const arrayDimension = arrayDimensionToSymbol(target);
105
+ targetResult.push(symbolChar, quoted, dataType, quoted, arrayDimension, str, suffix);
106
+ result.push(targetResult.filter(_util.hasVal).join(''));
107
+ }
108
+ if (alias) result.push(` AS ${(0, _util.identifierToSql)(alias)}`);
109
+ const sql = result.filter(_util.hasVal).join('');
110
+ return outParentheses ? `(${sql})` : sql;
111
+ }
112
+ function extractFunToSQL(stmt) {
113
+ const {
114
+ args,
115
+ type
116
+ } = stmt;
117
+ const {
118
+ field,
119
+ cast_type: castType,
120
+ source
121
+ } = args;
122
+ const result = [`${(0, _util.toUpper)(type)}(${(0, _util.toUpper)(field)}`, 'FROM', (0, _util.toUpper)(castType), (0, _expr.exprToSQL)(source)];
123
+ return `${result.filter(_util.hasVal).join(' ')})`;
124
+ }
125
+ function flattenArgToSQL(arg) {
126
+ if (!arg) return '';
127
+ const {
128
+ type,
129
+ symbol,
130
+ value
131
+ } = arg;
132
+ const result = [(0, _util.toUpper)(type), symbol, (0, _expr.exprToSQL)(value)];
133
+ return result.filter(_util.hasVal).join(' ');
134
+ }
135
+ function jsonObjectArgToSQL(argExpr) {
136
+ const {
137
+ expr
138
+ } = argExpr;
139
+ const {
140
+ key,
141
+ value,
142
+ on
143
+ } = expr;
144
+ const result = [(0, _expr.exprToSQL)(key), 'VALUE', (0, _expr.exprToSQL)(value)];
145
+ if (on) result.push('ON', 'NULL', (0, _expr.exprToSQL)(on));
146
+ return result.filter(_util.hasVal).join(' ');
147
+ }
148
+ function flattenFunToSQL(stmt) {
149
+ const {
150
+ args,
151
+ type
152
+ } = stmt;
153
+ const keys = ['input', 'path', 'outer', 'recursive', 'mode'];
154
+ const argsStr = keys.map(key => flattenArgToSQL(args[key])).filter(_util.hasVal).join(', ');
155
+ return `${(0, _util.toUpper)(type)}(${argsStr})`;
156
+ }
157
+ function funcArgToSQL(argExpr) {
158
+ const {
159
+ name,
160
+ symbol,
161
+ expr
162
+ } = argExpr.value;
163
+ return [name, symbol, (0, _expr.exprToSQL)(expr)].filter(_util.hasVal).join(' ');
164
+ }
165
+ function withinGroupToSQL(stmt) {
166
+ if (!stmt) return '';
167
+ const {
168
+ type,
169
+ keyword,
170
+ orderby
171
+ } = stmt;
172
+ return [(0, _util.toUpper)(type), (0, _util.toUpper)(keyword), `(${(0, _expr.orderOrPartitionByToSQL)(orderby, 'order by')})`].filter(_util.hasVal).join(' ');
173
+ }
174
+ function funcToSQL(expr) {
175
+ const {
176
+ args,
177
+ array_index,
178
+ name,
179
+ args_parentheses,
180
+ parentheses,
181
+ within_group: withinGroup,
182
+ over,
183
+ suffix
184
+ } = expr;
185
+ const overStr = (0, _over.overToSQL)(over);
186
+ const withinGroupStr = withinGroupToSQL(withinGroup);
187
+ const suffixStr = (0, _expr.exprToSQL)(suffix);
188
+ const funcName = [(0, _util.literalToSQL)(name.schema), name.name.map(_util.literalToSQL).join('.')].filter(_util.hasVal).join('.');
189
+ if (!args) return [funcName, withinGroupStr, overStr].filter(_util.hasVal).join(' ');
190
+ let separator = expr.separator || ', ';
191
+ if ((0, _util.toUpper)(funcName) === 'TRIM') separator = ' ';
192
+ let str = [funcName];
193
+ str.push(args_parentheses === false ? ' ' : '(');
194
+ const argsList = (0, _expr.exprToSQL)(args);
195
+ if (Array.isArray(separator)) {
196
+ let argsSQL = argsList[0];
197
+ for (let i = 1, len = argsList.length; i < len; ++i) {
198
+ argsSQL = [argsSQL, argsList[i]].join(` ${(0, _expr.exprToSQL)(separator[i - 1])} `);
199
+ }
200
+ str.push(argsSQL);
201
+ } else {
202
+ str.push(argsList.join(separator));
203
+ }
204
+ if (args_parentheses !== false) str.push(')');
205
+ str.push((0, _column.arrayIndexToSQL)(array_index));
206
+ str = [str.join(''), suffixStr].filter(_util.hasVal).join(' ');
207
+ return [parentheses ? `(${str})` : str, withinGroupStr, overStr].filter(_util.hasVal).join(' ');
208
+ }
209
+ function tablefuncFunToSQL(expr) {
210
+ const {
211
+ as,
212
+ name,
213
+ args
214
+ } = expr;
215
+ const funcName = [(0, _util.literalToSQL)(name.schema), name.name.map(_util.literalToSQL).join('.')].filter(_util.hasVal).join('.');
216
+ const result = [`${funcName}(${(0, _expr.exprToSQL)(args).join(', ')})`, 'AS', funcToSQL(as)];
217
+ return result.join(' ');
218
+ }
219
+ function lambdaToSQL(stmt) {
220
+ const {
221
+ args,
222
+ expr
223
+ } = stmt;
224
+ const {
225
+ value,
226
+ parentheses
227
+ } = args;
228
+ const argsList = value.map(_expr.exprToSQL).join(', ');
229
+ return [parentheses ? `(${argsList})` : argsList, '->', (0, _expr.exprToSQL)(expr)].join(' ');
230
+ }
231
+ });
@@ -0,0 +1,106 @@
1
+ (function (global, factory) {
2
+ if (typeof define === "function" && define.amd) {
3
+ define(["exports", "./util", "./expr"], factory);
4
+ } else if (typeof exports !== "undefined") {
5
+ factory(exports, require("./util"), require("./expr"));
6
+ } else {
7
+ var mod = {
8
+ exports: {}
9
+ };
10
+ factory(mod.exports, global.util, global.expr);
11
+ global.indexDefinition = mod.exports;
12
+ }
13
+ })(typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : this, function (_exports, _util, _expr) {
14
+ "use strict";
15
+
16
+ Object.defineProperty(_exports, "__esModule", {
17
+ value: true
18
+ });
19
+ _exports.indexDefinitionToSQL = indexDefinitionToSQL;
20
+ _exports.indexOptionListToSQL = indexOptionListToSQL;
21
+ _exports.indexOptionToSQL = indexOptionToSQL;
22
+ _exports.indexTypeAndOptionToSQL = indexTypeAndOptionToSQL;
23
+ _exports.indexTypeToSQL = indexTypeToSQL;
24
+ function indexTypeToSQL(indexType) {
25
+ if (!indexType) return [];
26
+ const {
27
+ keyword,
28
+ type
29
+ } = indexType;
30
+ return [keyword.toUpperCase(), (0, _util.toUpper)(type)];
31
+ }
32
+ function indexOptionToSQL(indexOpt) {
33
+ if (!indexOpt) return;
34
+ const {
35
+ type,
36
+ expr,
37
+ symbol
38
+ } = indexOpt;
39
+ const upperType = type.toUpperCase();
40
+ const indexOptArray = [];
41
+ indexOptArray.push(upperType);
42
+ switch (upperType) {
43
+ case 'KEY_BLOCK_SIZE':
44
+ if (symbol) indexOptArray.push(symbol);
45
+ indexOptArray.push((0, _util.literalToSQL)(expr));
46
+ break;
47
+ case 'BTREE':
48
+ case 'HASH':
49
+ indexOptArray.length = 0;
50
+ indexOptArray.push(...indexTypeToSQL(indexOpt));
51
+ break;
52
+ case 'WITH PARSER':
53
+ indexOptArray.push(expr);
54
+ break;
55
+ case 'VISIBLE':
56
+ case 'INVISIBLE':
57
+ break;
58
+ case 'COMMENT':
59
+ indexOptArray.shift();
60
+ indexOptArray.push((0, _util.commentToSQL)(indexOpt));
61
+ break;
62
+ case 'DATA_COMPRESSION':
63
+ indexOptArray.push(symbol, (0, _util.toUpper)(expr.value), (0, _util.onPartitionsToSQL)(expr.on));
64
+ break;
65
+ default:
66
+ indexOptArray.push(symbol, (0, _util.literalToSQL)(expr));
67
+ break;
68
+ }
69
+ return indexOptArray.filter(_util.hasVal).join(' ');
70
+ }
71
+ function indexOptionListToSQL(indexOptList) {
72
+ if (!indexOptList) return [];
73
+ return indexOptList.map(indexOptionToSQL);
74
+ }
75
+ function indexTypeAndOptionToSQL(indexDefinition) {
76
+ const {
77
+ constraint_type: constraintType,
78
+ index_type: indexType,
79
+ index_options: indexOptions = [],
80
+ definition,
81
+ on,
82
+ with: withExpr
83
+ } = indexDefinition;
84
+ const dataType = [];
85
+ dataType.push(...indexTypeToSQL(indexType));
86
+ if (definition && definition.length) {
87
+ const definitionSQL = (0, _util.toUpper)(constraintType) === 'CHECK' ? `(${(0, _expr.exprToSQL)(definition[0])})` : `(${definition.map(col => (0, _expr.exprToSQL)(col)).join(', ')})`;
88
+ dataType.push(definitionSQL);
89
+ }
90
+ dataType.push(indexOptionListToSQL(indexOptions).join(' '));
91
+ if (withExpr) dataType.push(`WITH (${indexOptionListToSQL(withExpr).join(', ')})`);
92
+ if (on) dataType.push(`ON [${on}]`);
93
+ return dataType;
94
+ }
95
+ function indexDefinitionToSQL(indexDefinition) {
96
+ const indexSQL = [];
97
+ const {
98
+ keyword,
99
+ index
100
+ } = indexDefinition;
101
+ indexSQL.push((0, _util.toUpper)(keyword));
102
+ indexSQL.push(index);
103
+ indexSQL.push(...indexTypeAndOptionToSQL(indexDefinition));
104
+ return indexSQL.filter(_util.hasVal).join(' ');
105
+ }
106
+ });
@@ -0,0 +1,112 @@
1
+ (function (global, factory) {
2
+ if (typeof define === "function" && define.amd) {
3
+ define(["exports", "./tables", "./expr", "./column", "./util", "./select", "./update"], factory);
4
+ } else if (typeof exports !== "undefined") {
5
+ factory(exports, require("./tables"), require("./expr"), require("./column"), require("./util"), require("./select"), require("./update"));
6
+ } else {
7
+ var mod = {
8
+ exports: {}
9
+ };
10
+ factory(mod.exports, global.tables, global.expr, global.column, global.util, global.select, global.update);
11
+ global.insert = mod.exports;
12
+ }
13
+ })(typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : this, function (_exports, _tables, _expr, _column, _util, _select, _update) {
14
+ "use strict";
15
+
16
+ Object.defineProperty(_exports, "__esModule", {
17
+ value: true
18
+ });
19
+ _exports.conflictToSQL = conflictToSQL;
20
+ _exports.insertToSQL = insertToSQL;
21
+ _exports.valuesToSQL = valuesToSQL;
22
+ /**
23
+ * @param {Array} values
24
+ * @return {string}
25
+ */
26
+ function valuesToSQL(values) {
27
+ if (values.type === 'select') return (0, _select.selectToSQL)(values);
28
+ const clauses = values.map(_expr.exprToSQL);
29
+ return `(${clauses.join('), (')})`;
30
+ }
31
+ function partitionToSQL(partition) {
32
+ if (!partition) return '';
33
+ const partitionArr = ['PARTITION', '('];
34
+ if (Array.isArray(partition)) {
35
+ partitionArr.push(partition.map(_util.identifierToSql).join(', '));
36
+ } else {
37
+ const {
38
+ value
39
+ } = partition;
40
+ partitionArr.push(value.map(_expr.exprToSQL).join(', '));
41
+ }
42
+ partitionArr.push(')');
43
+ return partitionArr.filter(_util.hasVal).join('');
44
+ }
45
+ function conflictTargetToSQL(conflictTarget) {
46
+ if (!conflictTarget) return '';
47
+ const {
48
+ type
49
+ } = conflictTarget;
50
+ switch (type) {
51
+ case 'column':
52
+ return `(${conflictTarget.expr.map(_column.columnRefToSQL).join(', ')})`;
53
+ }
54
+ }
55
+ function conflictActionToSQL(conflictAction) {
56
+ const {
57
+ expr,
58
+ keyword
59
+ } = conflictAction;
60
+ const {
61
+ type
62
+ } = expr;
63
+ const result = [(0, _util.toUpper)(keyword)];
64
+ switch (type) {
65
+ case 'origin':
66
+ result.push((0, _util.literalToSQL)(expr));
67
+ break;
68
+ case 'update':
69
+ result.push('UPDATE', (0, _util.commonOptionConnector)('SET', _update.setToSQL, expr.set), (0, _util.commonOptionConnector)('WHERE', _expr.exprToSQL, expr.where));
70
+ break;
71
+ }
72
+ return result.filter(_util.hasVal).join(' ');
73
+ }
74
+ function conflictToSQL(conflict) {
75
+ if (!conflict) return '';
76
+ const {
77
+ action,
78
+ target
79
+ } = conflict;
80
+ const result = [conflictTargetToSQL(target), conflictActionToSQL(action)];
81
+ return result.filter(_util.hasVal).join(' ');
82
+ }
83
+ function insertToSQL(stmt) {
84
+ const {
85
+ table,
86
+ type,
87
+ or: orExpr = [],
88
+ prefix = 'into',
89
+ columns,
90
+ conflict,
91
+ values,
92
+ where,
93
+ on_duplicate_update: onDuplicateUpdate,
94
+ partition,
95
+ returning,
96
+ set
97
+ } = stmt;
98
+ const {
99
+ keyword,
100
+ set: duplicateSet
101
+ } = onDuplicateUpdate || {};
102
+ const clauses = [(0, _util.toUpper)(type), orExpr.map(_util.literalToSQL).join(' '), (0, _util.toUpper)(prefix), (0, _tables.tablesToSQL)(table), partitionToSQL(partition)];
103
+ if (Array.isArray(columns)) clauses.push(`(${columns.map(_util.literalToSQL).join(', ')})`);
104
+ clauses.push((0, _util.commonOptionConnector)(Array.isArray(values) ? 'VALUES' : '', valuesToSQL, values));
105
+ clauses.push((0, _util.commonOptionConnector)('ON CONFLICT', conflictToSQL, conflict));
106
+ clauses.push((0, _util.commonOptionConnector)('SET', _update.setToSQL, set));
107
+ clauses.push((0, _util.commonOptionConnector)('WHERE', _expr.exprToSQL, where));
108
+ clauses.push((0, _util.commonOptionConnector)(keyword, _update.setToSQL, duplicateSet));
109
+ clauses.push((0, _util.returningToSQL)(returning));
110
+ return clauses.filter(_util.hasVal).join(' ');
111
+ }
112
+ });
@@ -0,0 +1,29 @@
1
+ (function (global, factory) {
2
+ if (typeof define === "function" && define.amd) {
3
+ define(["exports", "./util", "./expr"], factory);
4
+ } else if (typeof exports !== "undefined") {
5
+ factory(exports, require("./util"), require("./expr"));
6
+ } else {
7
+ var mod = {
8
+ exports: {}
9
+ };
10
+ factory(mod.exports, global.util, global.expr);
11
+ global.interval = mod.exports;
12
+ }
13
+ })(typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : this, function (_exports, _util, _expr) {
14
+ "use strict";
15
+
16
+ Object.defineProperty(_exports, "__esModule", {
17
+ value: true
18
+ });
19
+ _exports.intervalToSQL = intervalToSQL;
20
+ function intervalToSQL(intervalExpr) {
21
+ const {
22
+ expr,
23
+ unit,
24
+ suffix
25
+ } = intervalExpr;
26
+ const result = ['INTERVAL', (0, _expr.exprToSQL)(expr), (0, _util.toUpper)(unit), (0, _expr.exprToSQL)(suffix)];
27
+ return result.filter(_util.hasVal).join(' ');
28
+ }
29
+ });
@@ -0,0 +1,36 @@
1
+ (function (global, factory) {
2
+ if (typeof define === "function" && define.amd) {
3
+ define(["exports", "./expr", "./util"], factory);
4
+ } else if (typeof exports !== "undefined") {
5
+ factory(exports, require("./expr"), require("./util"));
6
+ } else {
7
+ var mod = {
8
+ exports: {}
9
+ };
10
+ factory(mod.exports, global.expr, global.util);
11
+ global.json = mod.exports;
12
+ }
13
+ })(typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : this, function (_exports, _expr, _util) {
14
+ "use strict";
15
+
16
+ Object.defineProperty(_exports, "__esModule", {
17
+ value: true
18
+ });
19
+ _exports.jsonExprToSQL = jsonExprToSQL;
20
+ _exports.jsonVisitorExprToSQL = jsonVisitorExprToSQL;
21
+ function jsonExprToSQL(expr) {
22
+ const {
23
+ keyword,
24
+ expr_list: exprList
25
+ } = expr;
26
+ const result = [(0, _util.toUpper)(keyword), exprList.map(exprItem => (0, _expr.exprToSQL)(exprItem)).join(', ')].join(' ');
27
+ return result;
28
+ }
29
+ function jsonVisitorExprToSQL(stmt) {
30
+ const {
31
+ symbol,
32
+ expr
33
+ } = stmt;
34
+ return [symbol, (0, _expr.exprToSQL)(expr)].join('');
35
+ }
36
+ });