@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,45 @@
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.limit = 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.limitToSQL = limitToSQL;
20
+ function composePrefixValSuffix(stmt) {
21
+ if (!stmt) return [];
22
+ return [stmt.prefix.map(_util.literalToSQL).join(' '), (0, _expr.exprToSQL)(stmt.value), stmt.suffix.map(_util.literalToSQL).join(' ')];
23
+ }
24
+ function fetchOffsetToSQL(stmt) {
25
+ const {
26
+ fetch,
27
+ offset
28
+ } = stmt;
29
+ const result = [...composePrefixValSuffix(offset), ...composePrefixValSuffix(fetch)];
30
+ return result.filter(_util.hasVal).join(' ');
31
+ }
32
+ function limitOffsetToSQL(limit) {
33
+ const {
34
+ seperator,
35
+ value
36
+ } = limit;
37
+ if (value.length === 1 && seperator === 'offset') return (0, _util.connector)('OFFSET', (0, _expr.exprToSQL)(value[0]));
38
+ return (0, _util.connector)('LIMIT', value.map(_expr.exprToSQL).join(`${seperator === 'offset' ? ' ' : ''}${(0, _util.toUpper)(seperator)} `));
39
+ }
40
+ function limitToSQL(limit) {
41
+ if (!limit) return '';
42
+ if (limit.fetch || limit.offset) return fetchOffsetToSQL(limit);
43
+ return limitOffsetToSQL(limit);
44
+ }
45
+ });
@@ -0,0 +1,39 @@
1
+ (function (global, factory) {
2
+ if (typeof define === "function" && define.amd) {
3
+ define(["exports", "./util", "./expr", "./window"], factory);
4
+ } else if (typeof exports !== "undefined") {
5
+ factory(exports, require("./util"), require("./expr"), require("./window"));
6
+ } else {
7
+ var mod = {
8
+ exports: {}
9
+ };
10
+ factory(mod.exports, global.util, global.expr, global.window);
11
+ global.over = mod.exports;
12
+ }
13
+ })(typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : this, function (_exports, _util, _expr, _window) {
14
+ "use strict";
15
+
16
+ Object.defineProperty(_exports, "__esModule", {
17
+ value: true
18
+ });
19
+ _exports.overToSQL = overToSQL;
20
+ function overToSQL(over) {
21
+ if (!over) return;
22
+ const {
23
+ as_window_specification: asWindowSpec,
24
+ expr,
25
+ keyword,
26
+ type,
27
+ parentheses
28
+ } = over;
29
+ const upperType = (0, _util.toUpper)(type);
30
+ if (upperType === 'WINDOW') return `OVER ${(0, _window.asWindowSpecToSQL)(asWindowSpec)}`;
31
+ if (upperType === 'ON UPDATE') {
32
+ let onUpdate = `${(0, _util.toUpper)(type)} ${(0, _util.toUpper)(keyword)}`;
33
+ const args = (0, _expr.exprToSQL)(expr) || [];
34
+ if (parentheses) onUpdate = `${onUpdate}(${args.join(', ')})`;
35
+ return onUpdate;
36
+ }
37
+ throw new Error('unknown over type');
38
+ }
39
+ });
@@ -0,0 +1,36 @@
1
+ (function (global, factory) {
2
+ if (typeof define === "function" && define.amd) {
3
+ define(["exports", "../pegjs/athena.pegjs", "../pegjs/bigquery.pegjs", "../pegjs/db2.pegjs", "../pegjs/flinksql.pegjs", "../pegjs/hive.pegjs", "../pegjs/mysql.pegjs", "../pegjs/mariadb.pegjs", "../pegjs/noql.pegjs", "../pegjs/postgresql.pegjs", "../pegjs/redshift.pegjs", "../pegjs/sqlite.pegjs", "../pegjs/transactsql.pegjs", "../pegjs/snowflake.pegjs", "../pegjs/trino.pegjs"], factory);
4
+ } else if (typeof exports !== "undefined") {
5
+ factory(exports, require("../pegjs/athena.pegjs"), require("../pegjs/bigquery.pegjs"), require("../pegjs/db2.pegjs"), require("../pegjs/flinksql.pegjs"), require("../pegjs/hive.pegjs"), require("../pegjs/mysql.pegjs"), require("../pegjs/mariadb.pegjs"), require("../pegjs/noql.pegjs"), require("../pegjs/postgresql.pegjs"), require("../pegjs/redshift.pegjs"), require("../pegjs/sqlite.pegjs"), require("../pegjs/transactsql.pegjs"), require("../pegjs/snowflake.pegjs"), require("../pegjs/trino.pegjs"));
6
+ } else {
7
+ var mod = {
8
+ exports: {}
9
+ };
10
+ factory(mod.exports, global.athena, global.bigquery, global.db2, global.flinksql, global.hive, global.mysql, global.mariadb, global.noql, global.postgresql, global.redshift, global.sqlite, global.transactsql, global.snowflake, global.trino);
11
+ global.parserAll = mod.exports;
12
+ }
13
+ })(typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : this, function (_exports, _athena, _bigquery, _db, _flinksql, _hive, _mysql, _mariadb, _noql, _postgresql, _redshift, _sqlite, _transactsql, _snowflake, _trino) {
14
+ "use strict";
15
+
16
+ Object.defineProperty(_exports, "__esModule", {
17
+ value: true
18
+ });
19
+ _exports.default = void 0;
20
+ var _default = _exports.default = {
21
+ athena: _athena.parse,
22
+ bigquery: _bigquery.parse,
23
+ db2: _db.parse,
24
+ flinksql: _flinksql.parse,
25
+ hive: _hive.parse,
26
+ mysql: _mysql.parse,
27
+ mariadb: _mariadb.parse,
28
+ noql: _noql.parse,
29
+ postgresql: _postgresql.parse,
30
+ redshift: _redshift.parse,
31
+ snowflake: _snowflake.parse,
32
+ sqlite: _sqlite.parse,
33
+ transactsql: _transactsql.parse,
34
+ trino: _trino.parse
35
+ };
36
+ });
@@ -0,0 +1,88 @@
1
+ (function (global, factory) {
2
+ if (typeof define === "function" && define.amd) {
3
+ define(["exports", "./column", "./expr", "./parser.all", "./sql", "./util"], factory);
4
+ } else if (typeof exports !== "undefined") {
5
+ factory(exports, require("./column"), require("./expr"), require("./parser.all"), require("./sql"), require("./util"));
6
+ } else {
7
+ var mod = {
8
+ exports: {}
9
+ };
10
+ factory(mod.exports, global.column, global.expr, global.parser, global.sql, global.util);
11
+ global.parser = mod.exports;
12
+ }
13
+ })(typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : this, function (_exports, _column, _expr, _parser, _sql, _util) {
14
+ "use strict";
15
+
16
+ Object.defineProperty(_exports, "__esModule", {
17
+ value: true
18
+ });
19
+ _exports.default = void 0;
20
+ _parser = _interopRequireDefault(_parser);
21
+ _sql = _interopRequireDefault(_sql);
22
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
23
+ class Parser {
24
+ astify(sql, opt = _util.DEFAULT_OPT) {
25
+ const astInfo = this.parse(sql, opt);
26
+ return astInfo && astInfo.ast;
27
+ }
28
+ sqlify(ast, opt = _util.DEFAULT_OPT) {
29
+ (0, _util.setParserOpt)(opt);
30
+ return (0, _sql.default)(ast, opt);
31
+ }
32
+ exprToSQL(expr, opt = _util.DEFAULT_OPT) {
33
+ (0, _util.setParserOpt)(opt);
34
+ return (0, _expr.exprToSQL)(expr);
35
+ }
36
+ columnsToSQL(columns, tables, opt = _util.DEFAULT_OPT) {
37
+ (0, _util.setParserOpt)(opt);
38
+ if (!columns || columns === '*') return [];
39
+ const isDual = (0, _column.getDual)(tables);
40
+ return columns.map(col => (0, _column.columnToSQL)(col, isDual));
41
+ }
42
+ parse(sql, opt = _util.DEFAULT_OPT) {
43
+ const {
44
+ database = PARSER_NAME || 'mysql'
45
+ } = opt;
46
+ (0, _util.setParserOpt)(opt);
47
+ const typeCase = database.toLowerCase();
48
+ if (_parser.default[typeCase]) return _parser.default[typeCase](opt.trimQuery === false ? sql : sql.trim(), opt.parseOptions || _util.DEFAULT_OPT.parseOptions);
49
+ throw new Error(`${database} is not supported currently`);
50
+ }
51
+ whiteListCheck(sql, whiteList, opt = _util.DEFAULT_OPT) {
52
+ if (!whiteList || whiteList.length === 0) return;
53
+ const {
54
+ type = 'table'
55
+ } = opt;
56
+ if (!this[`${type}List`] || typeof this[`${type}List`] !== 'function') throw new Error(`${type} is not valid check mode`);
57
+ const checkFun = this[`${type}List`].bind(this);
58
+ const authorityList = checkFun(sql, opt);
59
+ let hasAuthority = true;
60
+ let denyInfo = '';
61
+ for (const authority of authorityList) {
62
+ let hasCorrespondingAuthority = false;
63
+ for (const whiteAuthority of whiteList) {
64
+ const regex = new RegExp(`^${whiteAuthority}$`, 'i');
65
+ if (regex.test(authority)) {
66
+ hasCorrespondingAuthority = true;
67
+ break;
68
+ }
69
+ }
70
+ if (!hasCorrespondingAuthority) {
71
+ denyInfo = authority;
72
+ hasAuthority = false;
73
+ break;
74
+ }
75
+ }
76
+ if (!hasAuthority) throw new Error(`authority = '${denyInfo}' is required in ${type} whiteList to execute SQL = '${sql}'`);
77
+ }
78
+ tableList(sql, opt) {
79
+ const astInfo = this.parse(sql, opt);
80
+ return astInfo && astInfo.tableList;
81
+ }
82
+ columnList(sql, opt) {
83
+ const astInfo = this.parse(sql, opt);
84
+ return astInfo && astInfo.columnList;
85
+ }
86
+ }
87
+ var _default = _exports.default = Parser;
88
+ });
@@ -0,0 +1,23 @@
1
+ (function (global, factory) {
2
+ if (typeof define === "function" && define.amd) {
3
+ define(["exports", "../pegjs/mysql.pegjs"], factory);
4
+ } else if (typeof exports !== "undefined") {
5
+ factory(exports, require("../pegjs/mysql.pegjs"));
6
+ } else {
7
+ var mod = {
8
+ exports: {}
9
+ };
10
+ factory(mod.exports, global.mysql);
11
+ global.parserSingle = mod.exports;
12
+ }
13
+ })(typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : this, function (_exports, _mysql) {
14
+ "use strict";
15
+
16
+ Object.defineProperty(_exports, "__esModule", {
17
+ value: true
18
+ });
19
+ _exports.default = void 0;
20
+ var _default = _exports.default = {
21
+ [PARSER_NAME]: _mysql.parse
22
+ };
23
+ });
@@ -0,0 +1,39 @@
1
+ (function (global, factory) {
2
+ if (typeof define === "function" && define.amd) {
3
+ define(["exports", "./assign", "./expr", "./util"], factory);
4
+ } else if (typeof exports !== "undefined") {
5
+ factory(exports, require("./assign"), require("./expr"), require("./util"));
6
+ } else {
7
+ var mod = {
8
+ exports: {}
9
+ };
10
+ factory(mod.exports, global.assign, global.expr, global.util);
11
+ global.proc = mod.exports;
12
+ }
13
+ })(typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : this, function (_exports, _assign, _expr, _util) {
14
+ "use strict";
15
+
16
+ Object.defineProperty(_exports, "__esModule", {
17
+ value: true
18
+ });
19
+ _exports.procToSQL = procToSQL;
20
+ _exports.returnToSQL = returnToSQL;
21
+ function returnToSQL(stmt) {
22
+ const {
23
+ type,
24
+ expr
25
+ } = stmt;
26
+ return [(0, _util.toUpper)(type), (0, _expr.exprToSQL)(expr)].join(' ');
27
+ }
28
+ function procToSQL(expr) {
29
+ const {
30
+ stmt
31
+ } = expr;
32
+ switch (stmt.type) {
33
+ case 'assign':
34
+ return (0, _assign.assignToSQL)(stmt);
35
+ case 'return':
36
+ return returnToSQL(stmt);
37
+ }
38
+ }
39
+ });
@@ -0,0 +1,138 @@
1
+ (function (global, factory) {
2
+ if (typeof define === "function" && define.amd) {
3
+ define(["exports", "./expr", "./column", "./limit", "./with", "./tables", "./util", "./collate"], factory);
4
+ } else if (typeof exports !== "undefined") {
5
+ factory(exports, require("./expr"), require("./column"), require("./limit"), require("./with"), require("./tables"), require("./util"), require("./collate"));
6
+ } else {
7
+ var mod = {
8
+ exports: {}
9
+ };
10
+ factory(mod.exports, global.expr, global.column, global.limit, global._with, global.tables, global.util, global.collate);
11
+ global.select = mod.exports;
12
+ }
13
+ })(typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : this, function (_exports, _expr, _column, _limit, _with, _tables, _util, _collate) {
14
+ "use strict";
15
+
16
+ Object.defineProperty(_exports, "__esModule", {
17
+ value: true
18
+ });
19
+ _exports.selectIntoToSQL = selectIntoToSQL;
20
+ _exports.selectToSQL = selectToSQL;
21
+ function distinctToSQL(distinct) {
22
+ if (!distinct) return;
23
+ if (typeof distinct === 'string') return distinct;
24
+ const {
25
+ type,
26
+ columns
27
+ } = distinct;
28
+ const result = [(0, _util.toUpper)(type)];
29
+ if (columns) result.push(`(${columns.map(_expr.exprToSQL).join(', ')})`);
30
+ return result.filter(_util.hasVal).join(' ');
31
+ }
32
+ function selectIntoToSQL(into) {
33
+ if (!into) return;
34
+ const {
35
+ position
36
+ } = into;
37
+ if (!position) return;
38
+ const {
39
+ keyword,
40
+ expr
41
+ } = into;
42
+ const result = [];
43
+ const intoType = (0, _util.toUpper)(keyword);
44
+ switch (intoType) {
45
+ case 'VAR':
46
+ result.push(expr.map(_expr.varToSQL).join(', '));
47
+ break;
48
+ default:
49
+ result.push(intoType, typeof expr === 'string' ? (0, _util.identifierToSql)(expr) : (0, _expr.exprToSQL)(expr));
50
+ }
51
+ return result.filter(_util.hasVal).join(' ');
52
+ }
53
+ /**
54
+ * @param {Object} stmt
55
+ * @param {?Array} stmt.with
56
+ * @param {?Array} stmt.options
57
+ * @param {?string} stmt.distinct
58
+ * @param {?Array|string} stmt.columns
59
+ * @param {?Array} stmt.from
60
+ * @param {?Object} stmt.where
61
+ * @param {?Array} stmt.groupby
62
+ * @param {?Object} stmt.having
63
+ * @param {?Array} stmt.orderby
64
+ * @param {?Array} stmt.limit
65
+ * @return {string}
66
+ */
67
+
68
+ function forXmlToSQL(stmt) {
69
+ if (!stmt) return;
70
+ const {
71
+ expr,
72
+ keyword,
73
+ type
74
+ } = stmt;
75
+ const result = [(0, _util.toUpper)(type), (0, _util.toUpper)(keyword)];
76
+ if (!expr) return result.join(' ');
77
+ return `${result.join(' ')}(${(0, _expr.exprToSQL)(expr)})`;
78
+ }
79
+ function selectToSQL(stmt) {
80
+ const {
81
+ as_struct_val: asStructVal,
82
+ columns,
83
+ collate,
84
+ distinct,
85
+ for: forXml,
86
+ from,
87
+ for_sys_time_as_of: forSystem = {},
88
+ locking_read: lockingRead,
89
+ groupby,
90
+ having,
91
+ into = {},
92
+ isolation,
93
+ limit,
94
+ options,
95
+ orderby,
96
+ parentheses_symbol: parentheses,
97
+ qualify,
98
+ top,
99
+ window: windowInfo,
100
+ with: withInfo,
101
+ where
102
+ } = stmt;
103
+ const clauses = [(0, _with.withToSQL)(withInfo), 'SELECT', (0, _util.toUpper)(asStructVal)];
104
+ if (Array.isArray(options)) clauses.push(options.join(' '));
105
+ clauses.push(distinctToSQL(distinct), (0, _util.topToSQL)(top), (0, _column.columnsToSQL)(columns, from));
106
+ const {
107
+ position
108
+ } = into;
109
+ let intoSQL = '';
110
+ if (position) intoSQL = (0, _util.commonOptionConnector)('INTO', selectIntoToSQL, into);
111
+ if (position === 'column') clauses.push(intoSQL);
112
+ // FROM + joins
113
+ clauses.push((0, _util.commonOptionConnector)('FROM', _tables.tablesToSQL, from));
114
+ if (position === 'from') clauses.push(intoSQL);
115
+ const {
116
+ keyword,
117
+ expr
118
+ } = forSystem || {};
119
+ clauses.push((0, _util.commonOptionConnector)(keyword, _expr.exprToSQL, expr));
120
+ clauses.push((0, _util.commonOptionConnector)('WHERE', _expr.exprToSQL, where));
121
+ if (groupby) {
122
+ clauses.push((0, _util.connector)('GROUP BY', (0, _expr.getExprListSQL)(groupby.columns).join(', ')));
123
+ clauses.push((0, _expr.getExprListSQL)(groupby.modifiers).join(', '));
124
+ }
125
+ clauses.push((0, _util.commonOptionConnector)('HAVING', _expr.exprToSQL, having));
126
+ clauses.push((0, _util.commonOptionConnector)('QUALIFY', _expr.exprToSQL, qualify));
127
+ clauses.push((0, _util.commonOptionConnector)('WINDOW', _expr.exprToSQL, windowInfo));
128
+ clauses.push((0, _expr.orderOrPartitionByToSQL)(orderby, 'order by'));
129
+ clauses.push((0, _collate.collateToSQL)(collate));
130
+ clauses.push((0, _limit.limitToSQL)(limit));
131
+ if (isolation) clauses.push((0, _util.commonOptionConnector)(isolation.keyword, _util.literalToSQL, isolation.expr));
132
+ clauses.push((0, _util.toUpper)(lockingRead));
133
+ if (position === 'end') clauses.push(intoSQL);
134
+ clauses.push(forXmlToSQL(forXml));
135
+ const sql = clauses.filter(_util.hasVal).join(' ');
136
+ return parentheses ? `(${sql})` : sql;
137
+ }
138
+ });
@@ -0,0 +1,89 @@
1
+ (function (global, factory) {
2
+ if (typeof define === "function" && define.amd) {
3
+ define(["exports", "./expr", "./limit", "./tables", "./util"], factory);
4
+ } else if (typeof exports !== "undefined") {
5
+ factory(exports, require("./expr"), require("./limit"), require("./tables"), require("./util"));
6
+ } else {
7
+ var mod = {
8
+ exports: {}
9
+ };
10
+ factory(mod.exports, global.expr, global.limit, global.tables, global.util);
11
+ global.show = mod.exports;
12
+ }
13
+ })(typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : this, function (_exports, _expr, _limit, _tables, _util) {
14
+ "use strict";
15
+
16
+ Object.defineProperty(_exports, "__esModule", {
17
+ value: true
18
+ });
19
+ _exports.showToSQL = showToSQL;
20
+ function showEventToSQL(showEventExpr) {
21
+ const {
22
+ in: inClause,
23
+ from,
24
+ limit
25
+ } = showEventExpr;
26
+ return [(0, _util.commonOptionConnector)('IN', _util.literalToSQL, inClause && inClause.right), (0, _util.commonOptionConnector)('FROM', _tables.tablesToSQL, from), (0, _limit.limitToSQL)(limit)].filter(_util.hasVal).join(' ');
27
+ }
28
+ function showLikeAndWhereToSQL(showCharacterSetExpr) {
29
+ const {
30
+ expr
31
+ } = showCharacterSetExpr;
32
+ if (!expr) return;
33
+ const {
34
+ op
35
+ } = expr;
36
+ if ((0, _util.toUpper)(op) === 'LIKE') return (0, _util.commonOptionConnector)('LIKE', _util.literalToSQL, expr.right);
37
+ return (0, _util.commonOptionConnector)('WHERE', _expr.exprToSQL, expr);
38
+ }
39
+ function showGrantsForUser(showGrantsForExpr) {
40
+ const {
41
+ for: forExpr
42
+ } = showGrantsForExpr;
43
+ if (!forExpr) return;
44
+ const {
45
+ user,
46
+ host,
47
+ role_list
48
+ } = forExpr;
49
+ let userAndHost = `'${user}'`;
50
+ if (host) userAndHost += `@'${host}'`;
51
+ return ['FOR', userAndHost, role_list && 'USING', role_list && role_list.map(role => `'${role}'`).join(', ')].filter(_util.hasVal).join(' ');
52
+ }
53
+ function showToSQL(showExpr) {
54
+ let {
55
+ keyword
56
+ } = showExpr;
57
+ const {
58
+ suffix
59
+ } = showExpr;
60
+ let str = '';
61
+ switch ((0, _util.toUpper)(keyword)) {
62
+ case 'BINLOG':
63
+ str = showEventToSQL(showExpr);
64
+ break;
65
+ case 'CHARACTER':
66
+ case 'COLLATION':
67
+ str = showLikeAndWhereToSQL(showExpr);
68
+ break;
69
+ case 'COLUMNS':
70
+ case 'INDEXES':
71
+ case 'INDEX':
72
+ str = (0, _util.commonOptionConnector)('FROM', _tables.tablesToSQL, showExpr.from);
73
+ break;
74
+ case 'GRANTS':
75
+ str = showGrantsForUser(showExpr);
76
+ break;
77
+ case 'CREATE':
78
+ str = (0, _util.commonOptionConnector)('', _tables.tableToSQL, showExpr[suffix]);
79
+ break;
80
+ case 'VAR':
81
+ str = (0, _expr.varToSQL)(showExpr.var);
82
+ keyword = '';
83
+ break;
84
+ default:
85
+ break;
86
+ }
87
+ return ['SHOW', (0, _util.toUpper)(keyword), (0, _util.toUpper)(suffix), str].filter(_util.hasVal).join(' ');
88
+ }
89
+ });
@@ -0,0 +1,43 @@
1
+ (function (global, factory) {
2
+ if (typeof define === "function" && define.amd) {
3
+ define(["exports", "./union"], factory);
4
+ } else if (typeof exports !== "undefined") {
5
+ factory(exports, require("./union"));
6
+ } else {
7
+ var mod = {
8
+ exports: {}
9
+ };
10
+ factory(mod.exports, global.union);
11
+ global.sql = mod.exports;
12
+ }
13
+ })(typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : this, function (_exports, _union) {
14
+ "use strict";
15
+
16
+ Object.defineProperty(_exports, "__esModule", {
17
+ value: true
18
+ });
19
+ _exports.default = astToSQL;
20
+ const supportedTypes = ['analyze', 'attach', 'select', 'deallocate', 'delete', 'exec', 'update', 'insert', 'drop', 'rename', 'truncate', 'call', 'desc', 'use', 'alter', 'set', 'create', 'lock', 'unlock', 'declare', 'show', 'replace', 'if', 'grant', 'revoke', 'proc', 'raise', 'execute', 'transaction', 'explain', 'comment'];
21
+ function checkSupported(expr) {
22
+ const ast = expr && expr.ast ? expr.ast : expr;
23
+ if (!supportedTypes.includes(ast.type)) throw new Error(`${ast.type} statements not supported at the moment`);
24
+ }
25
+ function toSQL(ast) {
26
+ if (Array.isArray(ast)) {
27
+ ast.forEach(checkSupported);
28
+ return (0, _union.multipleToSQL)(ast);
29
+ }
30
+ checkSupported(ast);
31
+ return (0, _union.unionToSQL)(ast);
32
+ }
33
+ function goToSQL(stmt) {
34
+ if (!stmt || stmt.length === 0) return '';
35
+ const res = [toSQL(stmt.ast)];
36
+ if (stmt.go_next) res.push(stmt.go.toUpperCase(), goToSQL(stmt.go_next));
37
+ return res.filter(sqlItem => sqlItem).join(' ');
38
+ }
39
+ function astToSQL(ast) {
40
+ const sql = ast.go === 'go' ? goToSQL(ast) : toSQL(ast);
41
+ return sql;
42
+ }
43
+ });