@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,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,132 @@
|
|
|
1
|
+
(function (global, factory) {
|
|
2
|
+
if (typeof define === "function" && define.amd) {
|
|
3
|
+
define(["exports", "./expr", "./column", "./limit", "./with", "./tables", "./util"], factory);
|
|
4
|
+
} else if (typeof exports !== "undefined") {
|
|
5
|
+
factory(exports, require("./expr"), require("./column"), require("./limit"), require("./with"), require("./tables"), require("./util"));
|
|
6
|
+
} else {
|
|
7
|
+
var mod = {
|
|
8
|
+
exports: {}
|
|
9
|
+
};
|
|
10
|
+
factory(mod.exports, global.expr, global.column, global.limit, global._with, global.tables, global.util);
|
|
11
|
+
global.select = mod.exports;
|
|
12
|
+
}
|
|
13
|
+
})(typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : this, function (_exports, _expr, _column, _limit, _with, _tables, _util) {
|
|
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(_column.columnRefToSQL).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
|
+
distinct,
|
|
84
|
+
for: forXml,
|
|
85
|
+
from,
|
|
86
|
+
for_sys_time_as_of: forSystem = {},
|
|
87
|
+
locking_read: lockingRead,
|
|
88
|
+
groupby,
|
|
89
|
+
having,
|
|
90
|
+
into = {},
|
|
91
|
+
limit,
|
|
92
|
+
options,
|
|
93
|
+
orderby,
|
|
94
|
+
parentheses_symbol: parentheses,
|
|
95
|
+
qualify,
|
|
96
|
+
top,
|
|
97
|
+
window: windowInfo,
|
|
98
|
+
with: withInfo,
|
|
99
|
+
where
|
|
100
|
+
} = stmt;
|
|
101
|
+
const clauses = [(0, _with.withToSQL)(withInfo), 'SELECT', (0, _util.toUpper)(asStructVal)];
|
|
102
|
+
clauses.push((0, _util.topToSQL)(top));
|
|
103
|
+
if (Array.isArray(options)) clauses.push(options.join(' '));
|
|
104
|
+
clauses.push(distinctToSQL(distinct), (0, _column.columnsToSQL)(columns, from));
|
|
105
|
+
const {
|
|
106
|
+
position
|
|
107
|
+
} = into;
|
|
108
|
+
let intoSQL = '';
|
|
109
|
+
if (position) intoSQL = (0, _util.commonOptionConnector)('INTO', selectIntoToSQL, into);
|
|
110
|
+
if (position === 'column') clauses.push(intoSQL);
|
|
111
|
+
// FROM + joins
|
|
112
|
+
clauses.push((0, _util.commonOptionConnector)('FROM', _tables.tablesToSQL, from));
|
|
113
|
+
if (position === 'from') clauses.push(intoSQL);
|
|
114
|
+
const {
|
|
115
|
+
keyword,
|
|
116
|
+
expr
|
|
117
|
+
} = forSystem || {};
|
|
118
|
+
clauses.push((0, _util.commonOptionConnector)(keyword, _expr.exprToSQL, expr));
|
|
119
|
+
clauses.push((0, _util.commonOptionConnector)('WHERE', _expr.exprToSQL, where));
|
|
120
|
+
clauses.push((0, _util.connector)('GROUP BY', (0, _expr.getExprListSQL)(groupby).join(', ')));
|
|
121
|
+
clauses.push((0, _util.commonOptionConnector)('HAVING', _expr.exprToSQL, having));
|
|
122
|
+
clauses.push((0, _util.commonOptionConnector)('QUALIFY', _expr.exprToSQL, qualify));
|
|
123
|
+
clauses.push((0, _util.commonOptionConnector)('WINDOW', _expr.exprToSQL, windowInfo));
|
|
124
|
+
clauses.push((0, _expr.orderOrPartitionByToSQL)(orderby, 'order by'));
|
|
125
|
+
clauses.push((0, _limit.limitToSQL)(limit));
|
|
126
|
+
clauses.push((0, _util.toUpper)(lockingRead));
|
|
127
|
+
if (position === 'end') clauses.push(intoSQL);
|
|
128
|
+
clauses.push(forXmlToSQL(forXml));
|
|
129
|
+
const sql = clauses.filter(_util.hasVal).join(' ');
|
|
130
|
+
return parentheses ? `(${sql})` : sql;
|
|
131
|
+
}
|
|
132
|
+
});
|
|
@@ -0,0 +1,88 @@
|
|
|
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
|
+
str = (0, _util.commonOptionConnector)('FROM', _tables.tablesToSQL, showExpr.from);
|
|
72
|
+
break;
|
|
73
|
+
case 'GRANTS':
|
|
74
|
+
str = showGrantsForUser(showExpr);
|
|
75
|
+
break;
|
|
76
|
+
case 'CREATE':
|
|
77
|
+
str = (0, _util.commonOptionConnector)('', _tables.tableToSQL, showExpr[suffix]);
|
|
78
|
+
break;
|
|
79
|
+
case 'VAR':
|
|
80
|
+
str = (0, _expr.varToSQL)(showExpr.var);
|
|
81
|
+
keyword = '';
|
|
82
|
+
break;
|
|
83
|
+
default:
|
|
84
|
+
break;
|
|
85
|
+
}
|
|
86
|
+
return ['SHOW', (0, _util.toUpper)(keyword), (0, _util.toUpper)(suffix), str].filter(_util.hasVal).join(' ');
|
|
87
|
+
}
|
|
88
|
+
});
|
|
@@ -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'];
|
|
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
|
+
});
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
(function (global, factory) {
|
|
2
|
+
if (typeof define === "function" && define.amd) {
|
|
3
|
+
define(["exports", "./binary", "./column", "./expr", "./insert", "./interval", "./util"], factory);
|
|
4
|
+
} else if (typeof exports !== "undefined") {
|
|
5
|
+
factory(exports, require("./binary"), require("./column"), require("./expr"), require("./insert"), require("./interval"), require("./util"));
|
|
6
|
+
} else {
|
|
7
|
+
var mod = {
|
|
8
|
+
exports: {}
|
|
9
|
+
};
|
|
10
|
+
factory(mod.exports, global.binary, global.column, global.expr, global.insert, global.interval, global.util);
|
|
11
|
+
global.tables = mod.exports;
|
|
12
|
+
}
|
|
13
|
+
})(typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : this, function (_exports, _binary, _column, _expr, _insert, _interval, _util) {
|
|
14
|
+
"use strict";
|
|
15
|
+
|
|
16
|
+
Object.defineProperty(_exports, "__esModule", {
|
|
17
|
+
value: true
|
|
18
|
+
});
|
|
19
|
+
_exports.operatorToSQL = operatorToSQL;
|
|
20
|
+
_exports.tableHintToSQL = tableHintToSQL;
|
|
21
|
+
_exports.tableOptionToSQL = tableOptionToSQL;
|
|
22
|
+
_exports.tableToSQL = tableToSQL;
|
|
23
|
+
_exports.tableTumbleToSQL = tableTumbleToSQL;
|
|
24
|
+
_exports.tablesToSQL = tablesToSQL;
|
|
25
|
+
_exports.unnestToSQL = unnestToSQL;
|
|
26
|
+
function unnestToSQL(unnestExpr) {
|
|
27
|
+
const {
|
|
28
|
+
type,
|
|
29
|
+
as,
|
|
30
|
+
expr,
|
|
31
|
+
with_offset: withOffset
|
|
32
|
+
} = unnestExpr;
|
|
33
|
+
const result = [`${(0, _util.toUpper)(type)}(${expr && (0, _expr.exprToSQL)(expr) || ''})`, (0, _util.commonOptionConnector)('AS', _util.identifierToSql, as), (0, _util.commonOptionConnector)((0, _util.toUpper)(withOffset && withOffset.keyword), _util.identifierToSql, withOffset && withOffset.as)];
|
|
34
|
+
return result.filter(_util.hasVal).join(' ');
|
|
35
|
+
}
|
|
36
|
+
function pivotOperatorToSQL(operator) {
|
|
37
|
+
const {
|
|
38
|
+
as,
|
|
39
|
+
column,
|
|
40
|
+
expr,
|
|
41
|
+
in_expr,
|
|
42
|
+
type
|
|
43
|
+
} = operator;
|
|
44
|
+
const result = [(0, _expr.exprToSQL)(expr), 'FOR', (0, _column.columnRefToSQL)(column), (0, _binary.binaryToSQL)(in_expr)];
|
|
45
|
+
const sql = [`${(0, _util.toUpper)(type)}(${result.join(' ')})`];
|
|
46
|
+
if (as) sql.push('AS', (0, _util.identifierToSql)(as));
|
|
47
|
+
return sql.join(' ');
|
|
48
|
+
}
|
|
49
|
+
function operatorToSQL(operator) {
|
|
50
|
+
if (!operator) return;
|
|
51
|
+
const {
|
|
52
|
+
type
|
|
53
|
+
} = operator;
|
|
54
|
+
switch (type) {
|
|
55
|
+
case 'pivot':
|
|
56
|
+
case 'unpivot':
|
|
57
|
+
return pivotOperatorToSQL(operator);
|
|
58
|
+
default:
|
|
59
|
+
return '';
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
function tableHintToSQL(tableHintExpr) {
|
|
63
|
+
if (!tableHintExpr) return;
|
|
64
|
+
const {
|
|
65
|
+
keyword,
|
|
66
|
+
expr,
|
|
67
|
+
index,
|
|
68
|
+
index_columns,
|
|
69
|
+
parentheses,
|
|
70
|
+
prefix
|
|
71
|
+
} = tableHintExpr;
|
|
72
|
+
const result = [];
|
|
73
|
+
switch (keyword.toLowerCase()) {
|
|
74
|
+
case 'forceseek':
|
|
75
|
+
result.push((0, _util.toUpper)(keyword), `(${(0, _util.identifierToSql)(index)}`, `(${index_columns.map(_expr.exprToSQL).filter(_util.hasVal).join(', ')}))`);
|
|
76
|
+
break;
|
|
77
|
+
case 'spatial_window_max_cells':
|
|
78
|
+
result.push((0, _util.toUpper)(keyword), '=', (0, _expr.exprToSQL)(expr));
|
|
79
|
+
break;
|
|
80
|
+
case 'index':
|
|
81
|
+
result.push((0, _util.toUpper)(prefix), (0, _util.toUpper)(keyword), parentheses ? `(${expr.map(_util.identifierToSql).join(', ')})` : `= ${(0, _util.identifierToSql)(expr)}`);
|
|
82
|
+
break;
|
|
83
|
+
default:
|
|
84
|
+
result.push((0, _expr.exprToSQL)(expr));
|
|
85
|
+
}
|
|
86
|
+
return result.filter(_util.hasVal).join(' ');
|
|
87
|
+
}
|
|
88
|
+
function tableTumbleToSQL(tumble) {
|
|
89
|
+
if (!tumble) return '';
|
|
90
|
+
const {
|
|
91
|
+
data: tableInfo,
|
|
92
|
+
timecol,
|
|
93
|
+
size
|
|
94
|
+
} = tumble;
|
|
95
|
+
const fullTableName = [(0, _util.identifierToSql)(tableInfo.db), (0, _util.identifierToSql)(tableInfo.table)].filter(_util.hasVal).join('.');
|
|
96
|
+
const result = ['TABLE(TUMBLE(TABLE', fullTableName, `DESCRIPTOR(${(0, _column.columnRefToSQL)(timecol)})`, `${(0, _interval.intervalToSQL)(size)}))`];
|
|
97
|
+
return result.filter(_util.hasVal).join(' ');
|
|
98
|
+
}
|
|
99
|
+
function tableToSQL(tableInfo) {
|
|
100
|
+
if ((0, _util.toUpper)(tableInfo.type) === 'UNNEST') return unnestToSQL(tableInfo);
|
|
101
|
+
const {
|
|
102
|
+
table,
|
|
103
|
+
db,
|
|
104
|
+
as,
|
|
105
|
+
expr,
|
|
106
|
+
operator,
|
|
107
|
+
prefix: prefixStr,
|
|
108
|
+
schema,
|
|
109
|
+
server,
|
|
110
|
+
tablesample,
|
|
111
|
+
table_hint
|
|
112
|
+
} = tableInfo;
|
|
113
|
+
const serverName = (0, _util.identifierToSql)(server);
|
|
114
|
+
const database = (0, _util.identifierToSql)(db);
|
|
115
|
+
const schemaStr = (0, _util.identifierToSql)(schema);
|
|
116
|
+
let tableName = table && (0, _util.identifierToSql)(table);
|
|
117
|
+
if (expr) {
|
|
118
|
+
const exprType = expr.type;
|
|
119
|
+
switch (exprType) {
|
|
120
|
+
case 'values':
|
|
121
|
+
const {
|
|
122
|
+
parentheses,
|
|
123
|
+
values,
|
|
124
|
+
prefix
|
|
125
|
+
} = expr;
|
|
126
|
+
const valueSQL = [parentheses && '(', '', parentheses && ')'];
|
|
127
|
+
let valuesExpr = (0, _insert.valuesToSQL)(values);
|
|
128
|
+
if (prefix) valuesExpr = valuesExpr.split('(').slice(1).map(val => `${(0, _util.toUpper)(prefix)}(${val}`).join('');
|
|
129
|
+
valueSQL[1] = `VALUES ${valuesExpr}`;
|
|
130
|
+
tableName = valueSQL.filter(_util.hasVal).join('');
|
|
131
|
+
break;
|
|
132
|
+
case 'tumble':
|
|
133
|
+
tableName = tableTumbleToSQL(expr);
|
|
134
|
+
break;
|
|
135
|
+
default:
|
|
136
|
+
tableName = (0, _expr.exprToSQL)(expr);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
tableName = [(0, _util.toUpper)(prefixStr), tableName].filter(_util.hasVal).join(' ');
|
|
140
|
+
let str = [serverName, database, schemaStr, tableName].filter(_util.hasVal).join('.');
|
|
141
|
+
if (tableInfo.parentheses) str = `(${str})`;
|
|
142
|
+
const result = [str];
|
|
143
|
+
if (tablesample) {
|
|
144
|
+
const tableSampleSQL = ['TABLESAMPLE', (0, _expr.exprToSQL)(tablesample.expr), (0, _util.literalToSQL)(tablesample.repeatable)].filter(_util.hasVal).join(' ');
|
|
145
|
+
result.push(tableSampleSQL);
|
|
146
|
+
}
|
|
147
|
+
result.push((0, _util.commonOptionConnector)('AS', _util.identifierToSql, as), operatorToSQL(operator));
|
|
148
|
+
if (table_hint) result.push((0, _util.toUpper)(table_hint.keyword), `(${table_hint.expr.map(tableHintToSQL).filter(_util.hasVal).join(', ')})`);
|
|
149
|
+
return result.filter(_util.hasVal).join(' ');
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* @param {Array} tables
|
|
154
|
+
* @return {string}
|
|
155
|
+
*/
|
|
156
|
+
function tablesToSQL(tables) {
|
|
157
|
+
if (!tables) return '';
|
|
158
|
+
if (!Array.isArray(tables)) {
|
|
159
|
+
const {
|
|
160
|
+
expr,
|
|
161
|
+
parentheses
|
|
162
|
+
} = tables;
|
|
163
|
+
const sql = tablesToSQL(expr);
|
|
164
|
+
if (parentheses) return `(${sql})`;
|
|
165
|
+
return sql;
|
|
166
|
+
}
|
|
167
|
+
const baseTable = tables[0];
|
|
168
|
+
const clauses = [];
|
|
169
|
+
if (baseTable.type === 'dual') return 'DUAL';
|
|
170
|
+
clauses.push(tableToSQL(baseTable));
|
|
171
|
+
for (let i = 1; i < tables.length; ++i) {
|
|
172
|
+
const joinExpr = tables[i];
|
|
173
|
+
const {
|
|
174
|
+
on,
|
|
175
|
+
using,
|
|
176
|
+
join
|
|
177
|
+
} = joinExpr;
|
|
178
|
+
const str = [];
|
|
179
|
+
str.push(join ? ` ${(0, _util.toUpper)(join)}` : ',');
|
|
180
|
+
str.push(tableToSQL(joinExpr));
|
|
181
|
+
str.push((0, _util.commonOptionConnector)('ON', _expr.exprToSQL, on));
|
|
182
|
+
if (using) str.push(`USING (${using.map(_util.identifierToSql).join(', ')})`);
|
|
183
|
+
clauses.push(str.filter(_util.hasVal).join(' '));
|
|
184
|
+
}
|
|
185
|
+
return clauses.filter(_util.hasVal).join('');
|
|
186
|
+
}
|
|
187
|
+
function tableOptionToSQL(tableOption) {
|
|
188
|
+
const {
|
|
189
|
+
keyword,
|
|
190
|
+
symbol,
|
|
191
|
+
value
|
|
192
|
+
} = tableOption;
|
|
193
|
+
const sql = [keyword.toUpperCase()];
|
|
194
|
+
if (symbol) sql.push(symbol);
|
|
195
|
+
let val = value;
|
|
196
|
+
switch (keyword) {
|
|
197
|
+
case 'partition by':
|
|
198
|
+
case 'default collate':
|
|
199
|
+
val = (0, _expr.exprToSQL)(value);
|
|
200
|
+
break;
|
|
201
|
+
case 'options':
|
|
202
|
+
val = `(${value.map(tableOptionItem => [tableOptionItem.keyword, tableOptionItem.symbol, (0, _expr.exprToSQL)(tableOptionItem.value)].join(' ')).join(', ')})`;
|
|
203
|
+
break;
|
|
204
|
+
case 'cluster by':
|
|
205
|
+
val = value.map(_expr.exprToSQL).join(', ');
|
|
206
|
+
break;
|
|
207
|
+
}
|
|
208
|
+
sql.push(val);
|
|
209
|
+
return sql.join(' ');
|
|
210
|
+
}
|
|
211
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
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.transaction = 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.transactionToSQL = transactionToSQL;
|
|
20
|
+
function transactionToSQL(stmt) {
|
|
21
|
+
const {
|
|
22
|
+
expr
|
|
23
|
+
} = stmt;
|
|
24
|
+
return (0, _expr.exprToSQL)(expr);
|
|
25
|
+
}
|
|
26
|
+
});
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
(function (global, factory) {
|
|
2
|
+
if (typeof define === "function" && define.amd) {
|
|
3
|
+
define(["exports", "./alter", "./analyze", "./create", "./select", "./delete", "./update", "./insert", "./command", "./exec", "./expr", "./limit", "./proc", "./transaction", "./show", "./util"], factory);
|
|
4
|
+
} else if (typeof exports !== "undefined") {
|
|
5
|
+
factory(exports, require("./alter"), require("./analyze"), require("./create"), require("./select"), require("./delete"), require("./update"), require("./insert"), require("./command"), require("./exec"), require("./expr"), require("./limit"), require("./proc"), require("./transaction"), require("./show"), require("./util"));
|
|
6
|
+
} else {
|
|
7
|
+
var mod = {
|
|
8
|
+
exports: {}
|
|
9
|
+
};
|
|
10
|
+
factory(mod.exports, global.alter, global.analyze, global.create, global.select, global._delete, global.update, global.insert, global.command, global.exec, global.expr, global.limit, global.proc, global.transaction, global.show, global.util);
|
|
11
|
+
global.union = mod.exports;
|
|
12
|
+
}
|
|
13
|
+
})(typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : this, function (_exports, _alter, _analyze, _create, _select, _delete, _update, _insert, _command, _exec, _expr, _limit2, _proc, _transaction, _show, _util) {
|
|
14
|
+
"use strict";
|
|
15
|
+
|
|
16
|
+
Object.defineProperty(_exports, "__esModule", {
|
|
17
|
+
value: true
|
|
18
|
+
});
|
|
19
|
+
_exports.multipleToSQL = multipleToSQL;
|
|
20
|
+
_exports.unionToSQL = unionToSQL;
|
|
21
|
+
const typeToSQLFn = {
|
|
22
|
+
alter: _alter.alterToSQL,
|
|
23
|
+
analyze: _analyze.analyzeToSQL,
|
|
24
|
+
attach: _analyze.attachToSQL,
|
|
25
|
+
create: _create.createToSQL,
|
|
26
|
+
select: _select.selectToSQL,
|
|
27
|
+
deallocate: _command.deallocateToSQL,
|
|
28
|
+
delete: _delete.deleteToSQL,
|
|
29
|
+
exec: _exec.execToSQL,
|
|
30
|
+
execute: _command.executeToSQL,
|
|
31
|
+
for: _command.forLoopToSQL,
|
|
32
|
+
update: _update.updateToSQL,
|
|
33
|
+
if: _command.ifToSQL,
|
|
34
|
+
insert: _insert.insertToSQL,
|
|
35
|
+
drop: _command.commonCmdToSQL,
|
|
36
|
+
truncate: _command.commonCmdToSQL,
|
|
37
|
+
replace: _insert.insertToSQL,
|
|
38
|
+
declare: _command.declareToSQL,
|
|
39
|
+
use: _command.useToSQL,
|
|
40
|
+
rename: _command.renameToSQL,
|
|
41
|
+
call: _command.callToSQL,
|
|
42
|
+
desc: _command.descToSQL,
|
|
43
|
+
set: _command.setVarToSQL,
|
|
44
|
+
lock: _command.lockUnlockToSQL,
|
|
45
|
+
unlock: _command.lockUnlockToSQL,
|
|
46
|
+
show: _show.showToSQL,
|
|
47
|
+
grant: _command.grantAndRevokeToSQL,
|
|
48
|
+
revoke: _command.grantAndRevokeToSQL,
|
|
49
|
+
proc: _proc.procToSQL,
|
|
50
|
+
raise: _command.raiseToSQL,
|
|
51
|
+
transaction: _transaction.transactionToSQL
|
|
52
|
+
};
|
|
53
|
+
function unionToSQL(stmt) {
|
|
54
|
+
if (!stmt) return '';
|
|
55
|
+
const fun = typeToSQLFn[stmt.type];
|
|
56
|
+
const {
|
|
57
|
+
_parentheses,
|
|
58
|
+
_orderby,
|
|
59
|
+
_limit
|
|
60
|
+
} = stmt;
|
|
61
|
+
const res = [_parentheses && '(', fun(stmt)];
|
|
62
|
+
while (stmt._next) {
|
|
63
|
+
const nextFun = typeToSQLFn[stmt._next.type];
|
|
64
|
+
const unionKeyword = (0, _util.toUpper)(stmt.set_op);
|
|
65
|
+
res.push(unionKeyword, nextFun(stmt._next));
|
|
66
|
+
stmt = stmt._next;
|
|
67
|
+
}
|
|
68
|
+
res.push(_parentheses && ')', (0, _expr.orderOrPartitionByToSQL)(_orderby, 'order by'), (0, _limit2.limitToSQL)(_limit));
|
|
69
|
+
return res.filter(_util.hasVal).join(' ');
|
|
70
|
+
}
|
|
71
|
+
function multipleToSQL(stmt) {
|
|
72
|
+
const res = [];
|
|
73
|
+
for (let i = 0, len = stmt.length; i < len; ++i) {
|
|
74
|
+
const astInfo = stmt[i] && stmt[i].ast ? stmt[i].ast : stmt[i];
|
|
75
|
+
let sql = unionToSQL(astInfo);
|
|
76
|
+
if (i === len - 1 && astInfo.type === 'transaction') sql = `${sql} ;`;
|
|
77
|
+
res.push(sql);
|
|
78
|
+
}
|
|
79
|
+
return res.join(' ; ');
|
|
80
|
+
}
|
|
81
|
+
});
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
(function (global, factory) {
|
|
2
|
+
if (typeof define === "function" && define.amd) {
|
|
3
|
+
define(["exports", "./tables", "./expr", "./limit", "./util", "./with"], factory);
|
|
4
|
+
} else if (typeof exports !== "undefined") {
|
|
5
|
+
factory(exports, require("./tables"), require("./expr"), require("./limit"), require("./util"), require("./with"));
|
|
6
|
+
} else {
|
|
7
|
+
var mod = {
|
|
8
|
+
exports: {}
|
|
9
|
+
};
|
|
10
|
+
factory(mod.exports, global.tables, global.expr, global.limit, global.util, global._with);
|
|
11
|
+
global.update = mod.exports;
|
|
12
|
+
}
|
|
13
|
+
})(typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : this, function (_exports, _tables, _expr, _limit, _util, _with) {
|
|
14
|
+
"use strict";
|
|
15
|
+
|
|
16
|
+
Object.defineProperty(_exports, "__esModule", {
|
|
17
|
+
value: true
|
|
18
|
+
});
|
|
19
|
+
_exports.setToSQL = setToSQL;
|
|
20
|
+
_exports.updateToSQL = updateToSQL;
|
|
21
|
+
/**
|
|
22
|
+
* @param {Array} sets
|
|
23
|
+
* @return {string}
|
|
24
|
+
*/
|
|
25
|
+
function setToSQL(sets) {
|
|
26
|
+
if (!sets || sets.length === 0) return '';
|
|
27
|
+
const clauses = [];
|
|
28
|
+
for (const set of sets) {
|
|
29
|
+
const {
|
|
30
|
+
table,
|
|
31
|
+
column,
|
|
32
|
+
value
|
|
33
|
+
} = set;
|
|
34
|
+
const str = [table, column].filter(_util.hasVal).map(info => (0, _util.identifierToSql)(info)).join('.');
|
|
35
|
+
const setItem = [str];
|
|
36
|
+
let val = '';
|
|
37
|
+
if (value) {
|
|
38
|
+
val = (0, _expr.exprToSQL)(value);
|
|
39
|
+
setItem.push('=', val);
|
|
40
|
+
}
|
|
41
|
+
clauses.push(setItem.filter(_util.hasVal).join(' '));
|
|
42
|
+
}
|
|
43
|
+
return clauses.join(', ');
|
|
44
|
+
}
|
|
45
|
+
function updateToSQL(stmt) {
|
|
46
|
+
const {
|
|
47
|
+
from,
|
|
48
|
+
table,
|
|
49
|
+
set,
|
|
50
|
+
where,
|
|
51
|
+
orderby,
|
|
52
|
+
with: withInfo,
|
|
53
|
+
limit,
|
|
54
|
+
returning
|
|
55
|
+
} = stmt;
|
|
56
|
+
const clauses = [(0, _with.withToSQL)(withInfo), 'UPDATE', (0, _tables.tablesToSQL)(table), (0, _util.commonOptionConnector)('SET', setToSQL, set), (0, _util.commonOptionConnector)('FROM', _tables.tablesToSQL, from), (0, _util.commonOptionConnector)('WHERE', _expr.exprToSQL, where), (0, _expr.orderOrPartitionByToSQL)(orderby, 'order by'), (0, _limit.limitToSQL)(limit), (0, _util.returningToSQL)(returning)];
|
|
57
|
+
return clauses.filter(_util.hasVal).join(' ');
|
|
58
|
+
}
|
|
59
|
+
});
|