squel 5.13.0 → 6.0.5
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/CHANGELOG.md +39 -1
- package/README.md +160 -186
- package/dist/browser/squel.min.js +1 -0
- package/dist/cjs/index.js +1824 -0
- package/dist/cjs/index.js.map +14 -0
- package/dist/cjs/package.json +1 -0
- package/dist/esm/index.js +1783 -0
- package/dist/esm/index.js.map +14 -0
- package/dist/esm/package.json +1 -0
- package/dist/types/core.d.ts +12 -0
- package/dist/types/core.d.ts.map +1 -0
- package/dist/types/index.d.ts +8 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/mssql.d.ts +2 -0
- package/dist/types/mssql.d.ts.map +1 -0
- package/dist/types/mysql.d.ts +2 -0
- package/dist/types/mysql.d.ts.map +1 -0
- package/dist/types/postgres.d.ts +2 -0
- package/dist/types/postgres.d.ts.map +1 -0
- package/dist/types/types.d.ts +206 -0
- package/dist/types/types.d.ts.map +1 -0
- package/package.json +61 -41
- package/CONTRIBUTING.md +0 -28
- package/RELEASE.md +0 -13
- package/dist/squel-basic.js +0 -3067
- package/dist/squel-basic.min.js +0 -2
- package/dist/squel.d.ts +0 -1750
- package/dist/squel.js +0 -3982
- package/dist/squel.min.js +0 -2
- package/gulpfile.js +0 -117
- package/performance/select.js +0 -22
|
@@ -0,0 +1,1824 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
function __accessProp(key) {
|
|
6
|
+
return this[key];
|
|
7
|
+
}
|
|
8
|
+
var __toCommonJS = (from) => {
|
|
9
|
+
var entry = (__moduleCache ??= new WeakMap).get(from), desc;
|
|
10
|
+
if (entry)
|
|
11
|
+
return entry;
|
|
12
|
+
entry = __defProp({}, "__esModule", { value: true });
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (var key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(entry, key))
|
|
16
|
+
__defProp(entry, key, {
|
|
17
|
+
get: __accessProp.bind(from, key),
|
|
18
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
__moduleCache.set(from, entry);
|
|
22
|
+
return entry;
|
|
23
|
+
};
|
|
24
|
+
var __moduleCache;
|
|
25
|
+
var __returnValue = (v) => v;
|
|
26
|
+
function __exportSetter(name, newValue) {
|
|
27
|
+
this[name] = __returnValue.bind(null, newValue);
|
|
28
|
+
}
|
|
29
|
+
var __export = (target, all) => {
|
|
30
|
+
for (var name in all)
|
|
31
|
+
__defProp(target, name, {
|
|
32
|
+
get: all[name],
|
|
33
|
+
enumerable: true,
|
|
34
|
+
configurable: true,
|
|
35
|
+
set: __exportSetter.bind(all, name)
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
// src/index.ts
|
|
40
|
+
var exports_src = {};
|
|
41
|
+
__export(exports_src, {
|
|
42
|
+
squel: () => core_default,
|
|
43
|
+
default: () => src_default
|
|
44
|
+
});
|
|
45
|
+
module.exports = __toCommonJS(exports_src);
|
|
46
|
+
// package.json
|
|
47
|
+
var package_default = {
|
|
48
|
+
name: "squel",
|
|
49
|
+
version: "6.0.5",
|
|
50
|
+
description: "SQL query string builder",
|
|
51
|
+
keywords: [
|
|
52
|
+
"sql",
|
|
53
|
+
"database",
|
|
54
|
+
"rdbms",
|
|
55
|
+
"query-builder",
|
|
56
|
+
"mysql",
|
|
57
|
+
"postgres",
|
|
58
|
+
"mssql"
|
|
59
|
+
],
|
|
60
|
+
author: "Ramesh Nair <ram@hiddentao.com> (http://www.hiddentao.com/)",
|
|
61
|
+
contributors: [
|
|
62
|
+
"Ramesh Nair <ram@hiddentao.com> (http://www.hiddentao.com/)",
|
|
63
|
+
"Sergej Brjuchanov <serges@seznam.cz>"
|
|
64
|
+
],
|
|
65
|
+
license: "MIT",
|
|
66
|
+
repository: {
|
|
67
|
+
type: "git",
|
|
68
|
+
url: "https://github.com/hiddentao/squel.git"
|
|
69
|
+
},
|
|
70
|
+
homepage: "https://github.com/hiddentao/squel",
|
|
71
|
+
bugs: {
|
|
72
|
+
url: "https://github.com/hiddentao/squel/issues"
|
|
73
|
+
},
|
|
74
|
+
type: "module",
|
|
75
|
+
main: "./dist/cjs/index.js",
|
|
76
|
+
module: "./dist/esm/index.js",
|
|
77
|
+
types: "./dist/types/index.d.ts",
|
|
78
|
+
exports: {
|
|
79
|
+
".": {
|
|
80
|
+
types: "./dist/types/index.d.ts",
|
|
81
|
+
import: "./dist/esm/index.js",
|
|
82
|
+
require: "./dist/cjs/index.js"
|
|
83
|
+
},
|
|
84
|
+
"./browser": "./dist/browser/squel.min.js"
|
|
85
|
+
},
|
|
86
|
+
files: [
|
|
87
|
+
"dist",
|
|
88
|
+
"README.md",
|
|
89
|
+
"LICENSE.md",
|
|
90
|
+
"CHANGELOG.md"
|
|
91
|
+
],
|
|
92
|
+
engines: {
|
|
93
|
+
node: ">=18.0.0"
|
|
94
|
+
},
|
|
95
|
+
publishConfig: {
|
|
96
|
+
access: "public",
|
|
97
|
+
provenance: true
|
|
98
|
+
},
|
|
99
|
+
scripts: {
|
|
100
|
+
build: "bun run scripts/build.ts",
|
|
101
|
+
test: "bun test",
|
|
102
|
+
"test:coverage": "bun test --coverage --coverage-reporter=lcov",
|
|
103
|
+
"test:watch": "bun test --watch",
|
|
104
|
+
lint: "biome check --write ./src ./tests ./scripts",
|
|
105
|
+
format: "biome format --write ./src ./tests ./scripts",
|
|
106
|
+
check: "biome check ./src ./tests ./scripts",
|
|
107
|
+
typecheck: "tsc --noEmit",
|
|
108
|
+
prepare: "husky",
|
|
109
|
+
prepublishOnly: "bun run build && bun run test"
|
|
110
|
+
},
|
|
111
|
+
dependencies: {},
|
|
112
|
+
devDependencies: {
|
|
113
|
+
"@biomejs/biome": "^1.9.4",
|
|
114
|
+
"@commitlint/cli": "^19.8.1",
|
|
115
|
+
"@commitlint/config-conventional": "^19.8.1",
|
|
116
|
+
"@types/bun": "latest",
|
|
117
|
+
"@types/node": "^22.0.0",
|
|
118
|
+
"commit-and-tag-version": "^12.6.0",
|
|
119
|
+
husky: "^9.1.7",
|
|
120
|
+
typescript: "^5.3.0"
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
// src/core.ts
|
|
125
|
+
function _pad(str, pad) {
|
|
126
|
+
return str.length ? str + pad : str;
|
|
127
|
+
}
|
|
128
|
+
function _extend(dst, ...sources) {
|
|
129
|
+
if (dst && sources) {
|
|
130
|
+
for (const src of sources) {
|
|
131
|
+
if (src && typeof src === "object") {
|
|
132
|
+
for (const key of Object.getOwnPropertyNames(src)) {
|
|
133
|
+
dst[key] = src[key];
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
return dst;
|
|
139
|
+
}
|
|
140
|
+
function _isPlainObject(obj) {
|
|
141
|
+
return !!obj && obj.constructor.prototype === Object.prototype;
|
|
142
|
+
}
|
|
143
|
+
function _isArray(obj) {
|
|
144
|
+
return !!obj && obj.constructor.prototype === Array.prototype;
|
|
145
|
+
}
|
|
146
|
+
function _clone(src) {
|
|
147
|
+
if (!src)
|
|
148
|
+
return src;
|
|
149
|
+
const anySrc = src;
|
|
150
|
+
if (typeof anySrc.clone === "function")
|
|
151
|
+
return anySrc.clone();
|
|
152
|
+
if (_isPlainObject(src) || _isArray(src)) {
|
|
153
|
+
const ret = new anySrc.constructor;
|
|
154
|
+
for (const key of Object.getOwnPropertyNames(src)) {
|
|
155
|
+
if (typeof anySrc[key] !== "function") {
|
|
156
|
+
ret[key] = _clone(anySrc[key]);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
return ret;
|
|
160
|
+
}
|
|
161
|
+
return JSON.parse(JSON.stringify(src));
|
|
162
|
+
}
|
|
163
|
+
function registerValueHandler(handlers, type, handler) {
|
|
164
|
+
const typeofType = typeof type;
|
|
165
|
+
if (typeofType !== "function" && typeofType !== "string") {
|
|
166
|
+
throw new Error("type must be a class constructor or string");
|
|
167
|
+
}
|
|
168
|
+
if (typeof handler !== "function") {
|
|
169
|
+
throw new Error("handler must be a function");
|
|
170
|
+
}
|
|
171
|
+
for (const typeHandler of handlers) {
|
|
172
|
+
if (typeHandler.type === type) {
|
|
173
|
+
typeHandler.handler = handler;
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
handlers.push({ type, handler });
|
|
178
|
+
}
|
|
179
|
+
function getValueHandler(value, localHandlers, globalHandlers) {
|
|
180
|
+
return _getValueHandler(value, localHandlers) || _getValueHandler(value, globalHandlers);
|
|
181
|
+
}
|
|
182
|
+
function _getValueHandler(value, handlers) {
|
|
183
|
+
for (const typeHandler of handlers) {
|
|
184
|
+
if (typeof value === typeHandler.type || typeof typeHandler.type !== "string" && value instanceof typeHandler.type) {
|
|
185
|
+
return typeHandler.handler;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
function _buildSquel(flavour = null) {
|
|
191
|
+
const cls = {
|
|
192
|
+
isSquelBuilder(obj) {
|
|
193
|
+
return !!obj && !!obj._toParamString;
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
const _shouldApplyNesting = (obj) => {
|
|
197
|
+
return !cls.isSquelBuilder(obj) || !obj.options.rawNesting;
|
|
198
|
+
};
|
|
199
|
+
cls.DefaultQueryBuilderOptions = {
|
|
200
|
+
autoQuoteTableNames: false,
|
|
201
|
+
autoQuoteFieldNames: false,
|
|
202
|
+
autoQuoteAliasNames: true,
|
|
203
|
+
useAsForTableAliasNames: false,
|
|
204
|
+
nameQuoteCharacter: "`",
|
|
205
|
+
tableAliasQuoteCharacter: "`",
|
|
206
|
+
fieldAliasQuoteCharacter: '"',
|
|
207
|
+
valueHandlers: [],
|
|
208
|
+
parameterCharacter: "?",
|
|
209
|
+
numberedParameters: false,
|
|
210
|
+
numberedParametersPrefix: "$",
|
|
211
|
+
numberedParametersStartAt: 1,
|
|
212
|
+
replaceSingleQuotes: false,
|
|
213
|
+
singleQuoteReplacement: "''",
|
|
214
|
+
separator: " ",
|
|
215
|
+
stringFormatter: null,
|
|
216
|
+
rawNesting: false
|
|
217
|
+
};
|
|
218
|
+
cls.globalValueHandlers = [];
|
|
219
|
+
cls.registerValueHandler = (type, handler) => {
|
|
220
|
+
registerValueHandler(cls.globalValueHandlers, type, handler);
|
|
221
|
+
};
|
|
222
|
+
cls.Cloneable = class {
|
|
223
|
+
clone() {
|
|
224
|
+
const newInstance = new this.constructor;
|
|
225
|
+
return _extend(newInstance, _clone(_extend({}, this)));
|
|
226
|
+
}
|
|
227
|
+
};
|
|
228
|
+
cls.BaseBuilder = class extends cls.Cloneable {
|
|
229
|
+
options;
|
|
230
|
+
constructor(options) {
|
|
231
|
+
super();
|
|
232
|
+
const defaults = JSON.parse(JSON.stringify(cls.DefaultQueryBuilderOptions));
|
|
233
|
+
defaults.stringFormatter = cls.DefaultQueryBuilderOptions.stringFormatter;
|
|
234
|
+
this.options = _extend(defaults, options);
|
|
235
|
+
}
|
|
236
|
+
registerValueHandler(type, handler) {
|
|
237
|
+
registerValueHandler(this.options.valueHandlers, type, handler);
|
|
238
|
+
return this;
|
|
239
|
+
}
|
|
240
|
+
_sanitizeExpression(expr) {
|
|
241
|
+
if (!cls.isSquelBuilder(expr)) {
|
|
242
|
+
if (typeof expr !== "string") {
|
|
243
|
+
throw new Error("expression must be a string or builder instance");
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
return expr;
|
|
247
|
+
}
|
|
248
|
+
_sanitizeName(value, type) {
|
|
249
|
+
if (typeof value !== "string") {
|
|
250
|
+
throw new Error(`${type} must be a string`);
|
|
251
|
+
}
|
|
252
|
+
return value;
|
|
253
|
+
}
|
|
254
|
+
_sanitizeField(item) {
|
|
255
|
+
if (!cls.isSquelBuilder(item)) {
|
|
256
|
+
return this._sanitizeName(item, "field name");
|
|
257
|
+
}
|
|
258
|
+
return item;
|
|
259
|
+
}
|
|
260
|
+
_sanitizeBaseBuilder(item) {
|
|
261
|
+
if (cls.isSquelBuilder(item))
|
|
262
|
+
return item;
|
|
263
|
+
throw new Error("must be a builder instance");
|
|
264
|
+
}
|
|
265
|
+
_sanitizeTable(item, _allowNested) {
|
|
266
|
+
if (typeof item !== "string") {
|
|
267
|
+
try {
|
|
268
|
+
return this._sanitizeBaseBuilder(item);
|
|
269
|
+
} catch (_e) {
|
|
270
|
+
throw new Error("table name must be a string or a builder");
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
return this._sanitizeName(item, "table");
|
|
274
|
+
}
|
|
275
|
+
_sanitizeTableAlias(item) {
|
|
276
|
+
return this._sanitizeName(item, "table alias");
|
|
277
|
+
}
|
|
278
|
+
_sanitizeFieldAlias(item) {
|
|
279
|
+
return this._sanitizeName(item, "field alias");
|
|
280
|
+
}
|
|
281
|
+
_sanitizeLimitOffset(value) {
|
|
282
|
+
const num = Number.parseInt(value, 10);
|
|
283
|
+
if (num < 0 || Number.isNaN(num)) {
|
|
284
|
+
throw new Error("limit/offset must be >= 0");
|
|
285
|
+
}
|
|
286
|
+
return num;
|
|
287
|
+
}
|
|
288
|
+
_sanitizeValue(item) {
|
|
289
|
+
const itemType = typeof item;
|
|
290
|
+
if (item === null) {} else if (itemType === "string" || itemType === "number" || itemType === "boolean") {} else if (cls.isSquelBuilder(item)) {} else {
|
|
291
|
+
const typeIsValid = !!getValueHandler(item, this.options.valueHandlers, cls.globalValueHandlers);
|
|
292
|
+
if (!typeIsValid) {
|
|
293
|
+
throw new Error("field value must be a string, number, boolean, null or one of the registered custom value types");
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
return item;
|
|
297
|
+
}
|
|
298
|
+
_escapeValue(value) {
|
|
299
|
+
return this.options.replaceSingleQuotes && value ? value.replace(/'/g, this.options.singleQuoteReplacement) : value;
|
|
300
|
+
}
|
|
301
|
+
_formatTableName(item) {
|
|
302
|
+
if (this.options.autoQuoteTableNames) {
|
|
303
|
+
const q = this.options.nameQuoteCharacter;
|
|
304
|
+
item = `${q}${item}${q}`;
|
|
305
|
+
}
|
|
306
|
+
return item;
|
|
307
|
+
}
|
|
308
|
+
_formatFieldAlias(item) {
|
|
309
|
+
if (this.options.autoQuoteAliasNames) {
|
|
310
|
+
const q = this.options.fieldAliasQuoteCharacter;
|
|
311
|
+
item = `${q}${item}${q}`;
|
|
312
|
+
}
|
|
313
|
+
return item;
|
|
314
|
+
}
|
|
315
|
+
_formatTableAlias(item) {
|
|
316
|
+
if (this.options.autoQuoteAliasNames) {
|
|
317
|
+
const q = this.options.tableAliasQuoteCharacter;
|
|
318
|
+
item = `${q}${item}${q}`;
|
|
319
|
+
}
|
|
320
|
+
return this.options.useAsForTableAliasNames ? `AS ${item}` : item;
|
|
321
|
+
}
|
|
322
|
+
_formatFieldName(item, formattingOptions = {}) {
|
|
323
|
+
if (this.options.autoQuoteFieldNames) {
|
|
324
|
+
const q = this.options.nameQuoteCharacter;
|
|
325
|
+
if (formattingOptions.ignorePeriodsForFieldNameQuotes) {
|
|
326
|
+
item = `${q}${item}${q}`;
|
|
327
|
+
} else {
|
|
328
|
+
item = item.split(".").map((v) => v === "*" ? v : `${q}${v}${q}`).join(".");
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
return item;
|
|
332
|
+
}
|
|
333
|
+
_formatCustomValue(value, asParam, formattingOptions) {
|
|
334
|
+
const customHandler = getValueHandler(value, this.options.valueHandlers, cls.globalValueHandlers);
|
|
335
|
+
if (customHandler) {
|
|
336
|
+
value = customHandler(value, asParam, formattingOptions);
|
|
337
|
+
if (value && value.rawNesting) {
|
|
338
|
+
return { formatted: true, rawNesting: true, value: value.value };
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
return { formatted: !!customHandler, value };
|
|
342
|
+
}
|
|
343
|
+
_formatValueForParamArray(value, formattingOptions = {}) {
|
|
344
|
+
if (_isArray(value)) {
|
|
345
|
+
return value.map((v) => this._formatValueForParamArray(v, formattingOptions));
|
|
346
|
+
}
|
|
347
|
+
return this._formatCustomValue(value, true, formattingOptions).value;
|
|
348
|
+
}
|
|
349
|
+
_formatValueForQueryString(initialValue, formattingOptions = {}) {
|
|
350
|
+
const {
|
|
351
|
+
rawNesting,
|
|
352
|
+
formatted,
|
|
353
|
+
value: fv
|
|
354
|
+
} = this._formatCustomValue(initialValue, false, formattingOptions);
|
|
355
|
+
let value = fv;
|
|
356
|
+
if (formatted) {
|
|
357
|
+
if (rawNesting)
|
|
358
|
+
return value;
|
|
359
|
+
return this._applyNestingFormatting(value, _shouldApplyNesting(initialValue));
|
|
360
|
+
}
|
|
361
|
+
if (_isArray(value)) {
|
|
362
|
+
value = value.map((v) => this._formatValueForQueryString(v));
|
|
363
|
+
value = this._applyNestingFormatting(value.join(", "), _shouldApplyNesting(value));
|
|
364
|
+
} else {
|
|
365
|
+
const typeofValue = typeof value;
|
|
366
|
+
if (value === null) {
|
|
367
|
+
value = "NULL";
|
|
368
|
+
} else if (typeofValue === "boolean") {
|
|
369
|
+
value = value ? "TRUE" : "FALSE";
|
|
370
|
+
} else if (cls.isSquelBuilder(value)) {
|
|
371
|
+
value = this._applyNestingFormatting(value.toString(), _shouldApplyNesting(value));
|
|
372
|
+
} else if (typeofValue !== "number") {
|
|
373
|
+
if (typeofValue === "string" && this.options.stringFormatter) {
|
|
374
|
+
return this.options.stringFormatter(value);
|
|
375
|
+
}
|
|
376
|
+
if (formattingOptions.dontQuote) {
|
|
377
|
+
value = `${value}`;
|
|
378
|
+
} else {
|
|
379
|
+
const escapedValue = this._escapeValue(value);
|
|
380
|
+
value = `'${escapedValue}'`;
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
return value;
|
|
385
|
+
}
|
|
386
|
+
_applyNestingFormatting(str, nesting = true) {
|
|
387
|
+
if (str && typeof str === "string" && nesting && !this.options.rawNesting) {
|
|
388
|
+
let alreadyHasBrackets = str.charAt(0) === "(" && str.charAt(str.length - 1) === ")";
|
|
389
|
+
if (alreadyHasBrackets) {
|
|
390
|
+
let idx = 0;
|
|
391
|
+
let open = 1;
|
|
392
|
+
while (str.length - 1 > ++idx) {
|
|
393
|
+
const c = str.charAt(idx);
|
|
394
|
+
if (c === "(") {
|
|
395
|
+
open++;
|
|
396
|
+
} else if (c === ")") {
|
|
397
|
+
open--;
|
|
398
|
+
if (open < 1) {
|
|
399
|
+
alreadyHasBrackets = false;
|
|
400
|
+
break;
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
if (!alreadyHasBrackets) {
|
|
406
|
+
str = `(${str})`;
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
return str;
|
|
410
|
+
}
|
|
411
|
+
_buildString(str, values, options = {}) {
|
|
412
|
+
const { nested, buildParameterized, formattingOptions } = options;
|
|
413
|
+
values = values || [];
|
|
414
|
+
str = str || "";
|
|
415
|
+
let formattedStr = "";
|
|
416
|
+
let curValue = -1;
|
|
417
|
+
const formattedValues = [];
|
|
418
|
+
const paramChar = this.options.parameterCharacter;
|
|
419
|
+
let idx = 0;
|
|
420
|
+
while (str.length > idx) {
|
|
421
|
+
if (str.substring(idx, idx + paramChar.length) === paramChar) {
|
|
422
|
+
let value = values[++curValue];
|
|
423
|
+
if (buildParameterized) {
|
|
424
|
+
if (cls.isSquelBuilder(value)) {
|
|
425
|
+
const ret = value._toParamString({
|
|
426
|
+
buildParameterized,
|
|
427
|
+
nested: true
|
|
428
|
+
});
|
|
429
|
+
formattedStr += ret.text;
|
|
430
|
+
ret.values.forEach((v) => formattedValues.push(v));
|
|
431
|
+
} else {
|
|
432
|
+
value = this._formatValueForParamArray(value, formattingOptions);
|
|
433
|
+
if (_isArray(value)) {
|
|
434
|
+
const tmpStr = value.map(() => paramChar).join(", ");
|
|
435
|
+
formattedStr += `(${tmpStr})`;
|
|
436
|
+
value.forEach((val) => formattedValues.push(val));
|
|
437
|
+
} else {
|
|
438
|
+
formattedStr += paramChar;
|
|
439
|
+
formattedValues.push(value);
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
} else {
|
|
443
|
+
formattedStr += this._formatValueForQueryString(value, formattingOptions);
|
|
444
|
+
}
|
|
445
|
+
idx += paramChar.length;
|
|
446
|
+
} else {
|
|
447
|
+
formattedStr += str.charAt(idx);
|
|
448
|
+
idx++;
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
return {
|
|
452
|
+
text: this._applyNestingFormatting(formattedStr, !!nested),
|
|
453
|
+
values: formattedValues
|
|
454
|
+
};
|
|
455
|
+
}
|
|
456
|
+
_buildManyStrings(strings, strValues, options = {}) {
|
|
457
|
+
const parts = [];
|
|
458
|
+
const totalValues = [];
|
|
459
|
+
for (let idx = 0;strings.length > idx; ++idx) {
|
|
460
|
+
const inputString = strings[idx];
|
|
461
|
+
const inputValues = strValues[idx];
|
|
462
|
+
const { text, values } = this._buildString(inputString, inputValues, {
|
|
463
|
+
buildParameterized: options.buildParameterized,
|
|
464
|
+
nested: false
|
|
465
|
+
});
|
|
466
|
+
parts.push(text);
|
|
467
|
+
values.forEach((v) => totalValues.push(v));
|
|
468
|
+
}
|
|
469
|
+
const totalStr = parts.join(this.options.separator);
|
|
470
|
+
return {
|
|
471
|
+
text: totalStr.length ? this._applyNestingFormatting(totalStr, !!options.nested) : "",
|
|
472
|
+
values: totalValues
|
|
473
|
+
};
|
|
474
|
+
}
|
|
475
|
+
_toParamString(_options) {
|
|
476
|
+
throw new Error("Not yet implemented");
|
|
477
|
+
}
|
|
478
|
+
toString(options = {}) {
|
|
479
|
+
return this._toParamString(options).text;
|
|
480
|
+
}
|
|
481
|
+
toParam(options = {}) {
|
|
482
|
+
return this._toParamString({ ...options, buildParameterized: true });
|
|
483
|
+
}
|
|
484
|
+
};
|
|
485
|
+
cls.Expression = class extends cls.BaseBuilder {
|
|
486
|
+
_nodes;
|
|
487
|
+
constructor(options) {
|
|
488
|
+
super(options);
|
|
489
|
+
this._nodes = [];
|
|
490
|
+
}
|
|
491
|
+
and(expr, ...params) {
|
|
492
|
+
expr = this._sanitizeExpression(expr);
|
|
493
|
+
this._nodes.push({ type: "AND", expr, para: params });
|
|
494
|
+
return this;
|
|
495
|
+
}
|
|
496
|
+
or(expr, ...params) {
|
|
497
|
+
expr = this._sanitizeExpression(expr);
|
|
498
|
+
this._nodes.push({ type: "OR", expr, para: params });
|
|
499
|
+
return this;
|
|
500
|
+
}
|
|
501
|
+
_toParamString(options = {}) {
|
|
502
|
+
let totalStr = [];
|
|
503
|
+
const totalValues = [];
|
|
504
|
+
for (const node of this._nodes) {
|
|
505
|
+
const { type, expr, para } = node;
|
|
506
|
+
const { text, values } = cls.isSquelBuilder(expr) ? expr._toParamString({
|
|
507
|
+
buildParameterized: options.buildParameterized,
|
|
508
|
+
nested: true
|
|
509
|
+
}) : this._buildString(expr, para, {
|
|
510
|
+
buildParameterized: options.buildParameterized
|
|
511
|
+
});
|
|
512
|
+
if (totalStr.length)
|
|
513
|
+
totalStr.push(type);
|
|
514
|
+
totalStr.push(text);
|
|
515
|
+
values.forEach((v) => totalValues.push(v));
|
|
516
|
+
}
|
|
517
|
+
totalStr = totalStr.join(" ");
|
|
518
|
+
return {
|
|
519
|
+
text: this._applyNestingFormatting(totalStr, !!options.nested),
|
|
520
|
+
values: totalValues
|
|
521
|
+
};
|
|
522
|
+
}
|
|
523
|
+
};
|
|
524
|
+
cls.Case = class extends cls.BaseBuilder {
|
|
525
|
+
_fieldName = null;
|
|
526
|
+
_cases;
|
|
527
|
+
_elseValue = null;
|
|
528
|
+
constructor(fieldName, options = {}) {
|
|
529
|
+
super(options);
|
|
530
|
+
let name = null;
|
|
531
|
+
if (_isPlainObject(fieldName)) {
|
|
532
|
+
options = fieldName;
|
|
533
|
+
} else if (fieldName) {
|
|
534
|
+
name = this._sanitizeField(fieldName);
|
|
535
|
+
}
|
|
536
|
+
this._fieldName = name;
|
|
537
|
+
this.options = _extend(Object.assign({}, cls.DefaultQueryBuilderOptions), options);
|
|
538
|
+
this._cases = [];
|
|
539
|
+
}
|
|
540
|
+
when(expression, ...values) {
|
|
541
|
+
this._cases.unshift({ expression, values: values || [] });
|
|
542
|
+
return this;
|
|
543
|
+
}
|
|
544
|
+
then(result) {
|
|
545
|
+
if (this._cases.length === 0) {
|
|
546
|
+
throw new Error("when() needs to be called first");
|
|
547
|
+
}
|
|
548
|
+
this._cases[0].result = result;
|
|
549
|
+
return this;
|
|
550
|
+
}
|
|
551
|
+
else(elseValue) {
|
|
552
|
+
this._elseValue = elseValue;
|
|
553
|
+
return this;
|
|
554
|
+
}
|
|
555
|
+
_toParamString(options = {}) {
|
|
556
|
+
let totalStr = "";
|
|
557
|
+
const totalValues = [];
|
|
558
|
+
for (const { expression, values, result } of this._cases) {
|
|
559
|
+
totalStr = _pad(totalStr, " ");
|
|
560
|
+
const ret = this._buildString(expression, values, {
|
|
561
|
+
buildParameterized: options.buildParameterized,
|
|
562
|
+
nested: true
|
|
563
|
+
});
|
|
564
|
+
totalStr += `WHEN ${ret.text} THEN ${this._formatValueForQueryString(result)}`;
|
|
565
|
+
ret.values.forEach((v) => totalValues.push(v));
|
|
566
|
+
}
|
|
567
|
+
if (totalStr.length) {
|
|
568
|
+
totalStr += ` ELSE ${this._formatValueForQueryString(this._elseValue)} END`;
|
|
569
|
+
if (this._fieldName)
|
|
570
|
+
totalStr = `${this._fieldName} ${totalStr}`;
|
|
571
|
+
totalStr = `CASE ${totalStr}`;
|
|
572
|
+
} else {
|
|
573
|
+
totalStr = this._formatValueForQueryString(this._elseValue);
|
|
574
|
+
}
|
|
575
|
+
return { text: totalStr, values: totalValues };
|
|
576
|
+
}
|
|
577
|
+
};
|
|
578
|
+
cls.Block = class extends cls.BaseBuilder {
|
|
579
|
+
constructor(options) {
|
|
580
|
+
super(options);
|
|
581
|
+
}
|
|
582
|
+
exposedMethods() {
|
|
583
|
+
const ret = {};
|
|
584
|
+
let obj = this;
|
|
585
|
+
while (obj) {
|
|
586
|
+
for (const prop of Object.getOwnPropertyNames(obj)) {
|
|
587
|
+
if (prop !== "constructor" && typeof obj[prop] === "function" && prop.charAt(0) !== "_" && !cls.Block.prototype[prop]) {
|
|
588
|
+
ret[prop] = obj[prop];
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
obj = Object.getPrototypeOf(obj);
|
|
592
|
+
}
|
|
593
|
+
return ret;
|
|
594
|
+
}
|
|
595
|
+
};
|
|
596
|
+
cls.StringBlock = class extends cls.Block {
|
|
597
|
+
_str;
|
|
598
|
+
constructor(options, str) {
|
|
599
|
+
super(options);
|
|
600
|
+
this._str = str;
|
|
601
|
+
}
|
|
602
|
+
_toParamString(_options = {}) {
|
|
603
|
+
return { text: this._str, values: [] };
|
|
604
|
+
}
|
|
605
|
+
};
|
|
606
|
+
cls.FunctionBlock = class extends cls.Block {
|
|
607
|
+
_strings;
|
|
608
|
+
_values;
|
|
609
|
+
constructor(options) {
|
|
610
|
+
super(options);
|
|
611
|
+
this._strings = [];
|
|
612
|
+
this._values = [];
|
|
613
|
+
}
|
|
614
|
+
function(str, ...values) {
|
|
615
|
+
this._strings.push(str);
|
|
616
|
+
this._values.push(values);
|
|
617
|
+
}
|
|
618
|
+
_toParamString(options = {}) {
|
|
619
|
+
return this._buildManyStrings(this._strings, this._values, options);
|
|
620
|
+
}
|
|
621
|
+
};
|
|
622
|
+
cls.registerValueHandler(cls.FunctionBlock, (value, asParam = false) => {
|
|
623
|
+
return asParam ? value.toParam() : value.toString();
|
|
624
|
+
});
|
|
625
|
+
cls.AbstractTableBlock = class extends cls.Block {
|
|
626
|
+
_tables;
|
|
627
|
+
constructor(options, _prefix) {
|
|
628
|
+
super(options);
|
|
629
|
+
this._tables = [];
|
|
630
|
+
}
|
|
631
|
+
_table(table, alias = null) {
|
|
632
|
+
alias = alias ? this._sanitizeTableAlias(alias) : alias;
|
|
633
|
+
table = this._sanitizeTable(table);
|
|
634
|
+
if (this.options.singleTable)
|
|
635
|
+
this._tables = [];
|
|
636
|
+
this._tables.push({ table, alias });
|
|
637
|
+
}
|
|
638
|
+
_hasTable() {
|
|
639
|
+
return this._tables.length > 0;
|
|
640
|
+
}
|
|
641
|
+
_toParamString(options = {}) {
|
|
642
|
+
let totalStr = "";
|
|
643
|
+
const totalValues = [];
|
|
644
|
+
if (this._hasTable()) {
|
|
645
|
+
for (const { table, alias } of this._tables) {
|
|
646
|
+
totalStr = _pad(totalStr, ", ");
|
|
647
|
+
let tableStr;
|
|
648
|
+
if (cls.isSquelBuilder(table)) {
|
|
649
|
+
const { text, values } = table._toParamString({
|
|
650
|
+
buildParameterized: options.buildParameterized,
|
|
651
|
+
nested: true
|
|
652
|
+
});
|
|
653
|
+
tableStr = text;
|
|
654
|
+
values.forEach((v) => totalValues.push(v));
|
|
655
|
+
} else {
|
|
656
|
+
tableStr = this._formatTableName(table);
|
|
657
|
+
}
|
|
658
|
+
if (alias)
|
|
659
|
+
tableStr += ` ${this._formatTableAlias(alias)}`;
|
|
660
|
+
totalStr += tableStr;
|
|
661
|
+
}
|
|
662
|
+
if (this.options.prefix)
|
|
663
|
+
totalStr = `${this.options.prefix} ${totalStr}`;
|
|
664
|
+
}
|
|
665
|
+
return { text: totalStr, values: totalValues };
|
|
666
|
+
}
|
|
667
|
+
};
|
|
668
|
+
cls.TargetTableBlock = class extends cls.AbstractTableBlock {
|
|
669
|
+
target(table) {
|
|
670
|
+
this._table(table);
|
|
671
|
+
}
|
|
672
|
+
};
|
|
673
|
+
cls.UpdateTableBlock = class extends cls.AbstractTableBlock {
|
|
674
|
+
table(table, alias = null) {
|
|
675
|
+
this._table(table, alias);
|
|
676
|
+
}
|
|
677
|
+
_toParamString(options = {}) {
|
|
678
|
+
if (!this._hasTable())
|
|
679
|
+
throw new Error("table() needs to be called");
|
|
680
|
+
return super._toParamString(options);
|
|
681
|
+
}
|
|
682
|
+
};
|
|
683
|
+
cls.FromTableBlock = class extends cls.AbstractTableBlock {
|
|
684
|
+
constructor(options) {
|
|
685
|
+
super(_extend({}, options, { prefix: "FROM" }));
|
|
686
|
+
}
|
|
687
|
+
from(table, alias = null) {
|
|
688
|
+
this._table(table, alias);
|
|
689
|
+
}
|
|
690
|
+
};
|
|
691
|
+
cls.IntoTableBlock = class extends cls.AbstractTableBlock {
|
|
692
|
+
constructor(options) {
|
|
693
|
+
super(_extend({}, options, { prefix: "INTO", singleTable: true }));
|
|
694
|
+
}
|
|
695
|
+
into(table) {
|
|
696
|
+
this._table(table);
|
|
697
|
+
}
|
|
698
|
+
_toParamString(options = {}) {
|
|
699
|
+
if (!this._hasTable())
|
|
700
|
+
throw new Error("into() needs to be called");
|
|
701
|
+
return super._toParamString(options);
|
|
702
|
+
}
|
|
703
|
+
};
|
|
704
|
+
cls.GetFieldBlock = class extends cls.Block {
|
|
705
|
+
_fields;
|
|
706
|
+
constructor(options) {
|
|
707
|
+
super(options);
|
|
708
|
+
this._fields = [];
|
|
709
|
+
}
|
|
710
|
+
fields(_fields, options = {}) {
|
|
711
|
+
if (_isArray(_fields)) {
|
|
712
|
+
for (const field of _fields) {
|
|
713
|
+
this.field(field, null, options);
|
|
714
|
+
}
|
|
715
|
+
} else {
|
|
716
|
+
for (const field in _fields) {
|
|
717
|
+
const alias = _fields[field];
|
|
718
|
+
this.field(field, alias, options);
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
}
|
|
722
|
+
field(field, alias = null, options = {}) {
|
|
723
|
+
alias = alias ? this._sanitizeFieldAlias(alias) : alias;
|
|
724
|
+
field = this._sanitizeField(field);
|
|
725
|
+
const existingField = this._fields.filter((f) => f.name === field && f.alias === alias);
|
|
726
|
+
if (existingField.length)
|
|
727
|
+
return this;
|
|
728
|
+
this._fields.push({ name: field, alias, options });
|
|
729
|
+
return;
|
|
730
|
+
}
|
|
731
|
+
_toParamString(options = {}) {
|
|
732
|
+
const { queryBuilder, buildParameterized } = options;
|
|
733
|
+
let totalStr = "";
|
|
734
|
+
const totalValues = [];
|
|
735
|
+
for (const field of this._fields) {
|
|
736
|
+
totalStr = _pad(totalStr, ", ");
|
|
737
|
+
const { name, alias, options: fieldOptions } = field;
|
|
738
|
+
if (typeof name === "string") {
|
|
739
|
+
totalStr += this._formatFieldName(name, fieldOptions);
|
|
740
|
+
} else {
|
|
741
|
+
const ret = name._toParamString({
|
|
742
|
+
nested: true,
|
|
743
|
+
buildParameterized
|
|
744
|
+
});
|
|
745
|
+
totalStr += ret.text;
|
|
746
|
+
ret.values.forEach((v) => totalValues.push(v));
|
|
747
|
+
}
|
|
748
|
+
if (alias)
|
|
749
|
+
totalStr += ` AS ${this._formatFieldAlias(alias)}`;
|
|
750
|
+
}
|
|
751
|
+
if (!totalStr.length) {
|
|
752
|
+
const fromTableBlock = queryBuilder?.getBlock(cls.FromTableBlock);
|
|
753
|
+
if (fromTableBlock && fromTableBlock._hasTable()) {
|
|
754
|
+
totalStr = "*";
|
|
755
|
+
}
|
|
756
|
+
}
|
|
757
|
+
return { text: totalStr, values: totalValues };
|
|
758
|
+
}
|
|
759
|
+
};
|
|
760
|
+
cls.AbstractSetFieldBlock = class extends cls.Block {
|
|
761
|
+
_fields;
|
|
762
|
+
_values;
|
|
763
|
+
_valueOptions;
|
|
764
|
+
constructor(options) {
|
|
765
|
+
super(options);
|
|
766
|
+
this._fields = [];
|
|
767
|
+
this._values = [[]];
|
|
768
|
+
this._valueOptions = [[]];
|
|
769
|
+
}
|
|
770
|
+
_reset() {
|
|
771
|
+
this._fields = [];
|
|
772
|
+
this._values = [[]];
|
|
773
|
+
this._valueOptions = [[]];
|
|
774
|
+
}
|
|
775
|
+
_set(field, value, valueOptions = {}) {
|
|
776
|
+
if (this._values.length > 1) {
|
|
777
|
+
throw new Error("Cannot set multiple rows of fields this way.");
|
|
778
|
+
}
|
|
779
|
+
if (typeof value !== "undefined") {
|
|
780
|
+
value = this._sanitizeValue(value);
|
|
781
|
+
}
|
|
782
|
+
field = this._sanitizeField(field);
|
|
783
|
+
let index = this._fields.indexOf(field);
|
|
784
|
+
if (index === -1) {
|
|
785
|
+
this._fields.push(field);
|
|
786
|
+
index = this._fields.length - 1;
|
|
787
|
+
}
|
|
788
|
+
this._values[0][index] = value;
|
|
789
|
+
this._valueOptions[0][index] = valueOptions;
|
|
790
|
+
}
|
|
791
|
+
_setFields(fields, valueOptions = {}) {
|
|
792
|
+
if (typeof fields !== "object") {
|
|
793
|
+
throw new Error(`Expected an object but got ${typeof fields}`);
|
|
794
|
+
}
|
|
795
|
+
for (const field in fields) {
|
|
796
|
+
this._set(field, fields[field], valueOptions);
|
|
797
|
+
}
|
|
798
|
+
}
|
|
799
|
+
_setFieldsRows(fieldsRows, valueOptions = {}) {
|
|
800
|
+
if (!_isArray(fieldsRows)) {
|
|
801
|
+
throw new Error(`Expected an array of objects but got ${typeof fieldsRows}`);
|
|
802
|
+
}
|
|
803
|
+
this._reset();
|
|
804
|
+
for (let i = 0;fieldsRows.length > i; ++i) {
|
|
805
|
+
const fieldRow = fieldsRows[i];
|
|
806
|
+
for (let field in fieldRow) {
|
|
807
|
+
let value = fieldRow[field];
|
|
808
|
+
field = this._sanitizeField(field);
|
|
809
|
+
value = this._sanitizeValue(value);
|
|
810
|
+
let index = this._fields.indexOf(field);
|
|
811
|
+
if (i > 0 && index === -1) {
|
|
812
|
+
throw new Error("All fields in subsequent rows must match the fields in the first row");
|
|
813
|
+
}
|
|
814
|
+
if (index === -1) {
|
|
815
|
+
this._fields.push(field);
|
|
816
|
+
index = this._fields.length - 1;
|
|
817
|
+
}
|
|
818
|
+
if (!_isArray(this._values[i])) {
|
|
819
|
+
this._values[i] = [];
|
|
820
|
+
this._valueOptions[i] = [];
|
|
821
|
+
}
|
|
822
|
+
this._values[i][index] = value;
|
|
823
|
+
this._valueOptions[i][index] = valueOptions;
|
|
824
|
+
}
|
|
825
|
+
}
|
|
826
|
+
}
|
|
827
|
+
};
|
|
828
|
+
cls.SetFieldBlock = class extends cls.AbstractSetFieldBlock {
|
|
829
|
+
set(field, value, options) {
|
|
830
|
+
this._set(field, value, options);
|
|
831
|
+
}
|
|
832
|
+
setFields(fields, valueOptions) {
|
|
833
|
+
this._setFields(fields, valueOptions);
|
|
834
|
+
}
|
|
835
|
+
_toParamString(options = {}) {
|
|
836
|
+
const { buildParameterized } = options;
|
|
837
|
+
if (this._fields.length <= 0)
|
|
838
|
+
throw new Error("set() needs to be called");
|
|
839
|
+
let totalStr = "";
|
|
840
|
+
const totalValues = [];
|
|
841
|
+
for (let i = 0;i < this._fields.length; ++i) {
|
|
842
|
+
totalStr = _pad(totalStr, ", ");
|
|
843
|
+
let field = this._formatFieldName(this._fields[i]);
|
|
844
|
+
const value = this._values[0][i];
|
|
845
|
+
if (field.indexOf("=") < 0) {
|
|
846
|
+
field = `${field} = ${this.options.parameterCharacter}`;
|
|
847
|
+
}
|
|
848
|
+
const ret = this._buildString(field, [value], {
|
|
849
|
+
buildParameterized,
|
|
850
|
+
formattingOptions: this._valueOptions[0][i]
|
|
851
|
+
});
|
|
852
|
+
totalStr += ret.text;
|
|
853
|
+
ret.values.forEach((v) => totalValues.push(v));
|
|
854
|
+
}
|
|
855
|
+
return { text: `SET ${totalStr}`, values: totalValues };
|
|
856
|
+
}
|
|
857
|
+
};
|
|
858
|
+
cls.InsertFieldValueBlock = class extends cls.AbstractSetFieldBlock {
|
|
859
|
+
set(field, value, options = {}) {
|
|
860
|
+
this._set(field, value, options);
|
|
861
|
+
}
|
|
862
|
+
setFields(fields, valueOptions) {
|
|
863
|
+
this._setFields(fields, valueOptions);
|
|
864
|
+
}
|
|
865
|
+
setFieldsRows(fieldsRows, valueOptions) {
|
|
866
|
+
this._setFieldsRows(fieldsRows, valueOptions);
|
|
867
|
+
}
|
|
868
|
+
_toParamString(options = {}) {
|
|
869
|
+
const { buildParameterized } = options;
|
|
870
|
+
const fieldString = this._fields.map((f) => this._formatFieldName(f)).join(", ");
|
|
871
|
+
const valueStrings = [];
|
|
872
|
+
const totalValues = [];
|
|
873
|
+
for (let i = 0;i < this._values.length; ++i) {
|
|
874
|
+
valueStrings[i] = "";
|
|
875
|
+
for (let j = 0;j < this._values[i].length; ++j) {
|
|
876
|
+
const ret = this._buildString(this.options.parameterCharacter, [this._values[i][j]], {
|
|
877
|
+
buildParameterized,
|
|
878
|
+
formattingOptions: this._valueOptions[i][j]
|
|
879
|
+
});
|
|
880
|
+
ret.values.forEach((v) => totalValues.push(v));
|
|
881
|
+
valueStrings[i] = _pad(valueStrings[i], ", ");
|
|
882
|
+
valueStrings[i] += ret.text;
|
|
883
|
+
}
|
|
884
|
+
}
|
|
885
|
+
return {
|
|
886
|
+
text: fieldString.length ? `(${fieldString}) VALUES (${valueStrings.join("), (")})` : "",
|
|
887
|
+
values: totalValues
|
|
888
|
+
};
|
|
889
|
+
}
|
|
890
|
+
};
|
|
891
|
+
cls.InsertFieldsFromQueryBlock = class extends cls.Block {
|
|
892
|
+
_fields;
|
|
893
|
+
_query = null;
|
|
894
|
+
constructor(options) {
|
|
895
|
+
super(options);
|
|
896
|
+
this._fields = [];
|
|
897
|
+
}
|
|
898
|
+
fromQuery(fields, selectQuery) {
|
|
899
|
+
this._fields = fields.map((v) => this._sanitizeField(v));
|
|
900
|
+
this._query = this._sanitizeBaseBuilder(selectQuery);
|
|
901
|
+
}
|
|
902
|
+
_toParamString(options = {}) {
|
|
903
|
+
let totalStr = "";
|
|
904
|
+
let totalValues = [];
|
|
905
|
+
if (this._fields.length && this._query) {
|
|
906
|
+
const { text, values } = this._query._toParamString({
|
|
907
|
+
buildParameterized: options.buildParameterized,
|
|
908
|
+
nested: true
|
|
909
|
+
});
|
|
910
|
+
totalStr = `(${this._fields.join(", ")}) ${this._applyNestingFormatting(text)}`;
|
|
911
|
+
totalValues = values;
|
|
912
|
+
}
|
|
913
|
+
return { text: totalStr, values: totalValues };
|
|
914
|
+
}
|
|
915
|
+
};
|
|
916
|
+
cls.DistinctBlock = class extends cls.Block {
|
|
917
|
+
_useDistinct = false;
|
|
918
|
+
distinct() {
|
|
919
|
+
this._useDistinct = true;
|
|
920
|
+
}
|
|
921
|
+
_toParamString() {
|
|
922
|
+
return { text: this._useDistinct ? "DISTINCT" : "", values: [] };
|
|
923
|
+
}
|
|
924
|
+
};
|
|
925
|
+
cls.GroupByBlock = class extends cls.Block {
|
|
926
|
+
_groups;
|
|
927
|
+
constructor(options) {
|
|
928
|
+
super(options);
|
|
929
|
+
this._groups = [];
|
|
930
|
+
}
|
|
931
|
+
group(field) {
|
|
932
|
+
this._groups.push(this._sanitizeField(field));
|
|
933
|
+
}
|
|
934
|
+
_toParamString(_options = {}) {
|
|
935
|
+
return {
|
|
936
|
+
text: this._groups.length ? `GROUP BY ${this._groups.join(", ")}` : "",
|
|
937
|
+
values: []
|
|
938
|
+
};
|
|
939
|
+
}
|
|
940
|
+
};
|
|
941
|
+
cls.AbstractVerbSingleValueBlock = class extends cls.Block {
|
|
942
|
+
_value = null;
|
|
943
|
+
constructor(options) {
|
|
944
|
+
super(options);
|
|
945
|
+
}
|
|
946
|
+
_setValue(value) {
|
|
947
|
+
this._value = value !== null ? this._sanitizeLimitOffset(value) : value;
|
|
948
|
+
}
|
|
949
|
+
_toParamString(options = {}) {
|
|
950
|
+
const expr = this._value !== null ? `${this.options.verb} ${this.options.parameterCharacter}` : "";
|
|
951
|
+
const values = this._value !== null ? [this._value] : [];
|
|
952
|
+
return this._buildString(expr, values, options);
|
|
953
|
+
}
|
|
954
|
+
};
|
|
955
|
+
cls.OffsetBlock = class extends cls.AbstractVerbSingleValueBlock {
|
|
956
|
+
constructor(options) {
|
|
957
|
+
super(_extend({}, options, { verb: "OFFSET" }));
|
|
958
|
+
}
|
|
959
|
+
offset(start) {
|
|
960
|
+
this._setValue(start);
|
|
961
|
+
}
|
|
962
|
+
};
|
|
963
|
+
cls.LimitBlock = class extends cls.AbstractVerbSingleValueBlock {
|
|
964
|
+
constructor(options) {
|
|
965
|
+
super(_extend({}, options, { verb: "LIMIT" }));
|
|
966
|
+
}
|
|
967
|
+
limit(limit) {
|
|
968
|
+
this._setValue(limit);
|
|
969
|
+
}
|
|
970
|
+
};
|
|
971
|
+
cls.AbstractConditionBlock = class extends cls.Block {
|
|
972
|
+
_conditions;
|
|
973
|
+
constructor(options) {
|
|
974
|
+
super(options);
|
|
975
|
+
this._conditions = [];
|
|
976
|
+
}
|
|
977
|
+
_condition(condition, ...values) {
|
|
978
|
+
condition = this._sanitizeExpression(condition);
|
|
979
|
+
this._conditions.push({ expr: condition, values: values || [] });
|
|
980
|
+
}
|
|
981
|
+
_toParamString(options = {}) {
|
|
982
|
+
const parts = [];
|
|
983
|
+
const totalValues = [];
|
|
984
|
+
for (const { expr, values } of this._conditions) {
|
|
985
|
+
const ret = cls.isSquelBuilder(expr) ? expr._toParamString({
|
|
986
|
+
buildParameterized: options.buildParameterized
|
|
987
|
+
}) : this._buildString(expr, values, {
|
|
988
|
+
buildParameterized: options.buildParameterized
|
|
989
|
+
});
|
|
990
|
+
if (ret.text.length)
|
|
991
|
+
parts.push(ret.text);
|
|
992
|
+
ret.values.forEach((v) => totalValues.push(v));
|
|
993
|
+
}
|
|
994
|
+
const totalStr = parts.join(") AND (");
|
|
995
|
+
return {
|
|
996
|
+
text: totalStr.length ? `${this.options.verb} (${totalStr})` : "",
|
|
997
|
+
values: totalValues
|
|
998
|
+
};
|
|
999
|
+
}
|
|
1000
|
+
};
|
|
1001
|
+
cls.WhereBlock = class extends cls.AbstractConditionBlock {
|
|
1002
|
+
constructor(options) {
|
|
1003
|
+
super(_extend({}, options, { verb: "WHERE" }));
|
|
1004
|
+
}
|
|
1005
|
+
where(condition, ...values) {
|
|
1006
|
+
this._condition(condition, ...values);
|
|
1007
|
+
}
|
|
1008
|
+
};
|
|
1009
|
+
cls.HavingBlock = class extends cls.AbstractConditionBlock {
|
|
1010
|
+
constructor(options) {
|
|
1011
|
+
super(_extend({}, options, { verb: "HAVING" }));
|
|
1012
|
+
}
|
|
1013
|
+
having(condition, ...values) {
|
|
1014
|
+
this._condition(condition, ...values);
|
|
1015
|
+
}
|
|
1016
|
+
};
|
|
1017
|
+
cls.OrderByBlock = class extends cls.Block {
|
|
1018
|
+
_orders;
|
|
1019
|
+
constructor(options) {
|
|
1020
|
+
super(options);
|
|
1021
|
+
this._orders = [];
|
|
1022
|
+
}
|
|
1023
|
+
order(field, dir, ...values) {
|
|
1024
|
+
field = this._sanitizeField(field);
|
|
1025
|
+
let direction;
|
|
1026
|
+
if (typeof dir === "string") {
|
|
1027
|
+
direction = dir;
|
|
1028
|
+
} else if (dir === undefined) {
|
|
1029
|
+
direction = "ASC";
|
|
1030
|
+
} else if (dir === null) {
|
|
1031
|
+
direction = null;
|
|
1032
|
+
} else {
|
|
1033
|
+
direction = dir ? "ASC" : "DESC";
|
|
1034
|
+
}
|
|
1035
|
+
this._orders.push({ field, dir: direction, values: values || [] });
|
|
1036
|
+
}
|
|
1037
|
+
_toParamString(options = {}) {
|
|
1038
|
+
let totalStr = "";
|
|
1039
|
+
const totalValues = [];
|
|
1040
|
+
for (const { field, dir, values } of this._orders) {
|
|
1041
|
+
totalStr = _pad(totalStr, ", ");
|
|
1042
|
+
const ret = this._buildString(field, values, {
|
|
1043
|
+
buildParameterized: options.buildParameterized
|
|
1044
|
+
});
|
|
1045
|
+
totalStr += ret.text;
|
|
1046
|
+
if (_isArray(ret.values)) {
|
|
1047
|
+
ret.values.forEach((v) => totalValues.push(v));
|
|
1048
|
+
}
|
|
1049
|
+
if (dir !== null)
|
|
1050
|
+
totalStr += ` ${dir}`;
|
|
1051
|
+
}
|
|
1052
|
+
return {
|
|
1053
|
+
text: totalStr.length ? `ORDER BY ${totalStr}` : "",
|
|
1054
|
+
values: totalValues
|
|
1055
|
+
};
|
|
1056
|
+
}
|
|
1057
|
+
};
|
|
1058
|
+
cls.JoinBlock = class extends cls.Block {
|
|
1059
|
+
_joins;
|
|
1060
|
+
constructor(options) {
|
|
1061
|
+
super(options);
|
|
1062
|
+
this._joins = [];
|
|
1063
|
+
}
|
|
1064
|
+
join(table, alias = null, condition = null, type = "INNER") {
|
|
1065
|
+
table = this._sanitizeTable(table, true);
|
|
1066
|
+
alias = alias ? this._sanitizeTableAlias(alias) : alias;
|
|
1067
|
+
condition = condition ? this._sanitizeExpression(condition) : condition;
|
|
1068
|
+
this._joins.push({ type, table, alias, condition });
|
|
1069
|
+
}
|
|
1070
|
+
left_join(table, alias = null, condition = null) {
|
|
1071
|
+
this.join(table, alias, condition, "LEFT");
|
|
1072
|
+
}
|
|
1073
|
+
right_join(table, alias = null, condition = null) {
|
|
1074
|
+
this.join(table, alias, condition, "RIGHT");
|
|
1075
|
+
}
|
|
1076
|
+
outer_join(table, alias = null, condition = null) {
|
|
1077
|
+
this.join(table, alias, condition, "OUTER");
|
|
1078
|
+
}
|
|
1079
|
+
left_outer_join(table, alias = null, condition = null) {
|
|
1080
|
+
this.join(table, alias, condition, "LEFT OUTER");
|
|
1081
|
+
}
|
|
1082
|
+
full_join(table, alias = null, condition = null) {
|
|
1083
|
+
this.join(table, alias, condition, "FULL");
|
|
1084
|
+
}
|
|
1085
|
+
cross_join(table, alias = null, condition = null) {
|
|
1086
|
+
this.join(table, alias, condition, "CROSS");
|
|
1087
|
+
}
|
|
1088
|
+
_toParamString(options = {}) {
|
|
1089
|
+
let totalStr = "";
|
|
1090
|
+
const totalValues = [];
|
|
1091
|
+
for (const { type, table, alias, condition } of this._joins) {
|
|
1092
|
+
totalStr = _pad(totalStr, this.options.separator);
|
|
1093
|
+
let tableStr;
|
|
1094
|
+
if (cls.isSquelBuilder(table)) {
|
|
1095
|
+
const ret = table._toParamString({
|
|
1096
|
+
buildParameterized: options.buildParameterized,
|
|
1097
|
+
nested: true
|
|
1098
|
+
});
|
|
1099
|
+
ret.values.forEach((v) => totalValues.push(v));
|
|
1100
|
+
tableStr = ret.text;
|
|
1101
|
+
} else {
|
|
1102
|
+
tableStr = this._formatTableName(table);
|
|
1103
|
+
}
|
|
1104
|
+
totalStr += `${type} JOIN ${tableStr}`;
|
|
1105
|
+
if (alias)
|
|
1106
|
+
totalStr += ` ${this._formatTableAlias(alias)}`;
|
|
1107
|
+
if (condition) {
|
|
1108
|
+
totalStr += " ON ";
|
|
1109
|
+
let ret;
|
|
1110
|
+
if (cls.isSquelBuilder(condition)) {
|
|
1111
|
+
ret = condition._toParamString({
|
|
1112
|
+
buildParameterized: options.buildParameterized
|
|
1113
|
+
});
|
|
1114
|
+
} else {
|
|
1115
|
+
ret = this._buildString(condition, [], {
|
|
1116
|
+
buildParameterized: options.buildParameterized
|
|
1117
|
+
});
|
|
1118
|
+
}
|
|
1119
|
+
totalStr += this._applyNestingFormatting(ret.text);
|
|
1120
|
+
ret.values.forEach((v) => totalValues.push(v));
|
|
1121
|
+
}
|
|
1122
|
+
}
|
|
1123
|
+
return { text: totalStr, values: totalValues };
|
|
1124
|
+
}
|
|
1125
|
+
};
|
|
1126
|
+
cls.UnionBlock = class extends cls.Block {
|
|
1127
|
+
_unions;
|
|
1128
|
+
constructor(options) {
|
|
1129
|
+
super(options);
|
|
1130
|
+
this._unions = [];
|
|
1131
|
+
}
|
|
1132
|
+
union(table, type = "UNION") {
|
|
1133
|
+
table = this._sanitizeTable(table);
|
|
1134
|
+
this._unions.push({ type, table });
|
|
1135
|
+
}
|
|
1136
|
+
union_all(table) {
|
|
1137
|
+
this.union(table, "UNION ALL");
|
|
1138
|
+
}
|
|
1139
|
+
_toParamString(options = {}) {
|
|
1140
|
+
let totalStr = "";
|
|
1141
|
+
const totalValues = [];
|
|
1142
|
+
for (const { type, table } of this._unions) {
|
|
1143
|
+
totalStr = _pad(totalStr, this.options.separator);
|
|
1144
|
+
let tableStr;
|
|
1145
|
+
if (table instanceof cls.BaseBuilder) {
|
|
1146
|
+
const ret = table._toParamString({
|
|
1147
|
+
buildParameterized: options.buildParameterized,
|
|
1148
|
+
nested: true
|
|
1149
|
+
});
|
|
1150
|
+
tableStr = ret.text;
|
|
1151
|
+
ret.values.forEach((v) => totalValues.push(v));
|
|
1152
|
+
} else {
|
|
1153
|
+
totalStr = this._formatTableName(table);
|
|
1154
|
+
tableStr = "";
|
|
1155
|
+
}
|
|
1156
|
+
totalStr += `${type} ${tableStr}`;
|
|
1157
|
+
}
|
|
1158
|
+
return { text: totalStr, values: totalValues };
|
|
1159
|
+
}
|
|
1160
|
+
};
|
|
1161
|
+
cls.QueryBuilder = class extends cls.BaseBuilder {
|
|
1162
|
+
blocks;
|
|
1163
|
+
constructor(options, blocks) {
|
|
1164
|
+
super(options);
|
|
1165
|
+
this.blocks = blocks || [];
|
|
1166
|
+
for (const block of this.blocks) {
|
|
1167
|
+
const exposedMethods = block.exposedMethods();
|
|
1168
|
+
for (const methodName in exposedMethods) {
|
|
1169
|
+
const methodBody = exposedMethods[methodName];
|
|
1170
|
+
if (this[methodName] !== undefined) {
|
|
1171
|
+
throw new Error(`Builder already has a builder method called: ${methodName}`);
|
|
1172
|
+
}
|
|
1173
|
+
((b, name, body) => {
|
|
1174
|
+
this[name] = (...args) => {
|
|
1175
|
+
body.call(b, ...args);
|
|
1176
|
+
return this;
|
|
1177
|
+
};
|
|
1178
|
+
})(block, methodName, methodBody);
|
|
1179
|
+
}
|
|
1180
|
+
}
|
|
1181
|
+
}
|
|
1182
|
+
registerValueHandler(type, handler) {
|
|
1183
|
+
for (const block of this.blocks) {
|
|
1184
|
+
block.registerValueHandler(type, handler);
|
|
1185
|
+
}
|
|
1186
|
+
super.registerValueHandler(type, handler);
|
|
1187
|
+
return this;
|
|
1188
|
+
}
|
|
1189
|
+
updateOptions(options) {
|
|
1190
|
+
this.options = _extend(this.options, options);
|
|
1191
|
+
for (const block of this.blocks) {
|
|
1192
|
+
block.options = _extend(block.options, options);
|
|
1193
|
+
}
|
|
1194
|
+
}
|
|
1195
|
+
_toParamString(options = {}) {
|
|
1196
|
+
const opts = _extend({}, this.options, options);
|
|
1197
|
+
const blockResults = this.blocks.map((b) => b._toParamString({
|
|
1198
|
+
buildParameterized: opts.buildParameterized,
|
|
1199
|
+
queryBuilder: this
|
|
1200
|
+
}));
|
|
1201
|
+
const blockTexts = blockResults.map((b) => b.text);
|
|
1202
|
+
const blockValues = blockResults.map((b) => b.values);
|
|
1203
|
+
let totalStr = blockTexts.filter((v) => v.length > 0).join(opts.separator);
|
|
1204
|
+
const totalValues = [];
|
|
1205
|
+
blockValues.forEach((block) => block.forEach((value) => totalValues.push(value)));
|
|
1206
|
+
if (!opts.nested) {
|
|
1207
|
+
if (opts.numberedParameters) {
|
|
1208
|
+
let i = opts.numberedParametersStartAt !== undefined ? opts.numberedParametersStartAt : 1;
|
|
1209
|
+
const regex = opts.parameterCharacter.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
|
|
1210
|
+
totalStr = totalStr.replace(new RegExp(regex, "g"), () => {
|
|
1211
|
+
return `${opts.numberedParametersPrefix}${i++}`;
|
|
1212
|
+
});
|
|
1213
|
+
}
|
|
1214
|
+
}
|
|
1215
|
+
return {
|
|
1216
|
+
text: this._applyNestingFormatting(totalStr, !!opts.nested),
|
|
1217
|
+
values: totalValues
|
|
1218
|
+
};
|
|
1219
|
+
}
|
|
1220
|
+
clone() {
|
|
1221
|
+
const blockClones = this.blocks.map((v) => v.clone());
|
|
1222
|
+
return new this.constructor(this.options, blockClones);
|
|
1223
|
+
}
|
|
1224
|
+
getBlock(blockType) {
|
|
1225
|
+
return this.blocks.filter((b) => b instanceof blockType)[0];
|
|
1226
|
+
}
|
|
1227
|
+
};
|
|
1228
|
+
cls.Select = class extends cls.QueryBuilder {
|
|
1229
|
+
constructor(options, blocks = null) {
|
|
1230
|
+
blocks = blocks || [
|
|
1231
|
+
new cls.StringBlock(options, "SELECT"),
|
|
1232
|
+
new cls.FunctionBlock(options),
|
|
1233
|
+
new cls.DistinctBlock(options),
|
|
1234
|
+
new cls.GetFieldBlock(options),
|
|
1235
|
+
new cls.FromTableBlock(options),
|
|
1236
|
+
new cls.JoinBlock(options),
|
|
1237
|
+
new cls.WhereBlock(options),
|
|
1238
|
+
new cls.GroupByBlock(options),
|
|
1239
|
+
new cls.HavingBlock(options),
|
|
1240
|
+
new cls.OrderByBlock(options),
|
|
1241
|
+
new cls.LimitBlock(options),
|
|
1242
|
+
new cls.OffsetBlock(options),
|
|
1243
|
+
new cls.UnionBlock(options)
|
|
1244
|
+
];
|
|
1245
|
+
super(options, blocks);
|
|
1246
|
+
}
|
|
1247
|
+
};
|
|
1248
|
+
cls.Update = class extends cls.QueryBuilder {
|
|
1249
|
+
constructor(options, blocks = null) {
|
|
1250
|
+
blocks = blocks || [
|
|
1251
|
+
new cls.StringBlock(options, "UPDATE"),
|
|
1252
|
+
new cls.UpdateTableBlock(options),
|
|
1253
|
+
new cls.SetFieldBlock(options),
|
|
1254
|
+
new cls.WhereBlock(options),
|
|
1255
|
+
new cls.OrderByBlock(options),
|
|
1256
|
+
new cls.LimitBlock(options)
|
|
1257
|
+
];
|
|
1258
|
+
super(options, blocks);
|
|
1259
|
+
}
|
|
1260
|
+
};
|
|
1261
|
+
cls.Delete = class extends cls.QueryBuilder {
|
|
1262
|
+
constructor(options, blocks = null) {
|
|
1263
|
+
blocks = blocks || [
|
|
1264
|
+
new cls.StringBlock(options, "DELETE"),
|
|
1265
|
+
new cls.TargetTableBlock(options),
|
|
1266
|
+
new cls.FromTableBlock(_extend({}, options, { singleTable: true })),
|
|
1267
|
+
new cls.JoinBlock(options),
|
|
1268
|
+
new cls.WhereBlock(options),
|
|
1269
|
+
new cls.OrderByBlock(options),
|
|
1270
|
+
new cls.LimitBlock(options)
|
|
1271
|
+
];
|
|
1272
|
+
super(options, blocks);
|
|
1273
|
+
}
|
|
1274
|
+
};
|
|
1275
|
+
cls.Insert = class extends cls.QueryBuilder {
|
|
1276
|
+
constructor(options, blocks = null) {
|
|
1277
|
+
blocks = blocks || [
|
|
1278
|
+
new cls.StringBlock(options, "INSERT"),
|
|
1279
|
+
new cls.IntoTableBlock(options),
|
|
1280
|
+
new cls.InsertFieldValueBlock(options),
|
|
1281
|
+
new cls.InsertFieldsFromQueryBlock(options)
|
|
1282
|
+
];
|
|
1283
|
+
super(options, blocks);
|
|
1284
|
+
}
|
|
1285
|
+
};
|
|
1286
|
+
const _squel = {
|
|
1287
|
+
VERSION: package_default.version,
|
|
1288
|
+
flavour,
|
|
1289
|
+
expr: (options) => new cls.Expression(options),
|
|
1290
|
+
case: (name, options) => new cls.Case(name, options),
|
|
1291
|
+
select: (options, blocks) => new cls.Select(options, blocks),
|
|
1292
|
+
update: (options, blocks) => new cls.Update(options, blocks),
|
|
1293
|
+
insert: (options, blocks) => new cls.Insert(options, blocks),
|
|
1294
|
+
delete: (options, blocks) => new cls.Delete(options, blocks),
|
|
1295
|
+
str: (...args) => {
|
|
1296
|
+
const inst = new cls.FunctionBlock;
|
|
1297
|
+
inst.function(...args);
|
|
1298
|
+
return inst;
|
|
1299
|
+
},
|
|
1300
|
+
rstr: (...args) => {
|
|
1301
|
+
const inst = new cls.FunctionBlock({ rawNesting: true });
|
|
1302
|
+
inst.function(...args);
|
|
1303
|
+
return inst;
|
|
1304
|
+
},
|
|
1305
|
+
registerValueHandler: cls.registerValueHandler
|
|
1306
|
+
};
|
|
1307
|
+
_squel.remove = _squel.delete;
|
|
1308
|
+
_squel.cls = cls;
|
|
1309
|
+
return _squel;
|
|
1310
|
+
}
|
|
1311
|
+
var squel = _buildSquel();
|
|
1312
|
+
squel.flavours = {};
|
|
1313
|
+
squel.useFlavour = function useFlavour(f = null) {
|
|
1314
|
+
if (!f)
|
|
1315
|
+
return squel;
|
|
1316
|
+
if (squel.flavours[f] instanceof Function) {
|
|
1317
|
+
const s = _buildSquel(f);
|
|
1318
|
+
squel.flavours[f].call(null, s);
|
|
1319
|
+
s.flavours = squel.flavours;
|
|
1320
|
+
s.useFlavour = squel.useFlavour;
|
|
1321
|
+
return s;
|
|
1322
|
+
}
|
|
1323
|
+
throw new Error(`Flavour not available: ${f}`);
|
|
1324
|
+
};
|
|
1325
|
+
var core_default = squel;
|
|
1326
|
+
|
|
1327
|
+
// src/mysql.ts
|
|
1328
|
+
squel.flavours.mysql = (_squel) => {
|
|
1329
|
+
const cls = _squel.cls;
|
|
1330
|
+
cls.MysqlOnDuplicateKeyUpdateBlock = class extends cls.AbstractSetFieldBlock {
|
|
1331
|
+
onDupUpdate(field, value, options) {
|
|
1332
|
+
this._set(field, value, options);
|
|
1333
|
+
}
|
|
1334
|
+
_toParamString(options = {}) {
|
|
1335
|
+
let totalStr = "";
|
|
1336
|
+
const totalValues = [];
|
|
1337
|
+
for (let i = 0;i < this._fields.length; ++i) {
|
|
1338
|
+
totalStr = _pad(totalStr, ", ");
|
|
1339
|
+
const field = this._fields[i];
|
|
1340
|
+
const value = this._values[0][i];
|
|
1341
|
+
const valueOptions = this._valueOptions[0][i];
|
|
1342
|
+
if (typeof value === "undefined") {
|
|
1343
|
+
totalStr += field;
|
|
1344
|
+
} else {
|
|
1345
|
+
const ret = this._buildString(`${field} = ${this.options.parameterCharacter}`, [value], {
|
|
1346
|
+
buildParameterized: options.buildParameterized,
|
|
1347
|
+
formattingOptions: valueOptions
|
|
1348
|
+
});
|
|
1349
|
+
totalStr += ret.text;
|
|
1350
|
+
ret.values.forEach((v) => totalValues.push(v));
|
|
1351
|
+
}
|
|
1352
|
+
}
|
|
1353
|
+
return {
|
|
1354
|
+
text: !totalStr.length ? "" : `ON DUPLICATE KEY UPDATE ${totalStr}`,
|
|
1355
|
+
values: totalValues
|
|
1356
|
+
};
|
|
1357
|
+
}
|
|
1358
|
+
};
|
|
1359
|
+
cls.Insert = class extends cls.QueryBuilder {
|
|
1360
|
+
constructor(options, blocks = null) {
|
|
1361
|
+
blocks = blocks || [
|
|
1362
|
+
new cls.StringBlock(options, "INSERT"),
|
|
1363
|
+
new cls.IntoTableBlock(options),
|
|
1364
|
+
new cls.InsertFieldValueBlock(options),
|
|
1365
|
+
new cls.InsertFieldsFromQueryBlock(options),
|
|
1366
|
+
new cls.MysqlOnDuplicateKeyUpdateBlock(options)
|
|
1367
|
+
];
|
|
1368
|
+
super(options, blocks);
|
|
1369
|
+
}
|
|
1370
|
+
};
|
|
1371
|
+
cls.Replace = class extends cls.QueryBuilder {
|
|
1372
|
+
constructor(options, blocks = null) {
|
|
1373
|
+
blocks = blocks || [
|
|
1374
|
+
new cls.StringBlock(options, "REPLACE"),
|
|
1375
|
+
new cls.IntoTableBlock(options),
|
|
1376
|
+
new cls.InsertFieldValueBlock(options),
|
|
1377
|
+
new cls.InsertFieldsFromQueryBlock(options)
|
|
1378
|
+
];
|
|
1379
|
+
super(options, blocks);
|
|
1380
|
+
}
|
|
1381
|
+
};
|
|
1382
|
+
_squel.replace = (options, blocks) => new cls.Replace(options, blocks);
|
|
1383
|
+
};
|
|
1384
|
+
|
|
1385
|
+
// src/postgres.ts
|
|
1386
|
+
squel.flavours.postgres = (_squel) => {
|
|
1387
|
+
const cls = _squel.cls;
|
|
1388
|
+
cls.DefaultQueryBuilderOptions.numberedParameters = true;
|
|
1389
|
+
cls.DefaultQueryBuilderOptions.numberedParametersStartAt = 1;
|
|
1390
|
+
cls.DefaultQueryBuilderOptions.autoQuoteAliasNames = false;
|
|
1391
|
+
cls.DefaultQueryBuilderOptions.useAsForTableAliasNames = true;
|
|
1392
|
+
cls.PostgresOnConflictKeyUpdateBlock = class extends cls.AbstractSetFieldBlock {
|
|
1393
|
+
_onConflict;
|
|
1394
|
+
_dupFields;
|
|
1395
|
+
constructor(options) {
|
|
1396
|
+
super(options);
|
|
1397
|
+
this._onConflict = false;
|
|
1398
|
+
this._dupFields = [];
|
|
1399
|
+
}
|
|
1400
|
+
onConflict(conflictFields, fields) {
|
|
1401
|
+
this._onConflict = true;
|
|
1402
|
+
if (!conflictFields)
|
|
1403
|
+
return;
|
|
1404
|
+
if (!_isArray(conflictFields)) {
|
|
1405
|
+
conflictFields = [conflictFields];
|
|
1406
|
+
}
|
|
1407
|
+
this._dupFields = conflictFields.map(this._sanitizeField.bind(this));
|
|
1408
|
+
if (fields) {
|
|
1409
|
+
Object.keys(fields).forEach((key) => {
|
|
1410
|
+
this._set(key, fields[key]);
|
|
1411
|
+
});
|
|
1412
|
+
}
|
|
1413
|
+
}
|
|
1414
|
+
_toParamString(options = {}) {
|
|
1415
|
+
let totalStr = "";
|
|
1416
|
+
const totalValues = [];
|
|
1417
|
+
for (let i = 0;i < this._fields.length; ++i) {
|
|
1418
|
+
totalStr = _pad(totalStr, ", ");
|
|
1419
|
+
const field = this._fields[i];
|
|
1420
|
+
const value = this._values[0][i];
|
|
1421
|
+
const valueOptions = this._valueOptions[0][i];
|
|
1422
|
+
if (typeof value === "undefined") {
|
|
1423
|
+
totalStr += field;
|
|
1424
|
+
} else {
|
|
1425
|
+
const ret = this._buildString(`${field} = ${this.options.parameterCharacter}`, [value], {
|
|
1426
|
+
buildParameterized: options.buildParameterized,
|
|
1427
|
+
formattingOptions: valueOptions
|
|
1428
|
+
});
|
|
1429
|
+
totalStr += ret.text;
|
|
1430
|
+
ret.values.forEach((v) => totalValues.push(v));
|
|
1431
|
+
}
|
|
1432
|
+
}
|
|
1433
|
+
const returned = { text: "", values: totalValues };
|
|
1434
|
+
if (this._onConflict) {
|
|
1435
|
+
const conflictFields = this._dupFields.length ? `(${this._dupFields.join(", ")}) ` : "";
|
|
1436
|
+
const action = totalStr.length ? `UPDATE SET ${totalStr}` : "NOTHING";
|
|
1437
|
+
returned.text = `ON CONFLICT ${conflictFields}DO ${action}`;
|
|
1438
|
+
}
|
|
1439
|
+
return returned;
|
|
1440
|
+
}
|
|
1441
|
+
};
|
|
1442
|
+
cls.ReturningBlock = class extends cls.Block {
|
|
1443
|
+
_fields;
|
|
1444
|
+
constructor(options) {
|
|
1445
|
+
super(options);
|
|
1446
|
+
this._fields = [];
|
|
1447
|
+
}
|
|
1448
|
+
returning(field, alias = null, options = {}) {
|
|
1449
|
+
alias = alias ? this._sanitizeFieldAlias(alias) : alias;
|
|
1450
|
+
field = this._sanitizeField(field);
|
|
1451
|
+
const existingField = this._fields.filter((f) => f.name === field && f.alias === alias);
|
|
1452
|
+
if (existingField.length)
|
|
1453
|
+
return this;
|
|
1454
|
+
this._fields.push({ name: field, alias, options });
|
|
1455
|
+
}
|
|
1456
|
+
_toParamString(options = {}) {
|
|
1457
|
+
const { buildParameterized } = options;
|
|
1458
|
+
let totalStr = "";
|
|
1459
|
+
const totalValues = [];
|
|
1460
|
+
for (const field of this._fields) {
|
|
1461
|
+
totalStr = _pad(totalStr, ", ");
|
|
1462
|
+
const { name, alias, options: fieldOptions } = field;
|
|
1463
|
+
if (typeof name === "string") {
|
|
1464
|
+
totalStr += this._formatFieldName(name, fieldOptions);
|
|
1465
|
+
} else {
|
|
1466
|
+
const ret = name._toParamString({ nested: true, buildParameterized });
|
|
1467
|
+
totalStr += ret.text;
|
|
1468
|
+
ret.values.forEach((v) => totalValues.push(v));
|
|
1469
|
+
}
|
|
1470
|
+
if (alias)
|
|
1471
|
+
totalStr += ` AS ${this._formatFieldAlias(alias)}`;
|
|
1472
|
+
}
|
|
1473
|
+
return {
|
|
1474
|
+
text: totalStr.length > 0 ? `RETURNING ${totalStr}` : "",
|
|
1475
|
+
values: totalValues
|
|
1476
|
+
};
|
|
1477
|
+
}
|
|
1478
|
+
};
|
|
1479
|
+
cls.WithBlock = class extends cls.Block {
|
|
1480
|
+
_tables;
|
|
1481
|
+
constructor(options) {
|
|
1482
|
+
super(options);
|
|
1483
|
+
this._tables = [];
|
|
1484
|
+
}
|
|
1485
|
+
with(alias, table) {
|
|
1486
|
+
this._tables.push({ alias, table });
|
|
1487
|
+
}
|
|
1488
|
+
_toParamString(options = {}) {
|
|
1489
|
+
const parts = [];
|
|
1490
|
+
const values = [];
|
|
1491
|
+
for (const { alias, table } of this._tables) {
|
|
1492
|
+
const ret = table._toParamString({
|
|
1493
|
+
buildParameterized: options.buildParameterized,
|
|
1494
|
+
nested: true
|
|
1495
|
+
});
|
|
1496
|
+
parts.push(`${alias} AS ${ret.text}`);
|
|
1497
|
+
ret.values.forEach((v) => values.push(v));
|
|
1498
|
+
}
|
|
1499
|
+
return {
|
|
1500
|
+
text: parts.length ? `WITH ${parts.join(", ")}` : "",
|
|
1501
|
+
values
|
|
1502
|
+
};
|
|
1503
|
+
}
|
|
1504
|
+
};
|
|
1505
|
+
cls.DistinctOnBlock = class extends cls.Block {
|
|
1506
|
+
_useDistinct = false;
|
|
1507
|
+
_distinctFields;
|
|
1508
|
+
constructor(options) {
|
|
1509
|
+
super(options);
|
|
1510
|
+
this._distinctFields = [];
|
|
1511
|
+
}
|
|
1512
|
+
distinct(...fields) {
|
|
1513
|
+
this._useDistinct = true;
|
|
1514
|
+
fields.forEach((field) => {
|
|
1515
|
+
this._distinctFields.push(this._sanitizeField(field));
|
|
1516
|
+
});
|
|
1517
|
+
}
|
|
1518
|
+
_toParamString() {
|
|
1519
|
+
let text = "";
|
|
1520
|
+
if (this._useDistinct) {
|
|
1521
|
+
text = "DISTINCT";
|
|
1522
|
+
if (this._distinctFields.length) {
|
|
1523
|
+
text += ` ON (${this._distinctFields.join(", ")})`;
|
|
1524
|
+
}
|
|
1525
|
+
}
|
|
1526
|
+
return { text, values: [] };
|
|
1527
|
+
}
|
|
1528
|
+
};
|
|
1529
|
+
cls.Select = class extends cls.QueryBuilder {
|
|
1530
|
+
constructor(options, blocks = null) {
|
|
1531
|
+
blocks = blocks || [
|
|
1532
|
+
new cls.WithBlock(options),
|
|
1533
|
+
new cls.StringBlock(options, "SELECT"),
|
|
1534
|
+
new cls.FunctionBlock(options),
|
|
1535
|
+
new cls.DistinctOnBlock(options),
|
|
1536
|
+
new cls.GetFieldBlock(options),
|
|
1537
|
+
new cls.FromTableBlock(options),
|
|
1538
|
+
new cls.JoinBlock(options),
|
|
1539
|
+
new cls.WhereBlock(options),
|
|
1540
|
+
new cls.GroupByBlock(options),
|
|
1541
|
+
new cls.HavingBlock(options),
|
|
1542
|
+
new cls.OrderByBlock(options),
|
|
1543
|
+
new cls.LimitBlock(options),
|
|
1544
|
+
new cls.OffsetBlock(options),
|
|
1545
|
+
new cls.UnionBlock(options)
|
|
1546
|
+
];
|
|
1547
|
+
super(options, blocks);
|
|
1548
|
+
}
|
|
1549
|
+
};
|
|
1550
|
+
cls.Insert = class extends cls.QueryBuilder {
|
|
1551
|
+
constructor(options, blocks = null) {
|
|
1552
|
+
blocks = blocks || [
|
|
1553
|
+
new cls.WithBlock(options),
|
|
1554
|
+
new cls.StringBlock(options, "INSERT"),
|
|
1555
|
+
new cls.IntoTableBlock(options),
|
|
1556
|
+
new cls.InsertFieldValueBlock(options),
|
|
1557
|
+
new cls.InsertFieldsFromQueryBlock(options),
|
|
1558
|
+
new cls.PostgresOnConflictKeyUpdateBlock(options),
|
|
1559
|
+
new cls.ReturningBlock(options)
|
|
1560
|
+
];
|
|
1561
|
+
super(options, blocks);
|
|
1562
|
+
}
|
|
1563
|
+
};
|
|
1564
|
+
cls.Update = class extends cls.QueryBuilder {
|
|
1565
|
+
constructor(options, blocks = null) {
|
|
1566
|
+
blocks = blocks || [
|
|
1567
|
+
new cls.WithBlock(options),
|
|
1568
|
+
new cls.StringBlock(options, "UPDATE"),
|
|
1569
|
+
new cls.UpdateTableBlock(options),
|
|
1570
|
+
new cls.SetFieldBlock(options),
|
|
1571
|
+
new cls.FromTableBlock(options),
|
|
1572
|
+
new cls.WhereBlock(options),
|
|
1573
|
+
new cls.OrderByBlock(options),
|
|
1574
|
+
new cls.LimitBlock(options),
|
|
1575
|
+
new cls.ReturningBlock(options)
|
|
1576
|
+
];
|
|
1577
|
+
super(options, blocks);
|
|
1578
|
+
}
|
|
1579
|
+
};
|
|
1580
|
+
cls.Delete = class extends cls.QueryBuilder {
|
|
1581
|
+
constructor(options, blocks = null) {
|
|
1582
|
+
blocks = blocks || [
|
|
1583
|
+
new cls.WithBlock(options),
|
|
1584
|
+
new cls.StringBlock(options, "DELETE"),
|
|
1585
|
+
new cls.TargetTableBlock(options),
|
|
1586
|
+
new cls.FromTableBlock({ ...options, singleTable: true }),
|
|
1587
|
+
new cls.JoinBlock(options),
|
|
1588
|
+
new cls.WhereBlock(options),
|
|
1589
|
+
new cls.OrderByBlock(options),
|
|
1590
|
+
new cls.LimitBlock(options),
|
|
1591
|
+
new cls.ReturningBlock(options)
|
|
1592
|
+
];
|
|
1593
|
+
super(options, blocks);
|
|
1594
|
+
}
|
|
1595
|
+
};
|
|
1596
|
+
};
|
|
1597
|
+
|
|
1598
|
+
// src/mssql.ts
|
|
1599
|
+
squel.flavours.mssql = (_squel) => {
|
|
1600
|
+
const cls = _squel.cls;
|
|
1601
|
+
cls.DefaultQueryBuilderOptions.replaceSingleQuotes = true;
|
|
1602
|
+
cls.DefaultQueryBuilderOptions.autoQuoteAliasNames = false;
|
|
1603
|
+
cls.DefaultQueryBuilderOptions.numberedParametersPrefix = "@";
|
|
1604
|
+
_squel.registerValueHandler(Date, (value) => {
|
|
1605
|
+
const date = value;
|
|
1606
|
+
return `'${date.getUTCFullYear()}-${date.getUTCMonth() + 1}-${date.getUTCDate()} ${date.getUTCHours()}:${date.getUTCMinutes()}:${date.getUTCSeconds()}'`;
|
|
1607
|
+
});
|
|
1608
|
+
cls.MssqlLimitOffsetTopBlock = class extends cls.Block {
|
|
1609
|
+
_limits;
|
|
1610
|
+
_offsets;
|
|
1611
|
+
ParentBlock;
|
|
1612
|
+
LimitBlock;
|
|
1613
|
+
TopBlock;
|
|
1614
|
+
OffsetBlock;
|
|
1615
|
+
constructor(options) {
|
|
1616
|
+
super(options);
|
|
1617
|
+
this._limits = null;
|
|
1618
|
+
this._offsets = null;
|
|
1619
|
+
const _limit = function(max) {
|
|
1620
|
+
max = this._sanitizeLimitOffset(max);
|
|
1621
|
+
this._parent._limits = max;
|
|
1622
|
+
};
|
|
1623
|
+
this.ParentBlock = class extends cls.Block {
|
|
1624
|
+
_parent;
|
|
1625
|
+
constructor(parent) {
|
|
1626
|
+
super(parent.options);
|
|
1627
|
+
this._parent = parent;
|
|
1628
|
+
}
|
|
1629
|
+
};
|
|
1630
|
+
this.LimitBlock = class extends this.ParentBlock {
|
|
1631
|
+
limit;
|
|
1632
|
+
constructor(parent) {
|
|
1633
|
+
super(parent);
|
|
1634
|
+
this.limit = _limit;
|
|
1635
|
+
}
|
|
1636
|
+
_toParamString() {
|
|
1637
|
+
let str = "";
|
|
1638
|
+
if (this._parent._limits && this._parent._offsets) {
|
|
1639
|
+
str = `FETCH NEXT ${this._parent._limits} ROWS ONLY`;
|
|
1640
|
+
}
|
|
1641
|
+
return { text: str, values: [] };
|
|
1642
|
+
}
|
|
1643
|
+
};
|
|
1644
|
+
this.TopBlock = class extends this.ParentBlock {
|
|
1645
|
+
top;
|
|
1646
|
+
constructor(parent) {
|
|
1647
|
+
super(parent);
|
|
1648
|
+
this.top = _limit;
|
|
1649
|
+
}
|
|
1650
|
+
_toParamString() {
|
|
1651
|
+
let str = "";
|
|
1652
|
+
if (this._parent._limits && !this._parent._offsets) {
|
|
1653
|
+
str = `TOP (${this._parent._limits})`;
|
|
1654
|
+
}
|
|
1655
|
+
return { text: str, values: [] };
|
|
1656
|
+
}
|
|
1657
|
+
};
|
|
1658
|
+
this.OffsetBlock = class extends this.ParentBlock {
|
|
1659
|
+
offset(start) {
|
|
1660
|
+
this._parent._offsets = this._sanitizeLimitOffset(start);
|
|
1661
|
+
}
|
|
1662
|
+
_toParamString() {
|
|
1663
|
+
let str = "";
|
|
1664
|
+
if (this._parent._offsets) {
|
|
1665
|
+
str = `OFFSET ${this._parent._offsets} ROWS`;
|
|
1666
|
+
}
|
|
1667
|
+
return { text: str, values: [] };
|
|
1668
|
+
}
|
|
1669
|
+
};
|
|
1670
|
+
}
|
|
1671
|
+
LIMIT() {
|
|
1672
|
+
return new this.LimitBlock(this);
|
|
1673
|
+
}
|
|
1674
|
+
TOP() {
|
|
1675
|
+
return new this.TopBlock(this);
|
|
1676
|
+
}
|
|
1677
|
+
OFFSET() {
|
|
1678
|
+
return new this.OffsetBlock(this);
|
|
1679
|
+
}
|
|
1680
|
+
};
|
|
1681
|
+
cls.MssqlUpdateTopBlock = class extends cls.Block {
|
|
1682
|
+
_limits;
|
|
1683
|
+
limit;
|
|
1684
|
+
top;
|
|
1685
|
+
constructor(options) {
|
|
1686
|
+
super(options);
|
|
1687
|
+
this._limits = null;
|
|
1688
|
+
const setter = (max) => {
|
|
1689
|
+
this._limits = this._sanitizeLimitOffset(max);
|
|
1690
|
+
};
|
|
1691
|
+
this.limit = setter;
|
|
1692
|
+
this.top = setter;
|
|
1693
|
+
}
|
|
1694
|
+
_toParamString() {
|
|
1695
|
+
return {
|
|
1696
|
+
text: this._limits ? `TOP (${this._limits})` : "",
|
|
1697
|
+
values: []
|
|
1698
|
+
};
|
|
1699
|
+
}
|
|
1700
|
+
};
|
|
1701
|
+
cls.MssqlInsertFieldValueBlock = class extends cls.InsertFieldValueBlock {
|
|
1702
|
+
_outputs;
|
|
1703
|
+
constructor(options) {
|
|
1704
|
+
super(options);
|
|
1705
|
+
this._outputs = [];
|
|
1706
|
+
}
|
|
1707
|
+
output(fields) {
|
|
1708
|
+
if (typeof fields === "string") {
|
|
1709
|
+
this._outputs.push(`INSERTED.${this._sanitizeField(fields)}`);
|
|
1710
|
+
} else {
|
|
1711
|
+
fields.forEach((f) => {
|
|
1712
|
+
this._outputs.push(`INSERTED.${this._sanitizeField(f)}`);
|
|
1713
|
+
});
|
|
1714
|
+
}
|
|
1715
|
+
}
|
|
1716
|
+
_toParamString(options) {
|
|
1717
|
+
const ret = super._toParamString(options);
|
|
1718
|
+
if (ret.text.length && this._outputs.length > 0) {
|
|
1719
|
+
const innerStr = `OUTPUT ${this._outputs.join(", ")} `;
|
|
1720
|
+
const valuesPos = ret.text.indexOf("VALUES");
|
|
1721
|
+
ret.text = ret.text.substring(0, valuesPos) + innerStr + ret.text.substring(valuesPos);
|
|
1722
|
+
}
|
|
1723
|
+
return ret;
|
|
1724
|
+
}
|
|
1725
|
+
};
|
|
1726
|
+
cls.MssqlUpdateDeleteOutputBlock = class extends cls.Block {
|
|
1727
|
+
_outputs;
|
|
1728
|
+
constructor(options) {
|
|
1729
|
+
super(options);
|
|
1730
|
+
this._outputs = [];
|
|
1731
|
+
}
|
|
1732
|
+
outputs(outputs) {
|
|
1733
|
+
for (const output in outputs) {
|
|
1734
|
+
this.output(output, outputs[output]);
|
|
1735
|
+
}
|
|
1736
|
+
}
|
|
1737
|
+
output(output, alias = null) {
|
|
1738
|
+
output = this._sanitizeField(output);
|
|
1739
|
+
alias = alias ? this._sanitizeFieldAlias(alias) : alias;
|
|
1740
|
+
this._outputs.push({
|
|
1741
|
+
name: this.options.forDelete ? `DELETED.${output}` : `INSERTED.${output}`,
|
|
1742
|
+
alias
|
|
1743
|
+
});
|
|
1744
|
+
}
|
|
1745
|
+
_toParamString(_queryBuilder) {
|
|
1746
|
+
let totalStr = "";
|
|
1747
|
+
if (this._outputs.length) {
|
|
1748
|
+
for (const output of this._outputs) {
|
|
1749
|
+
totalStr = _pad(totalStr, ", ");
|
|
1750
|
+
totalStr += output.name;
|
|
1751
|
+
if (output.alias) {
|
|
1752
|
+
totalStr += ` AS ${this._formatFieldAlias(output.alias)}`;
|
|
1753
|
+
}
|
|
1754
|
+
}
|
|
1755
|
+
totalStr = `OUTPUT ${totalStr}`;
|
|
1756
|
+
}
|
|
1757
|
+
return { text: totalStr, values: [] };
|
|
1758
|
+
}
|
|
1759
|
+
};
|
|
1760
|
+
cls.Select = class extends cls.QueryBuilder {
|
|
1761
|
+
constructor(options, blocks = null) {
|
|
1762
|
+
const limitOffsetTopBlock = new cls.MssqlLimitOffsetTopBlock(options);
|
|
1763
|
+
blocks = blocks || [
|
|
1764
|
+
new cls.StringBlock(options, "SELECT"),
|
|
1765
|
+
new cls.DistinctBlock(options),
|
|
1766
|
+
limitOffsetTopBlock.TOP(),
|
|
1767
|
+
new cls.GetFieldBlock(options),
|
|
1768
|
+
new cls.FromTableBlock(options),
|
|
1769
|
+
new cls.JoinBlock(options),
|
|
1770
|
+
new cls.WhereBlock(options),
|
|
1771
|
+
new cls.GroupByBlock(options),
|
|
1772
|
+
new cls.OrderByBlock(options),
|
|
1773
|
+
limitOffsetTopBlock.OFFSET(),
|
|
1774
|
+
limitOffsetTopBlock.LIMIT(),
|
|
1775
|
+
new cls.UnionBlock(options)
|
|
1776
|
+
];
|
|
1777
|
+
super(options, blocks);
|
|
1778
|
+
}
|
|
1779
|
+
};
|
|
1780
|
+
cls.Update = class extends cls.QueryBuilder {
|
|
1781
|
+
constructor(options, blocks = null) {
|
|
1782
|
+
blocks = blocks || [
|
|
1783
|
+
new cls.StringBlock(options, "UPDATE"),
|
|
1784
|
+
new cls.MssqlUpdateTopBlock(options),
|
|
1785
|
+
new cls.UpdateTableBlock(options),
|
|
1786
|
+
new cls.SetFieldBlock(options),
|
|
1787
|
+
new cls.MssqlUpdateDeleteOutputBlock(options),
|
|
1788
|
+
new cls.WhereBlock(options)
|
|
1789
|
+
];
|
|
1790
|
+
super(options, blocks);
|
|
1791
|
+
}
|
|
1792
|
+
};
|
|
1793
|
+
cls.Delete = class extends cls.QueryBuilder {
|
|
1794
|
+
constructor(options, blocks = null) {
|
|
1795
|
+
blocks = blocks || [
|
|
1796
|
+
new cls.StringBlock(options, "DELETE"),
|
|
1797
|
+
new cls.TargetTableBlock(options),
|
|
1798
|
+
new cls.FromTableBlock(_extend({}, options, { singleTable: true })),
|
|
1799
|
+
new cls.JoinBlock(options),
|
|
1800
|
+
new cls.MssqlUpdateDeleteOutputBlock(_extend({}, options, { forDelete: true })),
|
|
1801
|
+
new cls.WhereBlock(options),
|
|
1802
|
+
new cls.OrderByBlock(options),
|
|
1803
|
+
new cls.LimitBlock(options)
|
|
1804
|
+
];
|
|
1805
|
+
super(options, blocks);
|
|
1806
|
+
}
|
|
1807
|
+
};
|
|
1808
|
+
cls.Insert = class extends cls.QueryBuilder {
|
|
1809
|
+
constructor(options, blocks = null) {
|
|
1810
|
+
blocks = blocks || [
|
|
1811
|
+
new cls.StringBlock(options, "INSERT"),
|
|
1812
|
+
new cls.IntoTableBlock(options),
|
|
1813
|
+
new cls.MssqlInsertFieldValueBlock(options),
|
|
1814
|
+
new cls.InsertFieldsFromQueryBlock(options)
|
|
1815
|
+
];
|
|
1816
|
+
super(options, blocks);
|
|
1817
|
+
}
|
|
1818
|
+
};
|
|
1819
|
+
};
|
|
1820
|
+
|
|
1821
|
+
// src/index.ts
|
|
1822
|
+
var src_default = core_default;
|
|
1823
|
+
|
|
1824
|
+
//# debugId=C450E93AEB966A1364756E2164756E21
|