@nocobase/plugin-collection-fdw 2.0.3
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/LICENSE +201 -0
- package/README.md +99 -0
- package/client.d.ts +2 -0
- package/client.js +1 -0
- package/dist/client/07d37b2045cf49ac.js +10 -0
- package/dist/client/19796e1ee00c3777.js +10 -0
- package/dist/client/545679e3c044a8fb.js +10 -0
- package/dist/client/components/CreateDatabaseServerAction.d.ts +10 -0
- package/dist/client/components/DatabaseServerSelect.d.ts +20 -0
- package/dist/client/components/EditDatabaseServerAction.d.ts +10 -0
- package/dist/client/components/PreviewFields.d.ts +10 -0
- package/dist/client/components/PreviewTable.d.ts +10 -0
- package/dist/client/components/RemoteTableSelect.d.ts +10 -0
- package/dist/client/components/SyncFieldsAction.d.ts +11 -0
- package/dist/client/components/UnSupportFields.d.ts +12 -0
- package/dist/client/components/schema.d.ts +19 -0
- package/dist/client/dccc3127ba4bb534.js +10 -0
- package/dist/client/ff008086e5ac8e5e.js +10 -0
- package/dist/client/hooks.d.ts +20 -0
- package/dist/client/index.d.ts +13 -0
- package/dist/client/index.js +10 -0
- package/dist/externalVersion.js +24 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +42 -0
- package/dist/locale/de-DE.json +17 -0
- package/dist/locale/en-US.json +17 -0
- package/dist/locale/es-ES.json +17 -0
- package/dist/locale/fr-FR.json +17 -0
- package/dist/locale/hu-HU.json +17 -0
- package/dist/locale/id-ID.json +17 -0
- package/dist/locale/index.d.ts +10 -0
- package/dist/locale/index.js +42 -0
- package/dist/locale/it-IT.json +17 -0
- package/dist/locale/ja-JP.json +17 -0
- package/dist/locale/ko-KR.json +17 -0
- package/dist/locale/nl-NL.json +17 -0
- package/dist/locale/pt-BR.json +17 -0
- package/dist/locale/ru-RU.json +18 -0
- package/dist/locale/tr-TR.json +17 -0
- package/dist/locale/uk-UA.json +17 -0
- package/dist/locale/vi-VN.json +17 -0
- package/dist/locale/zh-CN.json +17 -0
- package/dist/locale/zh-TW.json +17 -0
- package/dist/node_modules/node-sql-parser/LICENSE +201 -0
- package/dist/node_modules/node-sql-parser/ast/postgresql.ts +1834 -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/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/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 +39 -0
- package/dist/node_modules/node-sql-parser/lib/alter.js +174 -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 +46 -0
- package/dist/node_modules/node-sql-parser/lib/case.js +39 -0
- package/dist/node_modules/node-sql-parser/lib/column.js +221 -0
- package/dist/node_modules/node-sql-parser/lib/command.js +299 -0
- package/dist/node_modules/node-sql-parser/lib/constrain.js +45 -0
- package/dist/node_modules/node-sql-parser/lib/create.js +439 -0
- package/dist/node_modules/node-sql-parser/lib/delete.js +42 -0
- package/dist/node_modules/node-sql-parser/lib/exec.js +37 -0
- package/dist/node_modules/node-sql-parser/lib/expr.js +123 -0
- package/dist/node_modules/node-sql-parser/lib/func.js +152 -0
- package/dist/node_modules/node-sql-parser/lib/index-definition.js +106 -0
- package/dist/node_modules/node-sql-parser/lib/insert.js +111 -0
- package/dist/node_modules/node-sql-parser/lib/interval.js +28 -0
- package/dist/node_modules/node-sql-parser/lib/json.js +28 -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 +33 -0
- package/dist/node_modules/node-sql-parser/lib/parser.js +82 -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 +132 -0
- package/dist/node_modules/node-sql-parser/lib/show.js +88 -0
- package/dist/node_modules/node-sql-parser/lib/sql.js +43 -0
- package/dist/node_modules/node-sql-parser/lib/tables.js +211 -0
- package/dist/node_modules/node-sql-parser/lib/transaction.js +26 -0
- package/dist/node_modules/node-sql-parser/lib/union.js +81 -0
- package/dist/node_modules/node-sql-parser/lib/update.js +59 -0
- package/dist/node_modules/node-sql-parser/lib/util.js +444 -0
- package/dist/node_modules/node-sql-parser/lib/window.js +85 -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 +227 -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/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/server/bridges/mariadb-to-mariadb.d.ts +3 -0
- package/dist/server/bridges/mariadb-to-mariadb.js +38 -0
- package/dist/server/bridges/mysql-to-mysql.d.ts +13 -0
- package/dist/server/bridges/mysql-to-mysql.js +117 -0
- package/dist/server/bridges/mysql-to-pg.d.ts +8 -0
- package/dist/server/bridges/mysql-to-pg.js +9 -0
- package/dist/server/bridges/pg-to-pg.d.ts +21 -0
- package/dist/server/bridges/pg-to-pg.js +137 -0
- package/dist/server/bridges/remote-local-bridge.d.ts +57 -0
- package/dist/server/bridges/remote-local-bridge.js +73 -0
- package/dist/server/collections/database-server-collection.d.ts +10 -0
- package/dist/server/collections/database-server-collection.js +54 -0
- package/dist/server/foreign-data-collection.d.ts +22 -0
- package/dist/server/foreign-data-collection.js +118 -0
- package/dist/server/index.d.ts +9 -0
- package/dist/server/index.js +42 -0
- package/dist/server/models/database-server.d.ts +29 -0
- package/dist/server/models/database-server.js +226 -0
- package/dist/server/plugin.d.ts +14 -0
- package/dist/server/plugin.js +111 -0
- package/dist/server/resourcers/tables.d.ts +17 -0
- package/dist/server/resourcers/tables.js +181 -0
- package/package.json +43 -0
- package/server.d.ts +2 -0
- package/server.js +1 -0
|
@@ -0,0 +1,439 @@
|
|
|
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 createTableToSQL(stmt) {
|
|
40
|
+
const {
|
|
41
|
+
type,
|
|
42
|
+
keyword,
|
|
43
|
+
table,
|
|
44
|
+
like,
|
|
45
|
+
as,
|
|
46
|
+
temporary,
|
|
47
|
+
if_not_exists: ifNotExists,
|
|
48
|
+
create_definitions: createDefinition,
|
|
49
|
+
table_options: tableOptions,
|
|
50
|
+
ignore_replace: ignoreReplace,
|
|
51
|
+
or_replace: orReplace,
|
|
52
|
+
query_expr: queryExpr
|
|
53
|
+
} = stmt;
|
|
54
|
+
const sql = [(0, _util.toUpper)(type), (0, _util.toUpper)(orReplace), (0, _util.toUpper)(temporary), (0, _util.toUpper)(keyword), (0, _util.toUpper)(ifNotExists), (0, _tables.tablesToSQL)(table)];
|
|
55
|
+
if (like) {
|
|
56
|
+
const {
|
|
57
|
+
type: likeType,
|
|
58
|
+
table: likeTable
|
|
59
|
+
} = like;
|
|
60
|
+
const likeTableName = (0, _tables.tablesToSQL)(likeTable);
|
|
61
|
+
sql.push((0, _util.toUpper)(likeType), likeTableName);
|
|
62
|
+
return sql.filter(_util.hasVal).join(' ');
|
|
63
|
+
}
|
|
64
|
+
if (createDefinition) {
|
|
65
|
+
sql.push(`(${createDefinition.map(createDefinitionToSQL).join(', ')})`);
|
|
66
|
+
}
|
|
67
|
+
if (tableOptions) {
|
|
68
|
+
sql.push(tableOptions.map(_tables.tableOptionToSQL).join(' '));
|
|
69
|
+
}
|
|
70
|
+
sql.push((0, _util.toUpper)(ignoreReplace), (0, _util.toUpper)(as));
|
|
71
|
+
if (queryExpr) sql.push((0, _union.unionToSQL)(queryExpr));
|
|
72
|
+
return sql.filter(_util.hasVal).join(' ');
|
|
73
|
+
}
|
|
74
|
+
function createTriggerToSQL(stmt) {
|
|
75
|
+
const {
|
|
76
|
+
definer,
|
|
77
|
+
for_each: forEach,
|
|
78
|
+
keyword,
|
|
79
|
+
execute: triggerBody,
|
|
80
|
+
type,
|
|
81
|
+
table,
|
|
82
|
+
if_not_exists: ife,
|
|
83
|
+
temporary,
|
|
84
|
+
trigger,
|
|
85
|
+
events: triggerEvents,
|
|
86
|
+
order: triggerOrder,
|
|
87
|
+
time: triggerTime,
|
|
88
|
+
when
|
|
89
|
+
} = stmt;
|
|
90
|
+
const sql = [(0, _util.toUpper)(type), (0, _util.toUpper)(temporary), definer, (0, _util.toUpper)(keyword), (0, _util.toUpper)(ife), (0, _tables.tableToSQL)(trigger), (0, _util.toUpper)(triggerTime), triggerEvents.map(event => {
|
|
91
|
+
const eventStr = [(0, _util.toUpper)(event.keyword)];
|
|
92
|
+
const {
|
|
93
|
+
args
|
|
94
|
+
} = event;
|
|
95
|
+
if (args) eventStr.push((0, _util.toUpper)(args.keyword), args.columns.map(_column.columnRefToSQL).join(', '));
|
|
96
|
+
return eventStr.join(' ');
|
|
97
|
+
}), '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)];
|
|
98
|
+
switch (triggerBody.type) {
|
|
99
|
+
case 'set':
|
|
100
|
+
sql.push((0, _util.commonOptionConnector)('SET', _update.setToSQL, triggerBody.expr));
|
|
101
|
+
break;
|
|
102
|
+
case 'multiple':
|
|
103
|
+
sql.push((0, _union.multipleToSQL)(triggerBody.expr.ast));
|
|
104
|
+
break;
|
|
105
|
+
}
|
|
106
|
+
sql.push((0, _util.toUpper)(triggerBody.suffix));
|
|
107
|
+
return sql.filter(_util.hasVal).join(' ');
|
|
108
|
+
}
|
|
109
|
+
function createConstraintTriggerToSQL(stmt) {
|
|
110
|
+
const {
|
|
111
|
+
constraint,
|
|
112
|
+
constraint_kw: constraintKw,
|
|
113
|
+
deferrable,
|
|
114
|
+
events,
|
|
115
|
+
execute,
|
|
116
|
+
for_each: forEach,
|
|
117
|
+
from,
|
|
118
|
+
location,
|
|
119
|
+
keyword,
|
|
120
|
+
or,
|
|
121
|
+
type,
|
|
122
|
+
table,
|
|
123
|
+
when
|
|
124
|
+
} = stmt;
|
|
125
|
+
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)];
|
|
126
|
+
const event = (0, _util.triggerEventToSQL)(events);
|
|
127
|
+
sql.push(event, 'ON', (0, _tables.tableToSQL)(table));
|
|
128
|
+
if (from) sql.push('FROM', (0, _tables.tableToSQL)(from));
|
|
129
|
+
sql.push(...(0, _util.commonKeywordArgsToSQL)(deferrable), ...(0, _util.commonKeywordArgsToSQL)(forEach));
|
|
130
|
+
if (when) sql.push((0, _util.toUpper)(when.type), (0, _expr.exprToSQL)(when.cond));
|
|
131
|
+
sql.push((0, _util.toUpper)(execute.keyword), (0, _func.funcToSQL)(execute.expr));
|
|
132
|
+
return sql.filter(_util.hasVal).join(' ');
|
|
133
|
+
}
|
|
134
|
+
function createExtensionToSQL(stmt) {
|
|
135
|
+
const {
|
|
136
|
+
extension,
|
|
137
|
+
from,
|
|
138
|
+
if_not_exists: ifNotExists,
|
|
139
|
+
keyword,
|
|
140
|
+
schema,
|
|
141
|
+
type,
|
|
142
|
+
with: withName,
|
|
143
|
+
version
|
|
144
|
+
} = stmt;
|
|
145
|
+
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)];
|
|
146
|
+
return sql.filter(_util.hasVal).join(' ');
|
|
147
|
+
}
|
|
148
|
+
function createIndexToSQL(stmt) {
|
|
149
|
+
const {
|
|
150
|
+
concurrently,
|
|
151
|
+
filestream_on: fileStream,
|
|
152
|
+
keyword,
|
|
153
|
+
include,
|
|
154
|
+
index_columns: indexColumns,
|
|
155
|
+
index_type: indexType,
|
|
156
|
+
index_using: indexUsing,
|
|
157
|
+
index,
|
|
158
|
+
on,
|
|
159
|
+
index_options: indexOpt,
|
|
160
|
+
algorithm_option: algorithmOpt,
|
|
161
|
+
lock_option: lockOpt,
|
|
162
|
+
on_kw: onKw,
|
|
163
|
+
table,
|
|
164
|
+
tablespace,
|
|
165
|
+
type,
|
|
166
|
+
where,
|
|
167
|
+
with: withExpr,
|
|
168
|
+
with_before_where: withBeforeWhere
|
|
169
|
+
} = stmt;
|
|
170
|
+
const withIndexOpt = withExpr && `WITH (${(0, _indexDefinition.indexOptionListToSQL)(withExpr).join(', ')})`;
|
|
171
|
+
const includeColumns = include && `${(0, _util.toUpper)(include.keyword)} (${include.columns.map(col => (0, _util.identifierToSql)(col)).join(', ')})`;
|
|
172
|
+
const sql = [(0, _util.toUpper)(type), (0, _util.toUpper)(indexType), (0, _util.toUpper)(keyword), (0, _util.toUpper)(concurrently), (0, _util.identifierToSql)(index), (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)];
|
|
173
|
+
if (withBeforeWhere) {
|
|
174
|
+
sql.push(withIndexOpt, (0, _util.commonOptionConnector)('WHERE', _expr.exprToSQL, where));
|
|
175
|
+
} else {
|
|
176
|
+
sql.push((0, _util.commonOptionConnector)('WHERE', _expr.exprToSQL, where), withIndexOpt);
|
|
177
|
+
}
|
|
178
|
+
sql.push((0, _util.commonOptionConnector)('ON', _expr.exprToSQL, on), (0, _util.commonOptionConnector)('FILESTREAM_ON', _util.literalToSQL, fileStream));
|
|
179
|
+
return sql.filter(_util.hasVal).join(' ');
|
|
180
|
+
}
|
|
181
|
+
function createSequenceToSQL(stmt) {
|
|
182
|
+
const {
|
|
183
|
+
type,
|
|
184
|
+
keyword,
|
|
185
|
+
sequence,
|
|
186
|
+
temporary,
|
|
187
|
+
if_not_exists: ifNotExists,
|
|
188
|
+
create_definitions: createDefinition
|
|
189
|
+
} = stmt;
|
|
190
|
+
const sql = [(0, _util.toUpper)(type), (0, _util.toUpper)(temporary), (0, _util.toUpper)(keyword), (0, _util.toUpper)(ifNotExists), (0, _tables.tablesToSQL)(sequence)];
|
|
191
|
+
if (createDefinition) sql.push(createDefinition.map(createDefinitionToSQL).join(' '));
|
|
192
|
+
return sql.filter(_util.hasVal).join(' ');
|
|
193
|
+
}
|
|
194
|
+
function createDatabaseToSQL(stmt) {
|
|
195
|
+
const {
|
|
196
|
+
type,
|
|
197
|
+
keyword,
|
|
198
|
+
database,
|
|
199
|
+
if_not_exists: ifNotExists,
|
|
200
|
+
create_definitions: createDefinition
|
|
201
|
+
} = stmt;
|
|
202
|
+
const sql = [(0, _util.toUpper)(type), (0, _util.toUpper)(keyword), (0, _util.toUpper)(ifNotExists), (0, _util.columnIdentifierToSql)(database)];
|
|
203
|
+
if (createDefinition) sql.push(createDefinition.map(_tables.tableOptionToSQL).join(' '));
|
|
204
|
+
return sql.filter(_util.hasVal).join(' ');
|
|
205
|
+
}
|
|
206
|
+
function createViewToSQL(stmt) {
|
|
207
|
+
const {
|
|
208
|
+
algorithm,
|
|
209
|
+
columns,
|
|
210
|
+
definer,
|
|
211
|
+
if_not_exists: ifNotExists,
|
|
212
|
+
keyword,
|
|
213
|
+
recursive,
|
|
214
|
+
replace,
|
|
215
|
+
select,
|
|
216
|
+
sql_security: sqlSecurity,
|
|
217
|
+
temporary,
|
|
218
|
+
type,
|
|
219
|
+
view,
|
|
220
|
+
with: withClause,
|
|
221
|
+
with_options: withOptions
|
|
222
|
+
} = stmt;
|
|
223
|
+
const {
|
|
224
|
+
db,
|
|
225
|
+
view: name
|
|
226
|
+
} = view;
|
|
227
|
+
const viewName = [(0, _util.identifierToSql)(db), (0, _util.identifierToSql)(name)].filter(_util.hasVal).join('.');
|
|
228
|
+
const sql = [(0, _util.toUpper)(type), (0, _util.toUpper)(replace), (0, _util.toUpper)(temporary), (0, _util.toUpper)(recursive), algorithm && `ALGORITHM = ${(0, _util.toUpper)(algorithm)}`, 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)];
|
|
229
|
+
return sql.filter(_util.hasVal).join(' ');
|
|
230
|
+
}
|
|
231
|
+
function createDomainToSQL(stmt) {
|
|
232
|
+
const {
|
|
233
|
+
as,
|
|
234
|
+
domain,
|
|
235
|
+
type,
|
|
236
|
+
keyword,
|
|
237
|
+
target,
|
|
238
|
+
create_definitions: createDefinition
|
|
239
|
+
} = stmt;
|
|
240
|
+
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)];
|
|
241
|
+
if (createDefinition && createDefinition.length > 0) {
|
|
242
|
+
const definitionSQL = [];
|
|
243
|
+
for (const definition of createDefinition) {
|
|
244
|
+
const definitionType = definition.type;
|
|
245
|
+
switch (definitionType) {
|
|
246
|
+
case 'collate':
|
|
247
|
+
definitionSQL.push((0, _util.commonTypeValue)(definition).join(' '));
|
|
248
|
+
break;
|
|
249
|
+
case 'default':
|
|
250
|
+
definitionSQL.push((0, _util.toUpper)(definitionType), (0, _expr.exprToSQL)(definition.value));
|
|
251
|
+
break;
|
|
252
|
+
case 'constraint':
|
|
253
|
+
definitionSQL.push((0, _constrain.constraintDefinitionToSQL)(definition));
|
|
254
|
+
break;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
sql.push(definitionSQL.filter(_util.hasVal).join(' '));
|
|
258
|
+
}
|
|
259
|
+
return sql.filter(_util.hasVal).join(' ');
|
|
260
|
+
}
|
|
261
|
+
function createTypeToSQL(stmt) {
|
|
262
|
+
const {
|
|
263
|
+
as,
|
|
264
|
+
create_definitions: createDefinition,
|
|
265
|
+
keyword,
|
|
266
|
+
name,
|
|
267
|
+
resource,
|
|
268
|
+
type
|
|
269
|
+
} = stmt;
|
|
270
|
+
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)];
|
|
271
|
+
if (createDefinition) {
|
|
272
|
+
const definitionSQL = [];
|
|
273
|
+
switch (resource) {
|
|
274
|
+
case 'enum':
|
|
275
|
+
definitionSQL.push((0, _expr.exprToSQL)(createDefinition));
|
|
276
|
+
break;
|
|
277
|
+
}
|
|
278
|
+
sql.push(definitionSQL.filter(_util.hasVal).join(' '));
|
|
279
|
+
}
|
|
280
|
+
return sql.filter(_util.hasVal).join(' ');
|
|
281
|
+
}
|
|
282
|
+
function createFunctionReturnsOptToSQL(stmt) {
|
|
283
|
+
if (stmt.dataType) return (0, _util.dataTypeToSQL)(stmt);
|
|
284
|
+
return [(0, _util.identifierToSql)(stmt.db), (0, _util.identifierToSql)(stmt.schema), (0, _util.identifierToSql)(stmt.table)].filter(_util.hasVal).join('.');
|
|
285
|
+
}
|
|
286
|
+
function createFunctionReturnsToSQL(stmt) {
|
|
287
|
+
const {
|
|
288
|
+
type,
|
|
289
|
+
keyword,
|
|
290
|
+
expr
|
|
291
|
+
} = stmt;
|
|
292
|
+
const sql = [(0, _util.toUpper)(type), (0, _util.toUpper)(keyword), Array.isArray(expr) ? `(${expr.map(_column.columnDefinitionToSQL).join(', ')})` : createFunctionReturnsOptToSQL(expr)];
|
|
293
|
+
return sql.filter(_util.hasVal).join(' ');
|
|
294
|
+
}
|
|
295
|
+
function createFunctionOptionToSQL(stmt) {
|
|
296
|
+
const {
|
|
297
|
+
type
|
|
298
|
+
} = stmt;
|
|
299
|
+
switch (type) {
|
|
300
|
+
case 'as':
|
|
301
|
+
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(' ');
|
|
302
|
+
case 'set':
|
|
303
|
+
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(' ');
|
|
304
|
+
default:
|
|
305
|
+
return (0, _expr.exprToSQL)(stmt);
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
function createFunctionToSQL(stmt) {
|
|
309
|
+
const {
|
|
310
|
+
type,
|
|
311
|
+
replace,
|
|
312
|
+
keyword,
|
|
313
|
+
name,
|
|
314
|
+
args,
|
|
315
|
+
returns,
|
|
316
|
+
options,
|
|
317
|
+
last
|
|
318
|
+
} = stmt;
|
|
319
|
+
const sql = [(0, _util.toUpper)(type), (0, _util.toUpper)(replace), (0, _util.toUpper)(keyword)];
|
|
320
|
+
const functionName = [(0, _util.identifierToSql)(name.schema), name.name].filter(_util.hasVal).join('.');
|
|
321
|
+
const argsSQL = args.map(_alter.alterArgsToSQL).filter(_util.hasVal).join(', ');
|
|
322
|
+
sql.push(`${functionName}(${argsSQL})`, createFunctionReturnsToSQL(returns), options.map(createFunctionOptionToSQL).join(' '), last);
|
|
323
|
+
return sql.filter(_util.hasVal).join(' ');
|
|
324
|
+
}
|
|
325
|
+
function aggregateOptionToSQL(stmt) {
|
|
326
|
+
const {
|
|
327
|
+
type,
|
|
328
|
+
symbol,
|
|
329
|
+
value
|
|
330
|
+
} = stmt;
|
|
331
|
+
const sql = [(0, _util.toUpper)(type), symbol];
|
|
332
|
+
switch ((0, _util.toUpper)(type)) {
|
|
333
|
+
case 'SFUNC':
|
|
334
|
+
sql.push([(0, _util.identifierToSql)(value.schema), value.name].filter(_util.hasVal).join('.'));
|
|
335
|
+
break;
|
|
336
|
+
case 'STYPE':
|
|
337
|
+
case 'MSTYPE':
|
|
338
|
+
sql.push((0, _util.dataTypeToSQL)(value));
|
|
339
|
+
break;
|
|
340
|
+
default:
|
|
341
|
+
sql.push((0, _expr.exprToSQL)(value));
|
|
342
|
+
break;
|
|
343
|
+
}
|
|
344
|
+
return sql.filter(_util.hasVal).join(' ');
|
|
345
|
+
}
|
|
346
|
+
function createAggregateToSQL(stmt) {
|
|
347
|
+
const {
|
|
348
|
+
type,
|
|
349
|
+
replace,
|
|
350
|
+
keyword,
|
|
351
|
+
name,
|
|
352
|
+
args,
|
|
353
|
+
options
|
|
354
|
+
} = stmt;
|
|
355
|
+
const sql = [(0, _util.toUpper)(type), (0, _util.toUpper)(replace), (0, _util.toUpper)(keyword)];
|
|
356
|
+
const functionName = [(0, _util.identifierToSql)(name.schema), name.name].filter(_util.hasVal).join('.');
|
|
357
|
+
const argsSQL = `${args.expr.map(_alter.alterArgsToSQL).join(', ')}${args.orderby ? [' ORDER', 'BY', args.orderby.map(_alter.alterArgsToSQL).join(', ')].join(' ') : ''}`;
|
|
358
|
+
sql.push(`${functionName}(${argsSQL})`, `(${options.map(aggregateOptionToSQL).join(', ')})`);
|
|
359
|
+
return sql.filter(_util.hasVal).join(' ');
|
|
360
|
+
}
|
|
361
|
+
function createUserToSQL(stmt) {
|
|
362
|
+
const {
|
|
363
|
+
attribute,
|
|
364
|
+
comment,
|
|
365
|
+
default_role: defaultRole,
|
|
366
|
+
if_not_exists: ifNotExists,
|
|
367
|
+
keyword,
|
|
368
|
+
lock_option: lockOption,
|
|
369
|
+
password_options: passwordOptions,
|
|
370
|
+
require: requireOption,
|
|
371
|
+
resource_options: resourceOptions,
|
|
372
|
+
type,
|
|
373
|
+
user
|
|
374
|
+
} = stmt;
|
|
375
|
+
const userAuthOptions = user.map(userAuthOption => {
|
|
376
|
+
const {
|
|
377
|
+
user: userInfo,
|
|
378
|
+
auth_option
|
|
379
|
+
} = userAuthOption;
|
|
380
|
+
const result = [(0, _command.grantUserOrRoleToSQL)(userInfo)];
|
|
381
|
+
if (auth_option) result.push((0, _util.toUpper)(auth_option.keyword), auth_option.auth_plugin, (0, _util.literalToSQL)(auth_option.value));
|
|
382
|
+
return result.filter(_util.hasVal).join(' ');
|
|
383
|
+
}).join(', ');
|
|
384
|
+
const sql = [(0, _util.toUpper)(type), (0, _util.toUpper)(keyword), (0, _util.toUpper)(ifNotExists), userAuthOptions];
|
|
385
|
+
if (defaultRole) sql.push((0, _util.toUpper)(defaultRole.keyword), defaultRole.value.map(_command.grantUserOrRoleToSQL).join(', '));
|
|
386
|
+
sql.push((0, _util.commonOptionConnector)(requireOption && requireOption.keyword, _expr.exprToSQL, requireOption && requireOption.value));
|
|
387
|
+
if (resourceOptions) sql.push((0, _util.toUpper)(resourceOptions.keyword), resourceOptions.value.map(resourceOption => (0, _expr.exprToSQL)(resourceOption)).join(' '));
|
|
388
|
+
if (passwordOptions) passwordOptions.forEach(passwordOption => sql.push((0, _util.commonOptionConnector)(passwordOption.keyword, _expr.exprToSQL, passwordOption.value)));
|
|
389
|
+
sql.push((0, _util.literalToSQL)(lockOption), (0, _util.commentToSQL)(comment), (0, _util.literalToSQL)(attribute));
|
|
390
|
+
return sql.filter(_util.hasVal).join(' ');
|
|
391
|
+
}
|
|
392
|
+
function createToSQL(stmt) {
|
|
393
|
+
const {
|
|
394
|
+
keyword
|
|
395
|
+
} = stmt;
|
|
396
|
+
let sql = '';
|
|
397
|
+
switch (keyword.toLowerCase()) {
|
|
398
|
+
case 'aggregate':
|
|
399
|
+
sql = createAggregateToSQL(stmt);
|
|
400
|
+
break;
|
|
401
|
+
case 'table':
|
|
402
|
+
sql = createTableToSQL(stmt);
|
|
403
|
+
break;
|
|
404
|
+
case 'trigger':
|
|
405
|
+
sql = stmt.resource === 'constraint' ? createConstraintTriggerToSQL(stmt) : createTriggerToSQL(stmt);
|
|
406
|
+
break;
|
|
407
|
+
case 'extension':
|
|
408
|
+
sql = createExtensionToSQL(stmt);
|
|
409
|
+
break;
|
|
410
|
+
case 'function':
|
|
411
|
+
sql = createFunctionToSQL(stmt);
|
|
412
|
+
break;
|
|
413
|
+
case 'index':
|
|
414
|
+
sql = createIndexToSQL(stmt);
|
|
415
|
+
break;
|
|
416
|
+
case 'sequence':
|
|
417
|
+
sql = createSequenceToSQL(stmt);
|
|
418
|
+
break;
|
|
419
|
+
case 'database':
|
|
420
|
+
sql = createDatabaseToSQL(stmt);
|
|
421
|
+
break;
|
|
422
|
+
case 'view':
|
|
423
|
+
sql = createViewToSQL(stmt);
|
|
424
|
+
break;
|
|
425
|
+
case 'domain':
|
|
426
|
+
sql = createDomainToSQL(stmt);
|
|
427
|
+
break;
|
|
428
|
+
case 'type':
|
|
429
|
+
sql = createTypeToSQL(stmt);
|
|
430
|
+
break;
|
|
431
|
+
case 'user':
|
|
432
|
+
sql = createUserToSQL(stmt);
|
|
433
|
+
break;
|
|
434
|
+
default:
|
|
435
|
+
throw new Error(`unknown create resource ${keyword}`);
|
|
436
|
+
}
|
|
437
|
+
return sql;
|
|
438
|
+
}
|
|
439
|
+
});
|
|
@@ -0,0 +1,42 @@
|
|
|
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
|
+
} = stmt;
|
|
30
|
+
const clauses = [(0, _with.withToSQL)(withInfo), 'DELETE'];
|
|
31
|
+
const columnInfo = (0, _column.columnsToSQL)(columns, from);
|
|
32
|
+
clauses.push(columnInfo);
|
|
33
|
+
if (Array.isArray(table)) {
|
|
34
|
+
if (!(table.length === 1 && table[0].addition === true)) clauses.push((0, _tables.tablesToSQL)(table));
|
|
35
|
+
}
|
|
36
|
+
clauses.push((0, _util.commonOptionConnector)('FROM', _tables.tablesToSQL, from));
|
|
37
|
+
clauses.push((0, _util.commonOptionConnector)('WHERE', _expr.exprToSQL, where));
|
|
38
|
+
clauses.push((0, _expr.orderOrPartitionByToSQL)(orderby, 'order by'));
|
|
39
|
+
clauses.push((0, _limit.limitToSQL)(limit));
|
|
40
|
+
return clauses.filter(_util.hasVal).join(' ');
|
|
41
|
+
}
|
|
42
|
+
});
|
|
@@ -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,123 @@
|
|
|
1
|
+
(function (global, factory) {
|
|
2
|
+
if (typeof define === "function" && define.amd) {
|
|
3
|
+
define(["exports", "./util", "./alter", "./aggregation", "./assign", "./binary", "./case", "./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("./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.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, _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
|
+
column_ref: _column.columnRefToSQL,
|
|
35
|
+
column_definition: _column.columnDefinitionToSQL,
|
|
36
|
+
datatype: _util.dataTypeToSQL,
|
|
37
|
+
extract: _func.extractFunToSQL,
|
|
38
|
+
flatten: _func.flattenFunToSQL,
|
|
39
|
+
fulltext_search: _column.fullTextSearchToSQL,
|
|
40
|
+
function: _func.funcToSQL,
|
|
41
|
+
insert: _union.unionToSQL,
|
|
42
|
+
interval: _interval.intervalToSQL,
|
|
43
|
+
json: _json.jsonExprToSQL,
|
|
44
|
+
show: _show.showToSQL,
|
|
45
|
+
struct: _arrayStruct.arrayStructExprToSQL,
|
|
46
|
+
tablefunc: _func.tablefuncFunToSQL,
|
|
47
|
+
tables: _tables.tablesToSQL,
|
|
48
|
+
unnest: _tables.unnestToSQL,
|
|
49
|
+
'window': _window.namedWindowExprListToSQL
|
|
50
|
+
};
|
|
51
|
+
function varToSQL(expr) {
|
|
52
|
+
const {
|
|
53
|
+
prefix = '@',
|
|
54
|
+
name,
|
|
55
|
+
members,
|
|
56
|
+
keyword,
|
|
57
|
+
quoted,
|
|
58
|
+
suffix
|
|
59
|
+
} = expr;
|
|
60
|
+
const val = [];
|
|
61
|
+
if (keyword) val.push(keyword);
|
|
62
|
+
const varName = members && members.length > 0 ? `${name}.${members.join('.')}` : name;
|
|
63
|
+
let result = `${prefix || ''}${varName}`;
|
|
64
|
+
if (suffix) result += suffix;
|
|
65
|
+
val.push(result);
|
|
66
|
+
return [quoted, val.join(' '), quoted].filter(_util.hasVal).join('');
|
|
67
|
+
}
|
|
68
|
+
exprToSQLConvertFn.var = varToSQL;
|
|
69
|
+
function exprToSQL(exprOrigin) {
|
|
70
|
+
if (!exprOrigin) return;
|
|
71
|
+
const expr = exprOrigin;
|
|
72
|
+
if (exprOrigin.ast) {
|
|
73
|
+
const {
|
|
74
|
+
ast
|
|
75
|
+
} = expr;
|
|
76
|
+
Reflect.deleteProperty(expr, ast);
|
|
77
|
+
for (const key of Object.keys(ast)) {
|
|
78
|
+
expr[key] = ast[key];
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return exprToSQLConvertFn[expr.type] ? exprToSQLConvertFn[expr.type](expr) : (0, _util.literalToSQL)(expr);
|
|
82
|
+
}
|
|
83
|
+
function unaryToSQL(unarExpr) {
|
|
84
|
+
const {
|
|
85
|
+
operator,
|
|
86
|
+
parentheses,
|
|
87
|
+
expr
|
|
88
|
+
} = unarExpr;
|
|
89
|
+
const space = operator === '-' || operator === '+' || operator === '~' || operator === '!' ? '' : ' ';
|
|
90
|
+
const str = `${operator}${space}${exprToSQL(expr)}`;
|
|
91
|
+
return parentheses ? `(${str})` : str;
|
|
92
|
+
}
|
|
93
|
+
function getExprListSQL(exprList) {
|
|
94
|
+
if (!exprList) return [];
|
|
95
|
+
return exprList.map(exprToSQL);
|
|
96
|
+
}
|
|
97
|
+
exprToSQLConvertFn.expr_list = expr => {
|
|
98
|
+
const str = getExprListSQL(expr.value);
|
|
99
|
+
return expr.parentheses ? `(${str.join(', ')})` : str;
|
|
100
|
+
};
|
|
101
|
+
exprToSQLConvertFn.select = expr => {
|
|
102
|
+
const str = typeof expr._next === 'object' ? (0, _union.unionToSQL)(expr) : (0, _select.selectToSQL)(expr);
|
|
103
|
+
return expr.parentheses ? `(${str})` : str;
|
|
104
|
+
};
|
|
105
|
+
exprToSQLConvertFn.unary_expr = unaryToSQL;
|
|
106
|
+
function orderOrPartitionByToSQL(expr, prefix) {
|
|
107
|
+
if (!Array.isArray(expr)) return '';
|
|
108
|
+
let expressions = [];
|
|
109
|
+
const upperPrefix = (0, _util.toUpper)(prefix);
|
|
110
|
+
switch (upperPrefix) {
|
|
111
|
+
case 'ORDER BY':
|
|
112
|
+
expressions = expr.map(info => [exprToSQL(info.expr), info.type || 'ASC', (0, _util.toUpper)(info.nulls)].filter(_util.hasVal).join(' '));
|
|
113
|
+
break;
|
|
114
|
+
case 'PARTITION BY':
|
|
115
|
+
expressions = expr.map(info => exprToSQL(info.expr));
|
|
116
|
+
break;
|
|
117
|
+
default:
|
|
118
|
+
expressions = expr.map(info => exprToSQL(info.expr));
|
|
119
|
+
break;
|
|
120
|
+
}
|
|
121
|
+
return (0, _util.connector)(upperPrefix, expressions.join(', '));
|
|
122
|
+
}
|
|
123
|
+
});
|