@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.
- package/dist/externalVersion.js +2 -2
- package/{LICENSE → dist/node_modules/node-sql-parser/LICENSE} +3 -3
- package/dist/node_modules/node-sql-parser/ast/postgresql.ts +2063 -0
- package/dist/node_modules/node-sql-parser/build/athena.d.ts +1 -0
- package/dist/node_modules/node-sql-parser/build/athena.js +2 -0
- package/dist/node_modules/node-sql-parser/build/bigquery.d.ts +1 -0
- package/dist/node_modules/node-sql-parser/build/bigquery.js +2 -0
- package/dist/node_modules/node-sql-parser/build/db2.d.ts +1 -0
- package/dist/node_modules/node-sql-parser/build/db2.js +2 -0
- package/dist/node_modules/node-sql-parser/build/flinksql.d.ts +1 -0
- package/dist/node_modules/node-sql-parser/build/flinksql.js +2 -0
- package/dist/node_modules/node-sql-parser/build/hive.d.ts +1 -0
- package/dist/node_modules/node-sql-parser/build/hive.js +2 -0
- package/dist/node_modules/node-sql-parser/build/mariadb.d.ts +1 -0
- package/dist/node_modules/node-sql-parser/build/mariadb.js +2 -0
- package/dist/node_modules/node-sql-parser/build/mysql.d.ts +1 -0
- package/dist/node_modules/node-sql-parser/build/mysql.js +2 -0
- package/dist/node_modules/node-sql-parser/build/noql.d.ts +1 -0
- package/dist/node_modules/node-sql-parser/build/noql.js +2 -0
- package/dist/node_modules/node-sql-parser/build/postgresql.d.ts +1 -0
- package/dist/node_modules/node-sql-parser/build/postgresql.js +2 -0
- package/dist/node_modules/node-sql-parser/build/redshift.d.ts +1 -0
- package/dist/node_modules/node-sql-parser/build/redshift.js +2 -0
- package/dist/node_modules/node-sql-parser/build/snowflake.d.ts +1 -0
- package/dist/node_modules/node-sql-parser/build/snowflake.js +2 -0
- package/dist/node_modules/node-sql-parser/build/sqlite.d.ts +1 -0
- package/dist/node_modules/node-sql-parser/build/sqlite.js +2 -0
- package/dist/node_modules/node-sql-parser/build/transactsql.d.ts +1 -0
- package/dist/node_modules/node-sql-parser/build/transactsql.js +2 -0
- package/dist/node_modules/node-sql-parser/build/trino.d.ts +1 -0
- package/dist/node_modules/node-sql-parser/build/trino.js +2 -0
- package/dist/node_modules/node-sql-parser/index.d.ts +1 -0
- package/dist/node_modules/node-sql-parser/index.js +1 -0
- package/dist/node_modules/node-sql-parser/lib/aggregation.js +42 -0
- package/dist/node_modules/node-sql-parser/lib/alter.js +211 -0
- package/dist/node_modules/node-sql-parser/lib/analyze.js +40 -0
- package/dist/node_modules/node-sql-parser/lib/array-struct.js +60 -0
- package/dist/node_modules/node-sql-parser/lib/assign.js +33 -0
- package/dist/node_modules/node-sql-parser/lib/binary.js +48 -0
- package/dist/node_modules/node-sql-parser/lib/case.js +39 -0
- package/dist/node_modules/node-sql-parser/lib/collate.js +37 -0
- package/dist/node_modules/node-sql-parser/lib/column.js +259 -0
- package/dist/node_modules/node-sql-parser/lib/command.js +306 -0
- package/dist/node_modules/node-sql-parser/lib/comment.js +53 -0
- package/dist/node_modules/node-sql-parser/lib/constrain.js +49 -0
- package/dist/node_modules/node-sql-parser/lib/create.js +496 -0
- package/dist/node_modules/node-sql-parser/lib/delete.js +44 -0
- package/dist/node_modules/node-sql-parser/lib/exec.js +37 -0
- package/dist/node_modules/node-sql-parser/lib/explain.js +27 -0
- package/dist/node_modules/node-sql-parser/lib/expr.js +147 -0
- package/dist/node_modules/node-sql-parser/lib/func.js +231 -0
- package/dist/node_modules/node-sql-parser/lib/index-definition.js +106 -0
- package/dist/node_modules/node-sql-parser/lib/insert.js +112 -0
- package/dist/node_modules/node-sql-parser/lib/interval.js +29 -0
- package/dist/node_modules/node-sql-parser/lib/json.js +36 -0
- package/dist/node_modules/node-sql-parser/lib/limit.js +45 -0
- package/dist/node_modules/node-sql-parser/lib/over.js +39 -0
- package/dist/node_modules/node-sql-parser/lib/parser.all.js +36 -0
- package/dist/node_modules/node-sql-parser/lib/parser.js +88 -0
- package/dist/node_modules/node-sql-parser/lib/parser.single.js +23 -0
- package/dist/node_modules/node-sql-parser/lib/proc.js +39 -0
- package/dist/node_modules/node-sql-parser/lib/select.js +138 -0
- package/dist/node_modules/node-sql-parser/lib/show.js +89 -0
- package/dist/node_modules/node-sql-parser/lib/sql.js +43 -0
- package/dist/node_modules/node-sql-parser/lib/tables.js +277 -0
- package/dist/node_modules/node-sql-parser/lib/transaction.js +32 -0
- package/dist/node_modules/node-sql-parser/lib/union.js +83 -0
- package/dist/node_modules/node-sql-parser/lib/update.js +62 -0
- package/dist/node_modules/node-sql-parser/lib/util.js +458 -0
- package/dist/node_modules/node-sql-parser/lib/window.js +84 -0
- package/dist/node_modules/node-sql-parser/lib/with.js +37 -0
- package/dist/node_modules/node-sql-parser/package.json +1 -0
- package/dist/node_modules/node-sql-parser/types.d.ts +555 -0
- package/dist/node_modules/node-sql-parser/umd/athena.umd.d.ts +1 -0
- package/dist/node_modules/node-sql-parser/umd/athena.umd.js +2 -0
- package/dist/node_modules/node-sql-parser/umd/bigquery.umd.d.ts +1 -0
- package/dist/node_modules/node-sql-parser/umd/bigquery.umd.js +2 -0
- package/dist/node_modules/node-sql-parser/umd/db2.umd.d.ts +1 -0
- package/dist/node_modules/node-sql-parser/umd/db2.umd.js +2 -0
- package/dist/node_modules/node-sql-parser/umd/flinksql.umd.d.ts +1 -0
- package/dist/node_modules/node-sql-parser/umd/flinksql.umd.js +2 -0
- package/dist/node_modules/node-sql-parser/umd/hive.umd.d.ts +1 -0
- package/dist/node_modules/node-sql-parser/umd/hive.umd.js +2 -0
- package/dist/node_modules/node-sql-parser/umd/index.umd.d.ts +1 -0
- package/dist/node_modules/node-sql-parser/umd/index.umd.js +2 -0
- package/dist/node_modules/node-sql-parser/umd/mariadb.umd.d.ts +1 -0
- package/dist/node_modules/node-sql-parser/umd/mariadb.umd.js +2 -0
- package/dist/node_modules/node-sql-parser/umd/mysql.umd.d.ts +1 -0
- package/dist/node_modules/node-sql-parser/umd/mysql.umd.js +2 -0
- package/dist/node_modules/node-sql-parser/umd/noql.umd.d.ts +1 -0
- package/dist/node_modules/node-sql-parser/umd/noql.umd.js +2 -0
- package/dist/node_modules/node-sql-parser/umd/postgresql.umd.d.ts +1 -0
- package/dist/node_modules/node-sql-parser/umd/postgresql.umd.js +2 -0
- package/dist/node_modules/node-sql-parser/umd/redshift.umd.d.ts +1 -0
- package/dist/node_modules/node-sql-parser/umd/redshift.umd.js +2 -0
- package/dist/node_modules/node-sql-parser/umd/snowflake.umd.d.ts +1 -0
- package/dist/node_modules/node-sql-parser/umd/snowflake.umd.js +2 -0
- package/dist/node_modules/node-sql-parser/umd/sqlite.umd.d.ts +1 -0
- package/dist/node_modules/node-sql-parser/umd/sqlite.umd.js +2 -0
- package/dist/node_modules/node-sql-parser/umd/transactsql.umd.d.ts +1 -0
- package/dist/node_modules/node-sql-parser/umd/transactsql.umd.js +2 -0
- package/dist/node_modules/node-sql-parser/umd/trino.umd.d.ts +1 -0
- package/dist/node_modules/node-sql-parser/umd/trino.umd.js +2 -0
- package/dist/server/repositories/collection-repository.d.ts +3 -0
- package/dist/server/repositories/collection-repository.js +7 -1
- package/dist/server/resourcers/sql.d.ts +28 -1
- package/dist/server/resourcers/sql.js +121 -4
- package/dist/server/resourcers/views.d.ts +14 -0
- package/dist/server/server.d.ts +3 -0
- package/package.json +6 -4
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
(function (global, factory) {
|
|
2
|
+
if (typeof define === "function" && define.amd) {
|
|
3
|
+
define(["exports", "./expr", "./util", "./over"], factory);
|
|
4
|
+
} else if (typeof exports !== "undefined") {
|
|
5
|
+
factory(exports, require("./expr"), require("./util"), require("./over"));
|
|
6
|
+
} else {
|
|
7
|
+
var mod = {
|
|
8
|
+
exports: {}
|
|
9
|
+
};
|
|
10
|
+
factory(mod.exports, global.expr, global.util, global.over);
|
|
11
|
+
global.aggregation = mod.exports;
|
|
12
|
+
}
|
|
13
|
+
})(typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : this, function (_exports, _expr, _util, _over) {
|
|
14
|
+
"use strict";
|
|
15
|
+
|
|
16
|
+
Object.defineProperty(_exports, "__esModule", {
|
|
17
|
+
value: true
|
|
18
|
+
});
|
|
19
|
+
_exports.aggrToSQL = aggrToSQL;
|
|
20
|
+
function aggrToSQL(expr) {
|
|
21
|
+
/** @type {Object} */
|
|
22
|
+
const {
|
|
23
|
+
args,
|
|
24
|
+
filter,
|
|
25
|
+
over,
|
|
26
|
+
within_group_orderby
|
|
27
|
+
} = expr;
|
|
28
|
+
let str = (0, _expr.exprToSQL)(args.expr);
|
|
29
|
+
str = Array.isArray(str) ? str.join(', ') : str;
|
|
30
|
+
const fnName = expr.name;
|
|
31
|
+
const overStr = (0, _over.overToSQL)(over);
|
|
32
|
+
const separator = ' ';
|
|
33
|
+
if (args.distinct) str = ['DISTINCT', str].join(separator);
|
|
34
|
+
if (args.separator && args.separator.delimiter) str = [str, (0, _util.literalToSQL)(args.separator.delimiter)].join(`${args.separator.symbol} `);
|
|
35
|
+
if (args.separator && args.separator.expr) str = [str, (0, _expr.exprToSQL)(args.separator.expr)].join(' ');
|
|
36
|
+
if (args.orderby) str = [str, (0, _expr.orderOrPartitionByToSQL)(args.orderby, 'order by')].join(' ');
|
|
37
|
+
if (args.separator && args.separator.value) str = [str, (0, _util.toUpper)(args.separator.keyword), (0, _util.literalToSQL)(args.separator.value)].filter(_util.hasVal).join(' ');
|
|
38
|
+
const withinGroup = within_group_orderby ? `WITHIN GROUP (${(0, _expr.orderOrPartitionByToSQL)(within_group_orderby, 'order by')})` : '';
|
|
39
|
+
const filterStr = filter ? `FILTER (WHERE ${(0, _expr.exprToSQL)(filter.where)})` : '';
|
|
40
|
+
return [`${fnName}(${str})`, withinGroup, overStr, filterStr].filter(_util.hasVal).join(' ');
|
|
41
|
+
}
|
|
42
|
+
});
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
(function (global, factory) {
|
|
2
|
+
if (typeof define === "function" && define.amd) {
|
|
3
|
+
define(["exports", "./column", "./create", "./index-definition", "./tables", "./expr", "./select", "./util"], factory);
|
|
4
|
+
} else if (typeof exports !== "undefined") {
|
|
5
|
+
factory(exports, require("./column"), require("./create"), require("./index-definition"), require("./tables"), require("./expr"), require("./select"), require("./util"));
|
|
6
|
+
} else {
|
|
7
|
+
var mod = {
|
|
8
|
+
exports: {}
|
|
9
|
+
};
|
|
10
|
+
factory(mod.exports, global.column, global.create, global.indexDefinition, global.tables, global.expr, global.select, global.util);
|
|
11
|
+
global.alter = mod.exports;
|
|
12
|
+
}
|
|
13
|
+
})(typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : this, function (_exports, _column, _create, _indexDefinition, _tables, _expr, _select, _util) {
|
|
14
|
+
"use strict";
|
|
15
|
+
|
|
16
|
+
Object.defineProperty(_exports, "__esModule", {
|
|
17
|
+
value: true
|
|
18
|
+
});
|
|
19
|
+
_exports.alterArgsToSQL = alterArgsToSQL;
|
|
20
|
+
_exports.alterExprToSQL = alterExprToSQL;
|
|
21
|
+
_exports.alterToSQL = alterToSQL;
|
|
22
|
+
function alterExprPartition(action, expr) {
|
|
23
|
+
switch (action) {
|
|
24
|
+
case 'add':
|
|
25
|
+
const sql = expr.map(({
|
|
26
|
+
name,
|
|
27
|
+
value
|
|
28
|
+
}) => ['PARTITION', (0, _util.literalToSQL)(name), 'VALUES', (0, _util.toUpper)(value.type), `(${(0, _util.literalToSQL)(value.expr)})`].join(' ')).join(', ');
|
|
29
|
+
return `(${sql})`;
|
|
30
|
+
default:
|
|
31
|
+
return (0, _column.columnsToSQL)(expr);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
function alterExprToSQL(expr) {
|
|
35
|
+
if (!expr) return '';
|
|
36
|
+
const {
|
|
37
|
+
action,
|
|
38
|
+
create_definitions: createDefinition,
|
|
39
|
+
if_not_exists: ifNotExists,
|
|
40
|
+
keyword,
|
|
41
|
+
if_exists: ifExists,
|
|
42
|
+
old_column: oldColumn,
|
|
43
|
+
prefix,
|
|
44
|
+
resource,
|
|
45
|
+
symbol,
|
|
46
|
+
suffix
|
|
47
|
+
} = expr;
|
|
48
|
+
let name = '';
|
|
49
|
+
let dataType = [];
|
|
50
|
+
switch (resource) {
|
|
51
|
+
case 'column':
|
|
52
|
+
dataType = [(0, _column.columnDefinitionToSQL)(expr)];
|
|
53
|
+
break;
|
|
54
|
+
case 'index':
|
|
55
|
+
dataType = (0, _indexDefinition.indexTypeAndOptionToSQL)(expr);
|
|
56
|
+
name = expr[resource];
|
|
57
|
+
break;
|
|
58
|
+
case 'table':
|
|
59
|
+
case 'schema':
|
|
60
|
+
name = (0, _util.identifierToSql)(expr[resource]);
|
|
61
|
+
break;
|
|
62
|
+
case 'aggregate':
|
|
63
|
+
case 'function':
|
|
64
|
+
case 'domain':
|
|
65
|
+
case 'type':
|
|
66
|
+
name = (0, _util.identifierToSql)(expr[resource]);
|
|
67
|
+
break;
|
|
68
|
+
case 'algorithm':
|
|
69
|
+
case 'lock':
|
|
70
|
+
case 'table-option':
|
|
71
|
+
name = [symbol, (0, _util.toUpper)(expr[resource])].filter(_util.hasVal).join(' ');
|
|
72
|
+
break;
|
|
73
|
+
case 'constraint':
|
|
74
|
+
name = (0, _util.identifierToSql)(expr[resource]);
|
|
75
|
+
dataType = [(0, _create.createDefinitionToSQL)(createDefinition)];
|
|
76
|
+
break;
|
|
77
|
+
case 'partition':
|
|
78
|
+
dataType = [alterExprPartition(action, expr.partitions)];
|
|
79
|
+
break;
|
|
80
|
+
case 'key':
|
|
81
|
+
name = (0, _util.identifierToSql)(expr[resource]);
|
|
82
|
+
break;
|
|
83
|
+
default:
|
|
84
|
+
name = [symbol, expr[resource]].filter(val => val !== null).join(' ');
|
|
85
|
+
break;
|
|
86
|
+
}
|
|
87
|
+
const alterArray = [(0, _util.toUpper)(action), (0, _util.toUpper)(keyword), (0, _util.toUpper)(ifNotExists), (0, _util.toUpper)(ifExists), oldColumn && (0, _column.columnRefToSQL)(oldColumn), (0, _util.toUpper)(prefix), name && name.trim(), dataType.filter(_util.hasVal).join(' ')];
|
|
88
|
+
if (suffix) {
|
|
89
|
+
alterArray.push((0, _util.toUpper)(suffix.keyword), suffix.expr && (0, _column.columnRefToSQL)(suffix.expr));
|
|
90
|
+
}
|
|
91
|
+
return alterArray.filter(_util.hasVal).join(' ');
|
|
92
|
+
}
|
|
93
|
+
function alterTableToSQL(stmt) {
|
|
94
|
+
const {
|
|
95
|
+
type,
|
|
96
|
+
table,
|
|
97
|
+
if_exists,
|
|
98
|
+
prefix,
|
|
99
|
+
expr = []
|
|
100
|
+
} = stmt;
|
|
101
|
+
const action = (0, _util.toUpper)(type);
|
|
102
|
+
const tableName = (0, _tables.tablesToSQL)(table);
|
|
103
|
+
const exprList = expr.map(_expr.exprToSQL);
|
|
104
|
+
const result = [action, 'TABLE', (0, _util.toUpper)(if_exists), (0, _util.literalToSQL)(prefix), tableName, exprList.join(', ')];
|
|
105
|
+
return result.filter(_util.hasVal).join(' ');
|
|
106
|
+
}
|
|
107
|
+
function alterViewToSQL(stmt) {
|
|
108
|
+
const {
|
|
109
|
+
type,
|
|
110
|
+
columns,
|
|
111
|
+
attributes,
|
|
112
|
+
select,
|
|
113
|
+
view,
|
|
114
|
+
with: withExpr
|
|
115
|
+
} = stmt;
|
|
116
|
+
const action = (0, _util.toUpper)(type);
|
|
117
|
+
const viewName = (0, _tables.tableToSQL)(view);
|
|
118
|
+
const result = [action, 'VIEW', viewName];
|
|
119
|
+
if (columns) result.push(`(${columns.map(_column.columnRefToSQL).join(', ')})`);
|
|
120
|
+
if (attributes) result.push(`WITH ${attributes.map(_util.toUpper).join(', ')}`);
|
|
121
|
+
result.push('AS', (0, _select.selectToSQL)(select));
|
|
122
|
+
if (withExpr) result.push((0, _util.toUpper)(withExpr));
|
|
123
|
+
return result.filter(_util.hasVal).join(' ');
|
|
124
|
+
}
|
|
125
|
+
function alterArgsToSQL(arg) {
|
|
126
|
+
const defaultSQL = arg.default && [(0, _util.toUpper)(arg.default.keyword), (0, _expr.exprToSQL)(arg.default.value)].join(' ');
|
|
127
|
+
return [(0, _util.toUpper)(arg.mode), arg.name, (0, _util.dataTypeToSQL)(arg.type), defaultSQL].filter(_util.hasVal).join(' ');
|
|
128
|
+
}
|
|
129
|
+
function alterSchemaToSQL(stmt) {
|
|
130
|
+
const {
|
|
131
|
+
expr,
|
|
132
|
+
keyword,
|
|
133
|
+
schema,
|
|
134
|
+
type
|
|
135
|
+
} = stmt;
|
|
136
|
+
const result = [(0, _util.toUpper)(type), (0, _util.toUpper)(keyword), (0, _util.identifierToSql)(schema), alterExprToSQL(expr)];
|
|
137
|
+
return result.filter(_util.hasVal).join(' ');
|
|
138
|
+
}
|
|
139
|
+
function alterDomainTypeToSQL(stmt) {
|
|
140
|
+
const {
|
|
141
|
+
expr,
|
|
142
|
+
keyword,
|
|
143
|
+
name,
|
|
144
|
+
type
|
|
145
|
+
} = stmt;
|
|
146
|
+
const result = [(0, _util.toUpper)(type), (0, _util.toUpper)(keyword), [(0, _util.identifierToSql)(name.schema), (0, _util.identifierToSql)(name.name)].filter(_util.hasVal).join('.'), alterExprToSQL(expr)];
|
|
147
|
+
return result.filter(_util.hasVal).join(' ');
|
|
148
|
+
}
|
|
149
|
+
function alterFunctionToSQL(stmt) {
|
|
150
|
+
const {
|
|
151
|
+
args,
|
|
152
|
+
expr,
|
|
153
|
+
keyword,
|
|
154
|
+
name,
|
|
155
|
+
type
|
|
156
|
+
} = stmt;
|
|
157
|
+
const result = [(0, _util.toUpper)(type), (0, _util.toUpper)(keyword), [[(0, _util.identifierToSql)(name.schema), (0, _util.identifierToSql)(name.name)].filter(_util.hasVal).join('.'), args && `(${args.expr ? args.expr.map(alterArgsToSQL).join(', ') : ''})`].filter(_util.hasVal).join(''), alterExprToSQL(expr)];
|
|
158
|
+
return result.filter(_util.hasVal).join(' ');
|
|
159
|
+
}
|
|
160
|
+
function alterAggregateToSQL(stmt) {
|
|
161
|
+
const {
|
|
162
|
+
args,
|
|
163
|
+
expr,
|
|
164
|
+
keyword,
|
|
165
|
+
name,
|
|
166
|
+
type
|
|
167
|
+
} = stmt;
|
|
168
|
+
const {
|
|
169
|
+
expr: argsExpr,
|
|
170
|
+
orderby
|
|
171
|
+
} = args;
|
|
172
|
+
const result = [(0, _util.toUpper)(type), (0, _util.toUpper)(keyword), [[(0, _util.identifierToSql)(name.schema), (0, _util.identifierToSql)(name.name)].filter(_util.hasVal).join('.'), `(${argsExpr.map(alterArgsToSQL).join(', ')}${orderby ? [' ORDER', 'BY', orderby.map(alterArgsToSQL).join(', ')].join(' ') : ''})`].filter(_util.hasVal).join(''), alterExprToSQL(expr)];
|
|
173
|
+
return result.filter(_util.hasVal).join(' ');
|
|
174
|
+
}
|
|
175
|
+
function alterSequenceToSQL(stmt) {
|
|
176
|
+
const {
|
|
177
|
+
type,
|
|
178
|
+
keyword,
|
|
179
|
+
sequence,
|
|
180
|
+
if_exists,
|
|
181
|
+
expr = []
|
|
182
|
+
} = stmt;
|
|
183
|
+
const action = (0, _util.toUpper)(type);
|
|
184
|
+
const sequenceName = (0, _tables.tablesToSQL)(sequence);
|
|
185
|
+
const exprList = expr.map(_create.createDefinitionToSQL);
|
|
186
|
+
const result = [action, (0, _util.toUpper)(keyword), (0, _util.toUpper)(if_exists), sequenceName, exprList.join(', ')];
|
|
187
|
+
return result.filter(_util.hasVal).join(' ');
|
|
188
|
+
}
|
|
189
|
+
function alterToSQL(stmt) {
|
|
190
|
+
const {
|
|
191
|
+
keyword = 'table'
|
|
192
|
+
} = stmt;
|
|
193
|
+
switch (keyword) {
|
|
194
|
+
case 'aggregate':
|
|
195
|
+
return alterAggregateToSQL(stmt);
|
|
196
|
+
case 'table':
|
|
197
|
+
return alterTableToSQL(stmt);
|
|
198
|
+
case 'schema':
|
|
199
|
+
return alterSchemaToSQL(stmt);
|
|
200
|
+
case 'sequence':
|
|
201
|
+
return alterSequenceToSQL(stmt);
|
|
202
|
+
case 'domain':
|
|
203
|
+
case 'type':
|
|
204
|
+
return alterDomainTypeToSQL(stmt);
|
|
205
|
+
case 'function':
|
|
206
|
+
return alterFunctionToSQL(stmt);
|
|
207
|
+
case 'view':
|
|
208
|
+
return alterViewToSQL(stmt);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
});
|
|
@@ -0,0 +1,40 @@
|
|
|
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.analyze = 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.analyzeToSQL = analyzeToSQL;
|
|
20
|
+
_exports.attachToSQL = attachToSQL;
|
|
21
|
+
function analyzeToSQL(stmt) {
|
|
22
|
+
const {
|
|
23
|
+
type,
|
|
24
|
+
table
|
|
25
|
+
} = stmt;
|
|
26
|
+
const action = (0, _util.toUpper)(type);
|
|
27
|
+
const tableName = (0, _tables.tableToSQL)(table);
|
|
28
|
+
return [action, tableName].join(' ');
|
|
29
|
+
}
|
|
30
|
+
function attachToSQL(stmt) {
|
|
31
|
+
const {
|
|
32
|
+
type,
|
|
33
|
+
database,
|
|
34
|
+
expr,
|
|
35
|
+
as,
|
|
36
|
+
schema
|
|
37
|
+
} = stmt;
|
|
38
|
+
return [(0, _util.toUpper)(type), (0, _util.toUpper)(database), (0, _expr.exprToSQL)(expr), (0, _util.toUpper)(as), (0, _util.identifierToSql)(schema)].filter(_util.hasVal).join(' ');
|
|
39
|
+
}
|
|
40
|
+
});
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
(function (global, factory) {
|
|
2
|
+
if (typeof define === "function" && define.amd) {
|
|
3
|
+
define(["exports", "./column", "./expr", "./util"], factory);
|
|
4
|
+
} else if (typeof exports !== "undefined") {
|
|
5
|
+
factory(exports, require("./column"), require("./expr"), require("./util"));
|
|
6
|
+
} else {
|
|
7
|
+
var mod = {
|
|
8
|
+
exports: {}
|
|
9
|
+
};
|
|
10
|
+
factory(mod.exports, global.column, global.expr, global.util);
|
|
11
|
+
global.arrayStruct = mod.exports;
|
|
12
|
+
}
|
|
13
|
+
})(typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : this, function (_exports, _column, _expr, _util) {
|
|
14
|
+
"use strict";
|
|
15
|
+
|
|
16
|
+
Object.defineProperty(_exports, "__esModule", {
|
|
17
|
+
value: true
|
|
18
|
+
});
|
|
19
|
+
_exports.arrayStructExprToSQL = arrayStructExprToSQL;
|
|
20
|
+
_exports.arrayStructValueToSQL = arrayStructValueToSQL;
|
|
21
|
+
function arrayExprListToSQL(expr) {
|
|
22
|
+
const {
|
|
23
|
+
array_path: arrayPath,
|
|
24
|
+
brackets,
|
|
25
|
+
expr_list: exprList,
|
|
26
|
+
parentheses
|
|
27
|
+
} = expr;
|
|
28
|
+
if (!exprList) return `[${(0, _column.columnsToSQL)(arrayPath)}]`;
|
|
29
|
+
const result = Array.isArray(exprList) ? exprList.map(col => `(${(0, _column.columnsToSQL)(col)})`).filter(_util.hasVal).join(', ') : (0, _expr.exprToSQL)(exprList);
|
|
30
|
+
if (brackets) return `[${result}]`;
|
|
31
|
+
return parentheses ? `(${result})` : result;
|
|
32
|
+
}
|
|
33
|
+
function arrayStructValueToSQL(expr) {
|
|
34
|
+
const {
|
|
35
|
+
expr_list: exprList,
|
|
36
|
+
type
|
|
37
|
+
} = expr;
|
|
38
|
+
switch ((0, _util.toUpper)(type)) {
|
|
39
|
+
case 'STRUCT':
|
|
40
|
+
return `(${(0, _column.columnsToSQL)(exprList)})`;
|
|
41
|
+
case 'ARRAY':
|
|
42
|
+
return arrayExprListToSQL(expr);
|
|
43
|
+
default:
|
|
44
|
+
return '';
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
function arrayStructExprToSQL(expr) {
|
|
48
|
+
const {
|
|
49
|
+
definition,
|
|
50
|
+
keyword
|
|
51
|
+
} = expr;
|
|
52
|
+
const result = [(0, _util.toUpper)(keyword)];
|
|
53
|
+
if (definition && typeof definition === 'object') {
|
|
54
|
+
result.length = 0;
|
|
55
|
+
result.push((0, _util.arrayStructTypeToSQL)(definition));
|
|
56
|
+
}
|
|
57
|
+
result.push(arrayStructValueToSQL(expr));
|
|
58
|
+
return result.filter(_util.hasVal).join('');
|
|
59
|
+
}
|
|
60
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
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.assign = 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.assignToSQL = assignToSQL;
|
|
20
|
+
function assignToSQL(expr) {
|
|
21
|
+
/** @type {Object} */
|
|
22
|
+
const {
|
|
23
|
+
left,
|
|
24
|
+
right,
|
|
25
|
+
symbol,
|
|
26
|
+
keyword
|
|
27
|
+
} = expr;
|
|
28
|
+
left.keyword = keyword;
|
|
29
|
+
const leftVar = (0, _expr.exprToSQL)(left);
|
|
30
|
+
const rightVal = (0, _expr.exprToSQL)(right);
|
|
31
|
+
return [leftVar, (0, _util.toUpper)(symbol), rightVal].filter(_util.hasVal).join(' ');
|
|
32
|
+
}
|
|
33
|
+
});
|
|
@@ -0,0 +1,48 @@
|
|
|
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.binary = 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.binaryToSQL = binaryToSQL;
|
|
20
|
+
function binaryToSQL(expr) {
|
|
21
|
+
let operator = expr.operator || expr.op;
|
|
22
|
+
let rstr = (0, _expr.exprToSQL)(expr.right);
|
|
23
|
+
let isBetween = false;
|
|
24
|
+
if (Array.isArray(rstr)) {
|
|
25
|
+
switch (operator) {
|
|
26
|
+
case '=':
|
|
27
|
+
operator = 'IN';
|
|
28
|
+
break;
|
|
29
|
+
case '!=':
|
|
30
|
+
operator = 'NOT IN';
|
|
31
|
+
break;
|
|
32
|
+
case 'BETWEEN':
|
|
33
|
+
case 'NOT BETWEEN':
|
|
34
|
+
isBetween = true;
|
|
35
|
+
rstr = `${rstr[0]} AND ${rstr[1]}`;
|
|
36
|
+
break;
|
|
37
|
+
default:
|
|
38
|
+
break;
|
|
39
|
+
}
|
|
40
|
+
if (!isBetween) rstr = `(${rstr.join(', ')})`;
|
|
41
|
+
}
|
|
42
|
+
const escape = expr.right.escape || {};
|
|
43
|
+
const leftPart = Array.isArray(expr.left) ? expr.left.map(_expr.exprToSQL).join(', ') : (0, _expr.exprToSQL)(expr.left);
|
|
44
|
+
const str = [leftPart, operator, rstr, (0, _util.toUpper)(escape.type), (0, _expr.exprToSQL)(escape.value)].filter(_util.hasVal).join(' ');
|
|
45
|
+
const result = [expr.parentheses ? `(${str})` : str];
|
|
46
|
+
return result.join(' ');
|
|
47
|
+
}
|
|
48
|
+
});
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
(function (global, factory) {
|
|
2
|
+
if (typeof define === "function" && define.amd) {
|
|
3
|
+
define(["exports", "./expr"], factory);
|
|
4
|
+
} else if (typeof exports !== "undefined") {
|
|
5
|
+
factory(exports, require("./expr"));
|
|
6
|
+
} else {
|
|
7
|
+
var mod = {
|
|
8
|
+
exports: {}
|
|
9
|
+
};
|
|
10
|
+
factory(mod.exports, global.expr);
|
|
11
|
+
global._case = mod.exports;
|
|
12
|
+
}
|
|
13
|
+
})(typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : this, function (_exports, _expr) {
|
|
14
|
+
"use strict";
|
|
15
|
+
|
|
16
|
+
Object.defineProperty(_exports, "__esModule", {
|
|
17
|
+
value: true
|
|
18
|
+
});
|
|
19
|
+
_exports.caseToSQL = caseToSQL;
|
|
20
|
+
function caseToSQL(expr) {
|
|
21
|
+
const res = ['CASE'];
|
|
22
|
+
const {
|
|
23
|
+
args: conditions,
|
|
24
|
+
expr: exprItem,
|
|
25
|
+
parentheses
|
|
26
|
+
} = expr;
|
|
27
|
+
if (exprItem) res.push((0, _expr.exprToSQL)(exprItem));
|
|
28
|
+
for (let i = 0, len = conditions.length; i < len; ++i) {
|
|
29
|
+
res.push(conditions[i].type.toUpperCase());
|
|
30
|
+
if (conditions[i].cond) {
|
|
31
|
+
res.push((0, _expr.exprToSQL)(conditions[i].cond));
|
|
32
|
+
res.push('THEN');
|
|
33
|
+
}
|
|
34
|
+
res.push((0, _expr.exprToSQL)(conditions[i].result));
|
|
35
|
+
}
|
|
36
|
+
res.push('END');
|
|
37
|
+
return parentheses ? `(${res.join(' ')})` : res.join(' ');
|
|
38
|
+
}
|
|
39
|
+
});
|
|
@@ -0,0 +1,37 @@
|
|
|
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.collate = 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.collateToSQL = collateToSQL;
|
|
20
|
+
function collateToSQL(stmt) {
|
|
21
|
+
if (!stmt) return;
|
|
22
|
+
const {
|
|
23
|
+
keyword,
|
|
24
|
+
collate: {
|
|
25
|
+
name,
|
|
26
|
+
symbol,
|
|
27
|
+
value
|
|
28
|
+
}
|
|
29
|
+
} = stmt;
|
|
30
|
+
const result = [(0, _util.toUpper)(keyword)];
|
|
31
|
+
if (!value) result.push(symbol);
|
|
32
|
+
result.push(Array.isArray(name) ? name.map(_util.literalToSQL).join('.') : (0, _util.literalToSQL)(name));
|
|
33
|
+
if (value) result.push(symbol);
|
|
34
|
+
result.push((0, _expr.exprToSQL)(value));
|
|
35
|
+
return result.filter(_util.hasVal).join(' ');
|
|
36
|
+
}
|
|
37
|
+
});
|