@l-v-yonsama/multi-platform-database-drivers 0.1.132 → 0.1.157
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/built/src/drivers/MySQLDriver.d.ts +4 -2
- package/built/src/drivers/MySQLDriver.js +51 -25
- package/built/src/drivers/MySQLDriver.js.map +1 -1
- package/built/src/drivers/PostgresDriver.d.ts +4 -1
- package/built/src/drivers/PostgresDriver.js +69 -35
- package/built/src/drivers/PostgresDriver.js.map +1 -1
- package/built/src/drivers/RDSBaseDriver.d.ts +2 -7
- package/built/src/drivers/RDSBaseDriver.js +1 -24
- package/built/src/drivers/RDSBaseDriver.js.map +1 -1
- package/built/src/examples/mysql.js +5 -18
- package/built/src/examples/mysql.js.map +1 -1
- package/built/src/helpers/SQLHelper.d.ts +36 -33
- package/built/src/helpers/SQLHelper.js +290 -364
- package/built/src/helpers/SQLHelper.js.map +1 -1
- package/built/src/helpers/constant.d.ts +2 -0
- package/built/src/helpers/constant.js +270 -0
- package/built/src/helpers/constant.js.map +1 -0
- package/built/src/helpers/index.d.ts +1 -0
- package/built/src/helpers/index.js +1 -0
- package/built/src/helpers/index.js.map +1 -1
- package/built/src/resource/GeneralColumnUtil.d.ts +1 -0
- package/built/src/resource/GeneralColumnUtil.js +10 -1
- package/built/src/resource/GeneralColumnUtil.js.map +1 -1
- package/built/src/types/helpers/index.d.ts +69 -0
- package/built/src/types/helpers/index.js +11 -0
- package/built/src/types/helpers/index.js.map +1 -0
- package/built/src/types/index.d.ts +1 -0
- package/built/src/types/index.js +1 -0
- package/built/src/types/index.js.map +1 -1
- package/built/src/types/resource/ResultSetDataType.d.ts +2 -0
- package/built/src/types/resource/ResultSetDataType.js.map +1 -1
- package/built/src/util.d.ts +2 -2
- package/built/src/util.js +19 -2
- package/built/src/util.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,17 +1,225 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.getResourcePositions = exports.getProposals = exports.normalizeSimpleParametersQuery = exports.normalizePositionedParametersQuery = exports.normalizeQuery = exports.parseQuery = exports.toSafeQueryForPgsqlAst = exports.toViewDataQuery = exports.toDeleteStatementWithBinds = exports.toUpdateStatementWithBinds = exports.toInsertStatementWithBinds = exports.operatorToString = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const dayjs_1 = tslib_1.__importDefault(require("dayjs"));
|
|
6
|
+
const resource_1 = require("../resource");
|
|
4
7
|
const pgsql_ast_parser_1 = require("pgsql-ast-parser");
|
|
5
8
|
const util_1 = require("../util");
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
const types_1 = require("../types");
|
|
10
|
+
const constant_1 = require("./constant");
|
|
11
|
+
const operatorToString = (operator) => {
|
|
12
|
+
switch (operator) {
|
|
13
|
+
case 'equal':
|
|
14
|
+
return '=';
|
|
15
|
+
case 'notEqual':
|
|
16
|
+
return '<>';
|
|
17
|
+
case 'lessThan':
|
|
18
|
+
return '<';
|
|
19
|
+
case 'lessThanInclusive':
|
|
20
|
+
return '<=';
|
|
21
|
+
case 'greaterThan':
|
|
22
|
+
return '>';
|
|
23
|
+
case 'greaterThanInclusive':
|
|
24
|
+
return '>=';
|
|
25
|
+
case 'like':
|
|
26
|
+
return 'LIKE';
|
|
27
|
+
case 'notLike':
|
|
28
|
+
return 'NOT LIKE';
|
|
29
|
+
case 'in':
|
|
30
|
+
return 'IN';
|
|
31
|
+
case 'notIn':
|
|
32
|
+
return 'NOT IN';
|
|
33
|
+
case 'isNull':
|
|
34
|
+
return 'IS NULL';
|
|
35
|
+
case 'isNotNull':
|
|
36
|
+
return 'IS NOT NULL';
|
|
37
|
+
}
|
|
38
|
+
throw new Error(`Operator:${operator} is not defined`);
|
|
39
|
+
};
|
|
40
|
+
exports.operatorToString = operatorToString;
|
|
41
|
+
const toBindValue = (colType, value) => {
|
|
42
|
+
if ((0, resource_1.isTextLike)(colType)) {
|
|
43
|
+
return value;
|
|
44
|
+
}
|
|
45
|
+
if (value === undefined || value === null || value.length === 0) {
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
if ((0, resource_1.isNumericLike)(colType) ||
|
|
49
|
+
(0, resource_1.isDateTimeOrDateOrTime)(colType) ||
|
|
50
|
+
(0, resource_1.isBooleanLike)(colType)) {
|
|
51
|
+
let v;
|
|
52
|
+
if ((0, resource_1.isNumericLike)(colType)) {
|
|
53
|
+
v = (0, util_1.toNum)(value);
|
|
54
|
+
}
|
|
55
|
+
else if ((0, resource_1.isDateTimeOrDate)(colType)) {
|
|
56
|
+
const now = new Date();
|
|
57
|
+
if (/^(now|CURRENT_TIMESTAMP)$/i.test(value)) {
|
|
58
|
+
return now;
|
|
59
|
+
}
|
|
60
|
+
if (/^(today|CURRENT_DATE)$/i.test(value)) {
|
|
61
|
+
return new Date(now.getFullYear(), now.getMonth(), now.getDate(), 0, 0, 0, 0);
|
|
62
|
+
}
|
|
63
|
+
v = (0, util_1.toDate)(value);
|
|
64
|
+
}
|
|
65
|
+
else if ((0, resource_1.isTime)(colType)) {
|
|
66
|
+
v = value;
|
|
67
|
+
if ('now' === value.toLocaleUpperCase()) {
|
|
68
|
+
return (0, dayjs_1.default)().format('HH:mm:ss');
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
v = (0, util_1.toBoolean)(value);
|
|
73
|
+
}
|
|
74
|
+
return v === undefined ? null : v;
|
|
75
|
+
}
|
|
76
|
+
return value;
|
|
77
|
+
};
|
|
78
|
+
const toInsertStatementWithBinds = ({ schemaName, tableName, keys, values, toPositionedParameter, quote, }) => {
|
|
79
|
+
const tableNameWithSchema = createTableNameWithSchema({
|
|
80
|
+
schema: schemaName,
|
|
81
|
+
table: tableName,
|
|
82
|
+
quote,
|
|
83
|
+
});
|
|
84
|
+
const binds = [];
|
|
85
|
+
const columnNames = [];
|
|
86
|
+
const placeHolders = [];
|
|
87
|
+
let index = 0;
|
|
88
|
+
Object.keys(values).forEach((key) => {
|
|
89
|
+
var _a, _b;
|
|
90
|
+
const colType = (_b = (_a = keys.find((it) => it.name === key)) === null || _a === void 0 ? void 0 : _a.type) !== null && _b !== void 0 ? _b : types_1.GeneralColumnType.UNKNOWN;
|
|
91
|
+
const value = toBindValue(colType, values[key]);
|
|
92
|
+
if (value === null) {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
columnNames.push(`${wrapQuote(key, quote)}`);
|
|
96
|
+
binds.push(value);
|
|
97
|
+
placeHolders.push(toPositionedParameter === true ? `$${index + 1}` : '?');
|
|
98
|
+
index++;
|
|
99
|
+
});
|
|
100
|
+
const query = `INSERT INTO ${tableNameWithSchema} (${columnNames.join(',')}) VALUES (${placeHolders.join(',')})`;
|
|
101
|
+
return {
|
|
102
|
+
query,
|
|
103
|
+
binds,
|
|
104
|
+
};
|
|
105
|
+
};
|
|
106
|
+
exports.toInsertStatementWithBinds = toInsertStatementWithBinds;
|
|
107
|
+
const toUpdateStatementWithBinds = ({ schemaName, tableName, keys, values, conditions, toPositionedParameter, quote, }) => {
|
|
108
|
+
const tableNameWithSchema = createTableNameWithSchema({
|
|
109
|
+
schema: schemaName,
|
|
110
|
+
table: tableName,
|
|
111
|
+
quote,
|
|
112
|
+
});
|
|
113
|
+
const binds = [];
|
|
114
|
+
const setList = [];
|
|
115
|
+
const conditionList = [];
|
|
116
|
+
let index = 0;
|
|
117
|
+
Object.keys(values).forEach((key) => {
|
|
118
|
+
var _a, _b;
|
|
119
|
+
setList.push(`${wrapQuote(key, quote)} = ${toPositionedParameter === true ? `$${index + 1}` : '?'}`);
|
|
120
|
+
const colType = (_b = (_a = keys.find((it) => it.name === key)) === null || _a === void 0 ? void 0 : _a.type) !== null && _b !== void 0 ? _b : types_1.GeneralColumnType.UNKNOWN;
|
|
121
|
+
binds.push(toBindValue(colType, values[key]));
|
|
122
|
+
index++;
|
|
123
|
+
});
|
|
124
|
+
Object.keys(conditions).forEach((key) => {
|
|
125
|
+
var _a, _b;
|
|
126
|
+
conditionList.push(`${wrapQuote(key, quote)} = ${toPositionedParameter === true ? `$${index + 1}` : '?'}`);
|
|
127
|
+
const colType = (_b = (_a = keys.find((it) => it.name === key)) === null || _a === void 0 ? void 0 : _a.type) !== null && _b !== void 0 ? _b : types_1.GeneralColumnType.UNKNOWN;
|
|
128
|
+
binds.push(toBindValue(colType, conditions[key]));
|
|
129
|
+
index++;
|
|
130
|
+
});
|
|
131
|
+
const query = `UPDATE ${tableNameWithSchema} SET ${setList.join(',')} WHERE ${conditionList.join(' AND ')}`;
|
|
132
|
+
return {
|
|
133
|
+
query,
|
|
134
|
+
binds,
|
|
135
|
+
};
|
|
136
|
+
};
|
|
137
|
+
exports.toUpdateStatementWithBinds = toUpdateStatementWithBinds;
|
|
138
|
+
const toDeleteStatementWithBinds = ({ schemaName, tableName, keys, conditions, toPositionedParameter, quote, }) => {
|
|
139
|
+
const tableNameWithSchema = createTableNameWithSchema({
|
|
140
|
+
schema: schemaName,
|
|
141
|
+
table: tableName,
|
|
142
|
+
quote,
|
|
143
|
+
});
|
|
144
|
+
const binds = [];
|
|
145
|
+
const conditionList = [];
|
|
146
|
+
Object.keys(conditions).forEach((key, index) => {
|
|
147
|
+
var _a, _b;
|
|
148
|
+
conditionList.push(`${wrapQuote(key, quote)} = ${toPositionedParameter === true ? `$${index + 1}` : '?'}`);
|
|
149
|
+
const colType = (_b = (_a = keys.find((it) => it.name === key)) === null || _a === void 0 ? void 0 : _a.type) !== null && _b !== void 0 ? _b : types_1.GeneralColumnType.UNKNOWN;
|
|
150
|
+
binds.push(toBindValue(colType, conditions[key]));
|
|
151
|
+
});
|
|
152
|
+
const query = `DELETE FROM ${tableNameWithSchema} WHERE ${conditionList.join(' AND ')}`;
|
|
153
|
+
return {
|
|
154
|
+
query,
|
|
155
|
+
binds,
|
|
156
|
+
};
|
|
157
|
+
};
|
|
158
|
+
exports.toDeleteStatementWithBinds = toDeleteStatementWithBinds;
|
|
159
|
+
const toViewDataQuery = ({ tableRes, schemaName, toPositionedParameter, conditions, quote, }) => {
|
|
160
|
+
const tableNameWithSchema = createTableNameWithSchema({
|
|
161
|
+
schema: schemaName,
|
|
162
|
+
table: tableRes.name,
|
|
163
|
+
quote,
|
|
164
|
+
});
|
|
165
|
+
const binds = [];
|
|
166
|
+
let query = `SELECT * FROM ${tableNameWithSchema} `;
|
|
167
|
+
if (conditions && conditions.items.length) {
|
|
168
|
+
const { andOr, items } = conditions;
|
|
169
|
+
query += 'WHERE ';
|
|
170
|
+
let pos = 1;
|
|
171
|
+
items.forEach((it, idx) => {
|
|
172
|
+
if (idx > 0) {
|
|
173
|
+
query += andOr === 'and' ? 'AND ' : 'OR ';
|
|
174
|
+
}
|
|
175
|
+
query += `${wrapQuote(it.column, quote)} ${(0, exports.operatorToString)(it.operator)} `;
|
|
176
|
+
switch (it.operator) {
|
|
177
|
+
case 'isNotNull':
|
|
178
|
+
case 'isNull':
|
|
179
|
+
return;
|
|
180
|
+
case 'in':
|
|
181
|
+
case 'notIn':
|
|
182
|
+
{
|
|
183
|
+
query += ' (';
|
|
184
|
+
it.values.forEach((v, idx2) => {
|
|
185
|
+
if (idx2 > 0) {
|
|
186
|
+
query += ',';
|
|
187
|
+
}
|
|
188
|
+
if (toPositionedParameter === true) {
|
|
189
|
+
query += `$${pos} `;
|
|
190
|
+
}
|
|
191
|
+
else {
|
|
192
|
+
query += `? `;
|
|
193
|
+
}
|
|
194
|
+
binds.push(toBindValue(tableRes.getChildByName(it.column).colType, v));
|
|
195
|
+
pos++;
|
|
196
|
+
});
|
|
197
|
+
query += ') ';
|
|
198
|
+
}
|
|
199
|
+
break;
|
|
200
|
+
default:
|
|
201
|
+
{
|
|
202
|
+
if (toPositionedParameter === true) {
|
|
203
|
+
query += `$${pos} `;
|
|
204
|
+
}
|
|
205
|
+
else {
|
|
206
|
+
query += `? `;
|
|
207
|
+
}
|
|
208
|
+
binds.push(toBindValue(tableRes.getChildByName(it.column).colType, it.value));
|
|
209
|
+
pos++;
|
|
210
|
+
}
|
|
211
|
+
break;
|
|
212
|
+
}
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
return {
|
|
216
|
+
query: query.trim(),
|
|
217
|
+
binds,
|
|
218
|
+
};
|
|
219
|
+
};
|
|
220
|
+
exports.toViewDataQuery = toViewDataQuery;
|
|
13
221
|
const toSafeQueryForPgsqlAst = (query) => {
|
|
14
|
-
let replacedSql = query.replace(/\?/g, '$1');
|
|
222
|
+
let replacedSql = stripComment(query).replace(/\?/g, '$1');
|
|
15
223
|
replacedSql = replacedSql.replace(/^\s*(SHOW)\s+(\S+).*$/i, '$1 $2');
|
|
16
224
|
replacedSql = replacedSql.replace(/\s*INTERVAL\s+([\d]+)\s+(\S+)/i, " cast('$1 $2' as INTERVAL)");
|
|
17
225
|
replacedSql = replacedSql.replace(/\bLIMIT\s+([\d]+)\s*,\s*([\d]+)/i, 'LIMIT $2 OFFSET $1');
|
|
@@ -46,7 +254,9 @@ const normalizePositionedParametersQuery = (query, bindParams) => {
|
|
|
46
254
|
const checkBindParam = (s) => {
|
|
47
255
|
if (bindParams && bindParams[s] === undefined) {
|
|
48
256
|
missingParams.add(s);
|
|
257
|
+
return false;
|
|
49
258
|
}
|
|
259
|
+
return true;
|
|
50
260
|
};
|
|
51
261
|
const getOrCreateSinglePosition = (word) => {
|
|
52
262
|
if (!nameWithPos[word]) {
|
|
@@ -84,39 +294,20 @@ const normalizePositionedParametersQuery = (query, bindParams) => {
|
|
|
84
294
|
}
|
|
85
295
|
return list.join(',');
|
|
86
296
|
};
|
|
87
|
-
const lines = (0, util_1.tolines)(query);
|
|
297
|
+
const lines = (0, util_1.tolines)(stripComment(query));
|
|
88
298
|
const newLines = [];
|
|
89
299
|
lines.forEach((line) => {
|
|
90
|
-
const reg = /((
|
|
91
|
-
const normalized = line.replace(reg, (substring, g1, g2,
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
const
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
checkBindParam(word);
|
|
101
|
-
if (!bindParams ||
|
|
102
|
-
!bindParams[word] ||
|
|
103
|
-
bindParams[word].length === 0) {
|
|
104
|
-
return `${g5}( null )`;
|
|
300
|
+
const reg = /((?<!:):([a-zA-Z_$]\w*)\b)/gi;
|
|
301
|
+
const normalized = line.replace(reg, (substring, g1, g2, offset) => {
|
|
302
|
+
if (g1) {
|
|
303
|
+
const word = g2;
|
|
304
|
+
const ok = checkBindParam(word);
|
|
305
|
+
if (ok && Array.isArray(bindParams[word])) {
|
|
306
|
+
return getOrCreateMultiplePosition(word);
|
|
307
|
+
}
|
|
308
|
+
else {
|
|
309
|
+
return getOrCreateSinglePosition(word);
|
|
105
310
|
}
|
|
106
|
-
return `${g5}(${getOrCreateMultiplePosition(word)})`;
|
|
107
|
-
}
|
|
108
|
-
else if (g7) {
|
|
109
|
-
const word = g8;
|
|
110
|
-
checkBindParam(word);
|
|
111
|
-
return getOrCreateSinglePosition(word);
|
|
112
|
-
}
|
|
113
|
-
else if (g9) {
|
|
114
|
-
const word = g10;
|
|
115
|
-
checkBindParam(word);
|
|
116
|
-
return (_a = bindParams[word]) !== null && _a !== void 0 ? _a : '';
|
|
117
|
-
}
|
|
118
|
-
else if (g11) {
|
|
119
|
-
return substring;
|
|
120
311
|
}
|
|
121
312
|
return '';
|
|
122
313
|
});
|
|
@@ -156,51 +347,33 @@ const normalizeSimpleParametersQuery = (query, bindParams) => {
|
|
|
156
347
|
const checkBindParam = (s) => {
|
|
157
348
|
if (bindParams && bindParams[s] === undefined) {
|
|
158
349
|
missingParams.add(s);
|
|
350
|
+
return false;
|
|
159
351
|
}
|
|
352
|
+
return true;
|
|
160
353
|
};
|
|
161
354
|
const pushBindParam = (s) => {
|
|
162
355
|
if (bindParams) {
|
|
163
356
|
binds.push(bindParams[s]);
|
|
164
357
|
}
|
|
165
358
|
};
|
|
166
|
-
const lines = (0, util_1.tolines)(query);
|
|
359
|
+
const lines = (0, util_1.tolines)(stripComment(query));
|
|
167
360
|
const newLines = [];
|
|
168
361
|
lines.forEach((line) => {
|
|
169
|
-
const reg = /((
|
|
170
|
-
const normalized = line.replace(reg, (substring, g1, g2,
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
const
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
bindParams[word].length === 0) {
|
|
184
|
-
return `${g5}( null )`;
|
|
362
|
+
const reg = /((?<!:):([a-zA-Z_$]\w*)\b)/gi;
|
|
363
|
+
const normalized = line.replace(reg, (substring, g1, g2, offset) => {
|
|
364
|
+
if (g1) {
|
|
365
|
+
const word = g2;
|
|
366
|
+
const ok = checkBindParam(word);
|
|
367
|
+
if (ok && Array.isArray(bindParams[word])) {
|
|
368
|
+
const numOfBinds = bindParams[word].length;
|
|
369
|
+
binds.push(...bindParams[word]);
|
|
370
|
+
const bindStr = '?,'.repeat(numOfBinds);
|
|
371
|
+
return bindStr.substring(0, bindStr.length - 1);
|
|
372
|
+
}
|
|
373
|
+
else {
|
|
374
|
+
pushBindParam(word);
|
|
375
|
+
return '?';
|
|
185
376
|
}
|
|
186
|
-
const numOfBinds = bindParams[word].length;
|
|
187
|
-
binds.push(...bindParams[word]);
|
|
188
|
-
const bindStr = '?,'.repeat(numOfBinds);
|
|
189
|
-
return `${g5}(${bindStr.substring(0, bindStr.length - 1)})`;
|
|
190
|
-
}
|
|
191
|
-
else if (g7) {
|
|
192
|
-
const word = g8;
|
|
193
|
-
pushBindParam(word);
|
|
194
|
-
checkBindParam(word);
|
|
195
|
-
return '?';
|
|
196
|
-
}
|
|
197
|
-
else if (g9) {
|
|
198
|
-
const word = g10;
|
|
199
|
-
checkBindParam(word);
|
|
200
|
-
return (_a = bindParams[word]) !== null && _a !== void 0 ? _a : '';
|
|
201
|
-
}
|
|
202
|
-
else if (g11) {
|
|
203
|
-
return substring;
|
|
204
377
|
}
|
|
205
378
|
return '';
|
|
206
379
|
});
|
|
@@ -240,10 +413,10 @@ const getProposals = (params) => {
|
|
|
240
413
|
}
|
|
241
414
|
}
|
|
242
415
|
if (lastChar !== '.' && !parentWord) {
|
|
243
|
-
|
|
416
|
+
constant_1.RESERVED_WORDS.filter((s) => s.startsWith(upperKeyword)).forEach((s) => {
|
|
244
417
|
retList.push({
|
|
245
418
|
label: s,
|
|
246
|
-
kind: ProposalKind.ReservedWord,
|
|
419
|
+
kind: types_1.ProposalKind.ReservedWord,
|
|
247
420
|
});
|
|
248
421
|
});
|
|
249
422
|
}
|
|
@@ -277,30 +450,32 @@ const getResourcePositions = (params) => {
|
|
|
277
450
|
});
|
|
278
451
|
}
|
|
279
452
|
retList.push({
|
|
280
|
-
kind: ProposalKind.Table,
|
|
453
|
+
kind: types_1.ProposalKind.Table,
|
|
281
454
|
name: tableRes.name,
|
|
282
455
|
comment,
|
|
283
456
|
offset: m.index,
|
|
284
457
|
length: name.length,
|
|
285
458
|
});
|
|
286
459
|
}
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
460
|
+
if (columnNameSet.size > 0) {
|
|
461
|
+
const reg2 = new RegExp('\\b(' + Array.from(columnNameSet).join('|') + ')\\b', 'g');
|
|
462
|
+
let m2;
|
|
463
|
+
while ((m2 = reg2.exec(sqlLowerCase)) !== null) {
|
|
464
|
+
const name = m2[0];
|
|
465
|
+
const columnRes = tableResList
|
|
466
|
+
.flatMap((table) => table.children)
|
|
467
|
+
.find((column) => column.name.toLocaleLowerCase() === name);
|
|
468
|
+
if (!columnRes) {
|
|
469
|
+
continue;
|
|
470
|
+
}
|
|
471
|
+
retList.push({
|
|
472
|
+
kind: types_1.ProposalKind.Column,
|
|
473
|
+
name: columnRes.name,
|
|
474
|
+
comment: columnRes.comment,
|
|
475
|
+
offset: m2.index,
|
|
476
|
+
length: name.length,
|
|
477
|
+
});
|
|
296
478
|
}
|
|
297
|
-
retList.push({
|
|
298
|
-
kind: ProposalKind.Column,
|
|
299
|
-
name: columnRes.name,
|
|
300
|
-
comment: columnRes.comment,
|
|
301
|
-
offset: m2.index,
|
|
302
|
-
length: name.length,
|
|
303
|
-
});
|
|
304
479
|
}
|
|
305
480
|
return retList;
|
|
306
481
|
};
|
|
@@ -401,7 +576,7 @@ const getAllProposals = (db) => {
|
|
|
401
576
|
var _a;
|
|
402
577
|
retList.push({
|
|
403
578
|
label: it.name,
|
|
404
|
-
kind: ProposalKind.Column,
|
|
579
|
+
kind: types_1.ProposalKind.Column,
|
|
405
580
|
detail: (_a = it.comment) !== null && _a !== void 0 ? _a : '',
|
|
406
581
|
});
|
|
407
582
|
});
|
|
@@ -415,7 +590,7 @@ const createTableProposal = (schema, table) => {
|
|
|
415
590
|
}
|
|
416
591
|
return {
|
|
417
592
|
label: table.name,
|
|
418
|
-
kind: ProposalKind.Table,
|
|
593
|
+
kind: types_1.ProposalKind.Table,
|
|
419
594
|
detail,
|
|
420
595
|
};
|
|
421
596
|
};
|
|
@@ -424,281 +599,32 @@ const createColumnProposal = (table, column) => {
|
|
|
424
599
|
const detail = `${(_a = table.comment) !== null && _a !== void 0 ? _a : table.name}.${(_b = column.comment) !== null && _b !== void 0 ? _b : column.name}`;
|
|
425
600
|
return {
|
|
426
601
|
label: column.name,
|
|
427
|
-
kind: ProposalKind.Column,
|
|
602
|
+
kind: types_1.ProposalKind.Column,
|
|
428
603
|
detail,
|
|
429
604
|
};
|
|
430
605
|
};
|
|
606
|
+
const stripComment = (query) => {
|
|
607
|
+
return query
|
|
608
|
+
.replace(/\/\*[^*]*\*\//gm, '')
|
|
609
|
+
.replace(/(\s)?(#|--)\s+.*$/g, '$1');
|
|
610
|
+
};
|
|
431
611
|
const createReservedWordProposal = (word) => {
|
|
432
612
|
return {
|
|
433
613
|
label: word,
|
|
434
|
-
kind: ProposalKind.ReservedWord,
|
|
614
|
+
kind: types_1.ProposalKind.ReservedWord,
|
|
435
615
|
};
|
|
436
616
|
};
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
'BINARY',
|
|
451
|
-
'BLOB',
|
|
452
|
-
'BOTH',
|
|
453
|
-
'BY',
|
|
454
|
-
'CALL',
|
|
455
|
-
'CASCADE',
|
|
456
|
-
'CASE',
|
|
457
|
-
'CHANGE',
|
|
458
|
-
'CHAR',
|
|
459
|
-
'CHARACTER',
|
|
460
|
-
'CHECK',
|
|
461
|
-
'COLLATE',
|
|
462
|
-
'COLUMN',
|
|
463
|
-
'CONDITION',
|
|
464
|
-
'CONSTRAINT',
|
|
465
|
-
'CONTINUE',
|
|
466
|
-
'CONVERT',
|
|
467
|
-
'CREATE',
|
|
468
|
-
'CROSS',
|
|
469
|
-
'CURRENT_DATE',
|
|
470
|
-
'CURRENT_TIME',
|
|
471
|
-
'CURRENT_TIMESTAMP',
|
|
472
|
-
'CURRENT_USER',
|
|
473
|
-
'CURSOR',
|
|
474
|
-
'DATABASE',
|
|
475
|
-
'DATABASES',
|
|
476
|
-
'DAY_HOUR',
|
|
477
|
-
'DAY_MICROSECOND',
|
|
478
|
-
'DAY_MINUTE',
|
|
479
|
-
'DAY_SECOND',
|
|
480
|
-
'DEC',
|
|
481
|
-
'DECIMAL',
|
|
482
|
-
'DECLARE',
|
|
483
|
-
'DEFAULT',
|
|
484
|
-
'DELAYED',
|
|
485
|
-
'DELETE',
|
|
486
|
-
'DESC',
|
|
487
|
-
'DESCRIBE',
|
|
488
|
-
'DETERMINISTIC',
|
|
489
|
-
'DISTINCT',
|
|
490
|
-
'DISTINCTROW',
|
|
491
|
-
'DIV',
|
|
492
|
-
'DOUBLE',
|
|
493
|
-
'DROP',
|
|
494
|
-
'DUAL',
|
|
495
|
-
'EACH',
|
|
496
|
-
'ELSE',
|
|
497
|
-
'ELSEIF',
|
|
498
|
-
'ENCLOSED',
|
|
499
|
-
'ESCAPED',
|
|
500
|
-
'EXISTS',
|
|
501
|
-
'EXIT',
|
|
502
|
-
'EXPLAIN',
|
|
503
|
-
'FALSE',
|
|
504
|
-
'FETCH',
|
|
505
|
-
'FLOAT',
|
|
506
|
-
'FLOAT4',
|
|
507
|
-
'FLOAT8',
|
|
508
|
-
'FOR',
|
|
509
|
-
'FORCE',
|
|
510
|
-
'FOREIGN',
|
|
511
|
-
'FROM',
|
|
512
|
-
'FULLTEXT',
|
|
513
|
-
'GRANT',
|
|
514
|
-
'GROUP',
|
|
515
|
-
'HAVING',
|
|
516
|
-
'HIGH_PRIORITY',
|
|
517
|
-
'HOUR_MICROSECOND',
|
|
518
|
-
'HOUR_MINUTE',
|
|
519
|
-
'HOUR_SECOND',
|
|
520
|
-
'IF',
|
|
521
|
-
'IGNORE',
|
|
522
|
-
'IN',
|
|
523
|
-
'INDEX',
|
|
524
|
-
'INFILE',
|
|
525
|
-
'INNER',
|
|
526
|
-
'INOUT',
|
|
527
|
-
'INSENSITIVE',
|
|
528
|
-
'INSERT',
|
|
529
|
-
'INT',
|
|
530
|
-
'INT1',
|
|
531
|
-
'INT2',
|
|
532
|
-
'INT3',
|
|
533
|
-
'INT4',
|
|
534
|
-
'INT8',
|
|
535
|
-
'INTEGER',
|
|
536
|
-
'INTERVAL',
|
|
537
|
-
'INTO',
|
|
538
|
-
'IS',
|
|
539
|
-
'ITERATE',
|
|
540
|
-
'JOIN',
|
|
541
|
-
'KEY',
|
|
542
|
-
'KEYS',
|
|
543
|
-
'KILL',
|
|
544
|
-
'LEADING',
|
|
545
|
-
'LEAVE',
|
|
546
|
-
'LEFT',
|
|
547
|
-
'LIKE',
|
|
548
|
-
'LIMIT',
|
|
549
|
-
'LINEAR',
|
|
550
|
-
'LINES',
|
|
551
|
-
'LOAD',
|
|
552
|
-
'LOCALTIME',
|
|
553
|
-
'LOCALTIMESTAMP',
|
|
554
|
-
'LOCK',
|
|
555
|
-
'LONG',
|
|
556
|
-
'LONGBLOB',
|
|
557
|
-
'LONGTEXT',
|
|
558
|
-
'LOOP',
|
|
559
|
-
'LOW_PRIORITY',
|
|
560
|
-
'MASTER_SSL_VERIFY_SERVER_CERT',
|
|
561
|
-
'MATCH',
|
|
562
|
-
'MEDIUMBLOB',
|
|
563
|
-
'MEDIUMINT',
|
|
564
|
-
'MEDIUMTEXT',
|
|
565
|
-
'MIDDLEINT',
|
|
566
|
-
'MINUTE_MICROSECOND',
|
|
567
|
-
'MINUTE_SECOND',
|
|
568
|
-
'MOD',
|
|
569
|
-
'MODIFIES',
|
|
570
|
-
'NATURAL',
|
|
571
|
-
'NOT',
|
|
572
|
-
'NO_WRITE_TO_BINLOG',
|
|
573
|
-
'NULL',
|
|
574
|
-
'NUMERIC',
|
|
575
|
-
'ON',
|
|
576
|
-
'OPTIMIZE',
|
|
577
|
-
'OPTION',
|
|
578
|
-
'OPTIONALLY',
|
|
579
|
-
'OR',
|
|
580
|
-
'ORDER',
|
|
581
|
-
'OUT',
|
|
582
|
-
'OUTER',
|
|
583
|
-
'OUTFILE',
|
|
584
|
-
'PRECISION',
|
|
585
|
-
'PRIMARY',
|
|
586
|
-
'PROCEDURE',
|
|
587
|
-
'PURGE',
|
|
588
|
-
'RANGE',
|
|
589
|
-
'READ',
|
|
590
|
-
'READS',
|
|
591
|
-
'READ_ONLY',
|
|
592
|
-
'READ_WRITE',
|
|
593
|
-
'REAL',
|
|
594
|
-
'REFERENCES',
|
|
595
|
-
'REGEXP',
|
|
596
|
-
'RELEASE',
|
|
597
|
-
'RENAME',
|
|
598
|
-
'REPEAT',
|
|
599
|
-
'REPLACE',
|
|
600
|
-
'REQUIRE',
|
|
601
|
-
'RESTRICT',
|
|
602
|
-
'RETURN',
|
|
603
|
-
'REVOKE',
|
|
604
|
-
'RIGHT',
|
|
605
|
-
'RLIKE',
|
|
606
|
-
'SCHEMA',
|
|
607
|
-
'SCHEMAS',
|
|
608
|
-
'SECOND_MICROSECOND',
|
|
609
|
-
'SELECT',
|
|
610
|
-
'SENSITIVE',
|
|
611
|
-
'SEPARATOR',
|
|
612
|
-
'SET',
|
|
613
|
-
'SHOW',
|
|
614
|
-
'SMALLINT',
|
|
615
|
-
'SPATIAL',
|
|
616
|
-
'SPECIFIC',
|
|
617
|
-
'SQL',
|
|
618
|
-
'SQLEXCEPTION',
|
|
619
|
-
'SQLSTATE',
|
|
620
|
-
'SQLWARNING',
|
|
621
|
-
'SQL_BIG_RESULT',
|
|
622
|
-
'SQL_CALC_FOUND_ROWS',
|
|
623
|
-
'SQL_SMALL_RESULT',
|
|
624
|
-
'SSL',
|
|
625
|
-
'STARTING',
|
|
626
|
-
'STRAIGHT_JOIN',
|
|
627
|
-
'TABLE',
|
|
628
|
-
'TERMINATED',
|
|
629
|
-
'THEN',
|
|
630
|
-
'TINYBLOB',
|
|
631
|
-
'TINYINT',
|
|
632
|
-
'TINYTEXT',
|
|
633
|
-
'TO',
|
|
634
|
-
'TRAILING',
|
|
635
|
-
'TRIGGER',
|
|
636
|
-
'TRUE',
|
|
637
|
-
'UNDO',
|
|
638
|
-
'UNION',
|
|
639
|
-
'UNIQUE',
|
|
640
|
-
'UNLOCK',
|
|
641
|
-
'UNSIGNED',
|
|
642
|
-
'UPDATE',
|
|
643
|
-
'USAGE',
|
|
644
|
-
'USE',
|
|
645
|
-
'USING',
|
|
646
|
-
'UTC_DATE',
|
|
647
|
-
'UTC_TIME',
|
|
648
|
-
'UTC_TIMESTAMP',
|
|
649
|
-
'VALUES',
|
|
650
|
-
'VARBINARY',
|
|
651
|
-
'VARCHAR',
|
|
652
|
-
'VARCHARACTER',
|
|
653
|
-
'VARYING',
|
|
654
|
-
'WHEN',
|
|
655
|
-
'WHERE',
|
|
656
|
-
'WHILE',
|
|
657
|
-
'WITH',
|
|
658
|
-
'WRITE',
|
|
659
|
-
'XOR',
|
|
660
|
-
'YEAR_MONTH',
|
|
661
|
-
'ZEROFILL',
|
|
662
|
-
];
|
|
663
|
-
exports.FUNCTIONS = [
|
|
664
|
-
'ADDDATE',
|
|
665
|
-
'ADDTIME',
|
|
666
|
-
'CONVERT_TZ',
|
|
667
|
-
'CURDATE',
|
|
668
|
-
'CURRENT_DATE',
|
|
669
|
-
'CURRENT_TIME',
|
|
670
|
-
'CURRENT_TIMESTAMP',
|
|
671
|
-
'CURTIME',
|
|
672
|
-
'DATE',
|
|
673
|
-
'DATE_ADD',
|
|
674
|
-
'DATE_FORMAT',
|
|
675
|
-
'DATE_SUB',
|
|
676
|
-
'DATEDIFF',
|
|
677
|
-
'DAY',
|
|
678
|
-
'DAYNAME',
|
|
679
|
-
'DAYOFMONTH',
|
|
680
|
-
'DAYOFWEEK',
|
|
681
|
-
'DAYOFYEAR',
|
|
682
|
-
'EXTRACT',
|
|
683
|
-
'FROM_DAYS',
|
|
684
|
-
'FROM_UNIXTIME',
|
|
685
|
-
'GET_FORMAT',
|
|
686
|
-
'HOUR',
|
|
687
|
-
'LAST_DAY',
|
|
688
|
-
'LOCALTIME',
|
|
689
|
-
'LOCALTIMESTAMP',
|
|
690
|
-
'MAKEDATE',
|
|
691
|
-
'MAKETIME',
|
|
692
|
-
'MICROSECOND',
|
|
693
|
-
'MINUTE',
|
|
694
|
-
'MONTH',
|
|
695
|
-
'MONTHNAME',
|
|
696
|
-
'NOW',
|
|
697
|
-
'SYSDATE',
|
|
698
|
-
'TIMESTAMP',
|
|
699
|
-
'IFNULL',
|
|
700
|
-
'NULLIF',
|
|
701
|
-
'GROUP_CONCAT',
|
|
702
|
-
];
|
|
703
|
-
const FUNCTION_MATCHER = new RegExp(`(${exports.FUNCTIONS.join('|')})\\([^)]+?\\)`, 'gi');
|
|
617
|
+
const wrapQuote = (s, withQuote) => {
|
|
618
|
+
if (withQuote === true) {
|
|
619
|
+
return `\`${s}\``;
|
|
620
|
+
}
|
|
621
|
+
return s;
|
|
622
|
+
};
|
|
623
|
+
const createTableNameWithSchema = ({ schema, table, quote, }) => {
|
|
624
|
+
if (schema) {
|
|
625
|
+
return `${wrapQuote(schema, quote)}.${wrapQuote(table, quote)}`;
|
|
626
|
+
}
|
|
627
|
+
return `${wrapQuote(table, quote)}`;
|
|
628
|
+
};
|
|
629
|
+
const FUNCTION_MATCHER = new RegExp(`(${constant_1.FUNCTIONS.join('|')})\\([^)]+?\\)`, 'gi');
|
|
704
630
|
//# sourceMappingURL=SQLHelper.js.map
|