@sqb/builder 4.15.0 → 4.16.1
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/cjs/package.json +3 -0
- package/esm/classes.ns.js +38 -41
- package/esm/enums.js +8 -11
- package/esm/extensions.js +1 -5
- package/esm/helpers.js +1 -4
- package/esm/index.js +20 -25
- package/esm/op.initializers.js +46 -78
- package/esm/package.json +3 -0
- package/esm/query/delete-query.js +11 -15
- package/esm/query/insert-query.js +13 -17
- package/esm/query/query.js +10 -15
- package/esm/query/returning-query.js +8 -12
- package/esm/query/select-query.js +28 -32
- package/esm/query/union-query.js +4 -8
- package/esm/query/update-query.js +14 -18
- package/esm/serializable.js +1 -5
- package/esm/serialize-context.js +15 -19
- package/esm/sql-objects/base-field.js +2 -6
- package/esm/sql-objects/case-statement.js +6 -10
- package/esm/sql-objects/coalesce-statement.js +4 -8
- package/esm/sql-objects/count-statement.js +4 -8
- package/esm/sql-objects/expression.js +2 -6
- package/esm/sql-objects/field-expression.js +4 -8
- package/esm/sql-objects/group-column.js +4 -8
- package/esm/sql-objects/join-statement.js +19 -23
- package/esm/sql-objects/lower-statement.js +4 -8
- package/esm/sql-objects/max-statement.js +4 -8
- package/esm/sql-objects/min-statement.js +4 -8
- package/esm/sql-objects/operator.js +2 -6
- package/esm/sql-objects/operators/comp-operator.js +13 -17
- package/esm/sql-objects/operators/logical-operator.js +16 -21
- package/esm/sql-objects/operators/op-and.js +4 -8
- package/esm/sql-objects/operators/op-between.js +4 -8
- package/esm/sql-objects/operators/op-eq.js +4 -8
- package/esm/sql-objects/operators/op-exists.js +6 -10
- package/esm/sql-objects/operators/op-gt.js +4 -8
- package/esm/sql-objects/operators/op-gte.js +4 -8
- package/esm/sql-objects/operators/op-ilike.js +4 -8
- package/esm/sql-objects/operators/op-in.js +6 -10
- package/esm/sql-objects/operators/op-is-not.js +4 -8
- package/esm/sql-objects/operators/op-is.js +4 -8
- package/esm/sql-objects/operators/op-like.js +4 -8
- package/esm/sql-objects/operators/op-lt.js +4 -8
- package/esm/sql-objects/operators/op-lte.js +4 -8
- package/esm/sql-objects/operators/op-ne.js +4 -8
- package/esm/sql-objects/operators/op-not-between.js +4 -8
- package/esm/sql-objects/operators/op-not-exists.js +4 -8
- package/esm/sql-objects/operators/op-not-ilike.js +4 -8
- package/esm/sql-objects/operators/op-not-in.js +4 -8
- package/esm/sql-objects/operators/op-not-like.js +4 -8
- package/esm/sql-objects/operators/op-not.js +5 -9
- package/esm/sql-objects/operators/op-or.js +4 -8
- package/esm/sql-objects/order-column.js +4 -8
- package/esm/sql-objects/param-expression.js +4 -8
- package/esm/sql-objects/raw-statement.js +4 -8
- package/esm/sql-objects/returning-column.js +4 -8
- package/esm/sql-objects/sequence-getter-statement.js +4 -8
- package/esm/sql-objects/string-agg-statement.js +11 -15
- package/esm/sql-objects/table-name.js +4 -8
- package/esm/sql-objects/upper-statement.js +4 -8
- package/esm/sqlobject.initializers.js +101 -131
- package/esm/typeguards.js +59 -80
- package/esm/types.js +1 -2
- package/package.json +20 -11
- package/types/query/select-query.d.ts +1 -1
|
@@ -1,24 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const typeguards_js_1 = require("../typeguards.js");
|
|
13
|
-
const query_js_1 = require("./query.js");
|
|
14
|
-
class SelectQuery extends query_js_1.Query {
|
|
1
|
+
import { coerceToInt } from 'putil-varhelpers';
|
|
2
|
+
import { SerializationType } from '../enums.js';
|
|
3
|
+
import { printArray } from '../helpers.js';
|
|
4
|
+
import { FieldExpression } from '../sql-objects/field-expression.js';
|
|
5
|
+
import { GroupColumn } from '../sql-objects/group-column.js';
|
|
6
|
+
import { OpAnd } from '../sql-objects/operators/op-and.js';
|
|
7
|
+
import { OrderColumn } from '../sql-objects/order-column.js';
|
|
8
|
+
import { TableName } from '../sql-objects/table-name.js';
|
|
9
|
+
import { isJoinStatement, isSerializable } from '../typeguards.js';
|
|
10
|
+
import { Query } from './query.js';
|
|
11
|
+
export class SelectQuery extends Query {
|
|
15
12
|
constructor(...column) {
|
|
16
13
|
super();
|
|
17
14
|
if (column.length)
|
|
18
15
|
this.addColumn(...column);
|
|
19
16
|
}
|
|
20
17
|
get _type() {
|
|
21
|
-
return
|
|
18
|
+
return SerializationType.SELECT_QUERY;
|
|
22
19
|
}
|
|
23
20
|
/**
|
|
24
21
|
* Adds columns to query.
|
|
@@ -32,7 +29,7 @@ class SelectQuery extends query_js_1.Query {
|
|
|
32
29
|
if (Array.isArray(arg))
|
|
33
30
|
self.addColumn(...arg);
|
|
34
31
|
else
|
|
35
|
-
this._columns.push(
|
|
32
|
+
this._columns.push(isSerializable(arg) ? arg : new FieldExpression(arg));
|
|
36
33
|
}
|
|
37
34
|
return this;
|
|
38
35
|
}
|
|
@@ -44,7 +41,7 @@ class SelectQuery extends query_js_1.Query {
|
|
|
44
41
|
for (const arg of table) {
|
|
45
42
|
if (!arg)
|
|
46
43
|
continue;
|
|
47
|
-
this._tables.push(typeof arg === 'string' ? new
|
|
44
|
+
this._tables.push(typeof arg === 'string' ? new TableName(arg) : arg);
|
|
48
45
|
}
|
|
49
46
|
return this;
|
|
50
47
|
}
|
|
@@ -56,7 +53,7 @@ class SelectQuery extends query_js_1.Query {
|
|
|
56
53
|
for (const arg of join) {
|
|
57
54
|
if (!arg)
|
|
58
55
|
continue;
|
|
59
|
-
if (!
|
|
56
|
+
if (!isJoinStatement(arg))
|
|
60
57
|
throw new TypeError('Join statement required');
|
|
61
58
|
this._joins.push(arg);
|
|
62
59
|
}
|
|
@@ -66,7 +63,7 @@ class SelectQuery extends query_js_1.Query {
|
|
|
66
63
|
* Defines "where" part of query
|
|
67
64
|
*/
|
|
68
65
|
where(...condition) {
|
|
69
|
-
this._where = this._where || new
|
|
66
|
+
this._where = this._where || new OpAnd();
|
|
70
67
|
this._where.add(...condition);
|
|
71
68
|
return this;
|
|
72
69
|
}
|
|
@@ -78,7 +75,7 @@ class SelectQuery extends query_js_1.Query {
|
|
|
78
75
|
for (const arg of field) {
|
|
79
76
|
if (!arg)
|
|
80
77
|
continue;
|
|
81
|
-
this._groupBy.push(typeof arg === 'string' ? new
|
|
78
|
+
this._groupBy.push(typeof arg === 'string' ? new GroupColumn(arg) : arg);
|
|
82
79
|
}
|
|
83
80
|
return this;
|
|
84
81
|
}
|
|
@@ -90,7 +87,7 @@ class SelectQuery extends query_js_1.Query {
|
|
|
90
87
|
for (const arg of field) {
|
|
91
88
|
if (!arg)
|
|
92
89
|
continue;
|
|
93
|
-
this._orderBy.push(typeof arg === 'string' ? new
|
|
90
|
+
this._orderBy.push(typeof arg === 'string' ? new OrderColumn(arg) : arg);
|
|
94
91
|
}
|
|
95
92
|
return this;
|
|
96
93
|
}
|
|
@@ -105,14 +102,14 @@ class SelectQuery extends query_js_1.Query {
|
|
|
105
102
|
* Sets limit for query
|
|
106
103
|
*/
|
|
107
104
|
limit(limit) {
|
|
108
|
-
this._limit =
|
|
105
|
+
this._limit = coerceToInt(limit);
|
|
109
106
|
return this;
|
|
110
107
|
}
|
|
111
108
|
/**
|
|
112
109
|
* Sets offset for query
|
|
113
110
|
*/
|
|
114
111
|
offset(offset) {
|
|
115
|
-
this._offset =
|
|
112
|
+
this._offset = coerceToInt(offset);
|
|
116
113
|
return this;
|
|
117
114
|
}
|
|
118
115
|
/**
|
|
@@ -192,7 +189,7 @@ class SelectQuery extends query_js_1.Query {
|
|
|
192
189
|
}
|
|
193
190
|
}
|
|
194
191
|
}
|
|
195
|
-
return ctx.serialize(
|
|
192
|
+
return ctx.serialize(SerializationType.SELECT_QUERY_COLUMNS, arr, () => printArray(arr) || '*');
|
|
196
193
|
}
|
|
197
194
|
/**
|
|
198
195
|
*
|
|
@@ -214,7 +211,7 @@ class SelectQuery extends query_js_1.Query {
|
|
|
214
211
|
}
|
|
215
212
|
}
|
|
216
213
|
}
|
|
217
|
-
return ctx.serialize(
|
|
214
|
+
return ctx.serialize(SerializationType.SELECT_QUERY_FROM, arr, () => {
|
|
218
215
|
const s = arr.join(',');
|
|
219
216
|
return s ? 'from' + (s.substring(0, 1) !== '\n' ? ' ' : '') + s : '';
|
|
220
217
|
});
|
|
@@ -232,7 +229,7 @@ class SelectQuery extends query_js_1.Query {
|
|
|
232
229
|
arr.push(s);
|
|
233
230
|
}
|
|
234
231
|
}
|
|
235
|
-
return ctx.serialize(
|
|
232
|
+
return ctx.serialize(SerializationType.SELECT_QUERY_JOIN, arr, () => arr.join('\n'));
|
|
236
233
|
}
|
|
237
234
|
/**
|
|
238
235
|
*
|
|
@@ -241,7 +238,7 @@ class SelectQuery extends query_js_1.Query {
|
|
|
241
238
|
if (!this._where)
|
|
242
239
|
return '';
|
|
243
240
|
const s = this._where._serialize(ctx);
|
|
244
|
-
return ctx.serialize(
|
|
241
|
+
return ctx.serialize(SerializationType.CONDITIONS_BLOCK, s, () =>
|
|
245
242
|
/* istanbul ignore next */
|
|
246
243
|
s ? 'where ' + s : '');
|
|
247
244
|
}
|
|
@@ -258,8 +255,8 @@ class SelectQuery extends query_js_1.Query {
|
|
|
258
255
|
arr.push(s);
|
|
259
256
|
}
|
|
260
257
|
}
|
|
261
|
-
return ctx.serialize(
|
|
262
|
-
const s =
|
|
258
|
+
return ctx.serialize(SerializationType.SELECT_QUERY_GROUPBY, arr, () => {
|
|
259
|
+
const s = printArray(arr);
|
|
263
260
|
return s ? 'group by ' + s : '';
|
|
264
261
|
});
|
|
265
262
|
}
|
|
@@ -273,10 +270,9 @@ class SelectQuery extends query_js_1.Query {
|
|
|
273
270
|
arr.push(s);
|
|
274
271
|
}
|
|
275
272
|
}
|
|
276
|
-
return ctx.serialize(
|
|
277
|
-
const s =
|
|
273
|
+
return ctx.serialize(SerializationType.SELECT_QUERY_ORDERBY, arr, () => {
|
|
274
|
+
const s = printArray(arr);
|
|
278
275
|
return s ? 'order by ' + s : '';
|
|
279
276
|
});
|
|
280
277
|
}
|
|
281
278
|
}
|
|
282
|
-
exports.SelectQuery = SelectQuery;
|
package/esm/query/union-query.js
CHANGED
|
@@ -1,16 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const enums_js_1 = require("../enums.js");
|
|
5
|
-
const query_js_1 = require("./query.js");
|
|
6
|
-
class UnionQuery extends query_js_1.Query {
|
|
1
|
+
import { SerializationType } from '../enums.js';
|
|
2
|
+
import { Query } from './query.js';
|
|
3
|
+
export class UnionQuery extends Query {
|
|
7
4
|
constructor(queries, unionType) {
|
|
8
5
|
super();
|
|
9
6
|
this._queries = queries;
|
|
10
7
|
this._unionType = unionType;
|
|
11
8
|
}
|
|
12
9
|
get _type() {
|
|
13
|
-
return
|
|
10
|
+
return SerializationType.UNION_QUERY;
|
|
14
11
|
}
|
|
15
12
|
/**
|
|
16
13
|
* Performs serialization
|
|
@@ -27,4 +24,3 @@ class UnionQuery extends query_js_1.Query {
|
|
|
27
24
|
return o.queries.join(o.unionType === 'all' ? '\nUNION ALL\n' : '\nUNION\n');
|
|
28
25
|
}
|
|
29
26
|
}
|
|
30
|
-
exports.UnionQuery = UnionQuery;
|
|
@@ -1,32 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const typeguards_js_1 = require("../typeguards.js");
|
|
9
|
-
const returning_query_js_1 = require("./returning-query.js");
|
|
10
|
-
class UpdateQuery extends returning_query_js_1.ReturningQuery {
|
|
1
|
+
import { SerializationType } from '../enums.js';
|
|
2
|
+
import { printArray } from '../helpers.js';
|
|
3
|
+
import { OpAnd } from '../sql-objects/operators/op-and.js';
|
|
4
|
+
import { TableName } from '../sql-objects/table-name.js';
|
|
5
|
+
import { isRawStatement } from '../typeguards.js';
|
|
6
|
+
import { ReturningQuery } from './returning-query.js';
|
|
7
|
+
export class UpdateQuery extends ReturningQuery {
|
|
11
8
|
constructor(tableName, input) {
|
|
12
9
|
super();
|
|
13
|
-
if (!tableName || !(typeof tableName === 'string' ||
|
|
10
|
+
if (!tableName || !(typeof tableName === 'string' || isRawStatement(tableName))) {
|
|
14
11
|
throw new TypeError('String or Raw instance required as first argument (tableName) for UpdateQuery');
|
|
15
12
|
}
|
|
16
13
|
if (!input || !((typeof input === 'object' && !Array.isArray(input)) || input.isSelect)) {
|
|
17
14
|
throw new TypeError('Object or Raw instance required as second argument (input) for UpdateQuery');
|
|
18
15
|
}
|
|
19
|
-
this._table = typeof tableName === 'string' ? new
|
|
16
|
+
this._table = typeof tableName === 'string' ? new TableName(tableName) : tableName;
|
|
20
17
|
this._input = input;
|
|
21
18
|
}
|
|
22
19
|
get _type() {
|
|
23
|
-
return
|
|
20
|
+
return SerializationType.UPDATE_QUERY;
|
|
24
21
|
}
|
|
25
22
|
/**
|
|
26
23
|
* Defines "where" part of query
|
|
27
24
|
*/
|
|
28
25
|
where(...operator) {
|
|
29
|
-
this._where = this._where || new
|
|
26
|
+
this._where = this._where || new OpAnd();
|
|
30
27
|
this._where.add(...operator);
|
|
31
28
|
return this;
|
|
32
29
|
}
|
|
@@ -60,9 +57,9 @@ class UpdateQuery extends returning_query_js_1.ReturningQuery {
|
|
|
60
57
|
value,
|
|
61
58
|
});
|
|
62
59
|
}
|
|
63
|
-
return ctx.serialize(
|
|
60
|
+
return ctx.serialize(SerializationType.UPDATE_QUERY_VALUES, arr, () => {
|
|
64
61
|
const a = arr.map(o => o.field + ' = ' + o.value);
|
|
65
|
-
return
|
|
62
|
+
return printArray(a, ',');
|
|
66
63
|
});
|
|
67
64
|
}
|
|
68
65
|
/**
|
|
@@ -72,9 +69,8 @@ class UpdateQuery extends returning_query_js_1.ReturningQuery {
|
|
|
72
69
|
if (!this._where)
|
|
73
70
|
return '';
|
|
74
71
|
const s = this._where._serialize(ctx);
|
|
75
|
-
return ctx.serialize(
|
|
72
|
+
return ctx.serialize(SerializationType.CONDITIONS_BLOCK, s, () =>
|
|
76
73
|
/* istanbul ignore next */
|
|
77
74
|
s ? 'where ' + s : '');
|
|
78
75
|
}
|
|
79
76
|
}
|
|
80
|
-
exports.UpdateQuery = UpdateQuery;
|
package/esm/serializable.js
CHANGED
package/esm/serialize-context.js
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const serializable_js_1 = require("./serializable.js");
|
|
7
|
-
const typeguards_js_1 = require("./typeguards.js");
|
|
8
|
-
class SerializeContext {
|
|
1
|
+
import { SerializationType } from './enums.js';
|
|
2
|
+
import { SerializerRegistry } from './extensions.js';
|
|
3
|
+
import { Serializable } from './serializable.js';
|
|
4
|
+
import { isLogicalOperator, isQuery, isSerializable } from './typeguards.js';
|
|
5
|
+
export class SerializeContext {
|
|
9
6
|
constructor(opts) {
|
|
10
7
|
this.reservedWords = [
|
|
11
8
|
'schema',
|
|
@@ -79,7 +76,7 @@ class SerializeContext {
|
|
|
79
76
|
return s;
|
|
80
77
|
}
|
|
81
78
|
}
|
|
82
|
-
for (const ext of
|
|
79
|
+
for (const ext of SerializerRegistry.items()) {
|
|
83
80
|
if (ext.dialect === this.dialect && ext.serialize) {
|
|
84
81
|
const s = ext.serialize(this, type, o, fallback);
|
|
85
82
|
if (s != null)
|
|
@@ -96,28 +93,28 @@ class SerializeContext {
|
|
|
96
93
|
return 'null';
|
|
97
94
|
if (Array.isArray(v)) {
|
|
98
95
|
const vv = v.map(x => this.anyToSQL(x));
|
|
99
|
-
return this.serialize(
|
|
96
|
+
return this.serialize(SerializationType.ARRAY, vv, () => '(' + vv.join(',')) + ')';
|
|
100
97
|
}
|
|
101
98
|
if (typeof v === 'object') {
|
|
102
|
-
if (
|
|
99
|
+
if (isSerializable(v)) {
|
|
103
100
|
const s = v._serialize(this);
|
|
104
|
-
return s ? (
|
|
101
|
+
return s ? (isQuery(v) || isLogicalOperator(v) ? '(' + s + ')' : s) : /* istanbul ignore next */ '';
|
|
105
102
|
}
|
|
106
103
|
if (v instanceof Date) {
|
|
107
|
-
return this.serialize(
|
|
104
|
+
return this.serialize(SerializationType.DATE_VALUE, v, () => this.dateToSQL(v));
|
|
108
105
|
}
|
|
109
106
|
return this.stringToSQL(JSON.stringify(v));
|
|
110
107
|
}
|
|
111
108
|
if (typeof v === 'string') {
|
|
112
|
-
return this.serialize(
|
|
109
|
+
return this.serialize(SerializationType.STRING_VALUE, v, () => this.stringToSQL(v));
|
|
113
110
|
}
|
|
114
111
|
if (typeof v === 'boolean') {
|
|
115
|
-
return this.serialize(
|
|
112
|
+
return this.serialize(SerializationType.BOOLEAN_VALUE, v, () => this.booleanToSQL(v));
|
|
116
113
|
}
|
|
117
114
|
if (typeof v === 'number') {
|
|
118
|
-
return this.serialize(
|
|
115
|
+
return this.serialize(SerializationType.NUMBER_VALUE, v, () => this.numberToSQL(v));
|
|
119
116
|
}
|
|
120
|
-
if (v instanceof
|
|
117
|
+
if (v instanceof Serializable)
|
|
121
118
|
return v._serialize(this);
|
|
122
119
|
return v;
|
|
123
120
|
}
|
|
@@ -163,7 +160,7 @@ class SerializeContext {
|
|
|
163
160
|
return false;
|
|
164
161
|
if (this.reservedWords.includes(s.toLowerCase()))
|
|
165
162
|
return true;
|
|
166
|
-
for (const ext of
|
|
163
|
+
for (const ext of SerializerRegistry.items()) {
|
|
167
164
|
if (ext.dialect === this.dialect && ext.isReservedWord) {
|
|
168
165
|
if (ext.isReservedWord(this, s))
|
|
169
166
|
return true;
|
|
@@ -179,4 +176,3 @@ class SerializeContext {
|
|
|
179
176
|
return s;
|
|
180
177
|
}
|
|
181
178
|
}
|
|
182
|
-
exports.SerializeContext = SerializeContext;
|
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.BaseField = void 0;
|
|
4
|
-
const expression_js_1 = require("./expression.js");
|
|
5
|
-
class BaseField extends expression_js_1.Expression {
|
|
1
|
+
import { Expression } from './expression.js';
|
|
2
|
+
export class BaseField extends Expression {
|
|
6
3
|
constructor() {
|
|
7
4
|
super(...arguments);
|
|
8
5
|
this._field = '';
|
|
9
6
|
}
|
|
10
7
|
}
|
|
11
|
-
exports.BaseField = BaseField;
|
|
@@ -1,23 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const serializable_js_1 = require("../serializable.js");
|
|
6
|
-
const op_and_js_1 = require("./operators/op-and.js");
|
|
7
|
-
class CaseStatement extends serializable_js_1.Serializable {
|
|
1
|
+
import { SerializationType } from '../enums.js';
|
|
2
|
+
import { Serializable } from '../serializable.js';
|
|
3
|
+
import { OpAnd } from './operators/op-and.js';
|
|
4
|
+
export class CaseStatement extends Serializable {
|
|
8
5
|
constructor() {
|
|
9
6
|
super();
|
|
10
7
|
this._expressions = [];
|
|
11
8
|
}
|
|
12
9
|
get _type() {
|
|
13
|
-
return
|
|
10
|
+
return SerializationType.CASE_STATEMENT;
|
|
14
11
|
}
|
|
15
12
|
/**
|
|
16
13
|
* Defines "when" part of Case expression.
|
|
17
14
|
*/
|
|
18
15
|
when(...condition) {
|
|
19
16
|
if (condition.length)
|
|
20
|
-
this._condition = new
|
|
17
|
+
this._condition = new OpAnd(...condition);
|
|
21
18
|
else
|
|
22
19
|
this._condition = undefined;
|
|
23
20
|
return this;
|
|
@@ -82,4 +79,3 @@ class CaseStatement extends serializable_js_1.Serializable {
|
|
|
82
79
|
return out;
|
|
83
80
|
}
|
|
84
81
|
}
|
|
85
|
-
exports.CaseStatement = CaseStatement;
|
|
@@ -1,15 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const enums_js_1 = require("../enums.js");
|
|
5
|
-
const serializable_js_1 = require("../serializable.js");
|
|
6
|
-
class CoalesceStatement extends serializable_js_1.Serializable {
|
|
1
|
+
import { SerializationType } from '../enums.js';
|
|
2
|
+
import { Serializable } from '../serializable.js';
|
|
3
|
+
export class CoalesceStatement extends Serializable {
|
|
7
4
|
constructor(...expressions) {
|
|
8
5
|
super();
|
|
9
6
|
this._expressions = expressions;
|
|
10
7
|
}
|
|
11
8
|
get _type() {
|
|
12
|
-
return
|
|
9
|
+
return SerializationType.COALESCE_STATEMENT;
|
|
13
10
|
}
|
|
14
11
|
/**
|
|
15
12
|
* Sets alias to case expression.
|
|
@@ -40,4 +37,3 @@ class CoalesceStatement extends serializable_js_1.Serializable {
|
|
|
40
37
|
return 'coalesce(' + o.expressions.join(', ') + ')' + (this._alias ? ' ' + this._alias : '');
|
|
41
38
|
}
|
|
42
39
|
}
|
|
43
|
-
exports.CoalesceStatement = CoalesceStatement;
|
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const enums_js_1 = require("../enums.js");
|
|
5
|
-
const serializable_js_1 = require("../serializable.js");
|
|
6
|
-
class CountStatement extends serializable_js_1.Serializable {
|
|
1
|
+
import { SerializationType } from '../enums.js';
|
|
2
|
+
import { Serializable } from '../serializable.js';
|
|
3
|
+
export class CountStatement extends Serializable {
|
|
7
4
|
get _type() {
|
|
8
|
-
return
|
|
5
|
+
return SerializationType.COUNT_STATEMENT;
|
|
9
6
|
}
|
|
10
7
|
/**
|
|
11
8
|
* Sets alias to case expression.
|
|
@@ -33,4 +30,3 @@ class CountStatement extends serializable_js_1.Serializable {
|
|
|
33
30
|
return 'count(*)';
|
|
34
31
|
}
|
|
35
32
|
}
|
|
36
|
-
exports.CountStatement = CountStatement;
|
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.Expression = void 0;
|
|
4
|
-
const serializable_js_1 = require("../serializable.js");
|
|
5
|
-
class Expression extends serializable_js_1.Serializable {
|
|
1
|
+
import { Serializable } from '../serializable.js';
|
|
2
|
+
export class Expression extends Serializable {
|
|
6
3
|
}
|
|
7
|
-
exports.Expression = Expression;
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.FieldExpression = void 0;
|
|
4
|
-
const enums_js_1 = require("../enums.js");
|
|
5
|
-
const base_field_js_1 = require("./base-field.js");
|
|
1
|
+
import { SerializationType } from '../enums.js';
|
|
2
|
+
import { BaseField } from './base-field.js';
|
|
6
3
|
const TABLE_COLUMN_PATTERN = /^((?:[a-zA-Z_][\w$_]*\.){0,2}) *([0-9a-zA-Z_][\w$_]*|\*) *(?:as)? *([a-zA-Z_][\w$_]*)?$/;
|
|
7
|
-
class FieldExpression extends
|
|
4
|
+
export class FieldExpression extends BaseField {
|
|
8
5
|
constructor(arg0, arg1, arg2) {
|
|
9
6
|
super();
|
|
10
7
|
let expression;
|
|
@@ -31,7 +28,7 @@ class FieldExpression extends base_field_js_1.BaseField {
|
|
|
31
28
|
this._alias = this._field !== '*' ? m[3] : '';
|
|
32
29
|
}
|
|
33
30
|
get _type() {
|
|
34
|
-
return
|
|
31
|
+
return SerializationType.FIELD_NAME;
|
|
35
32
|
}
|
|
36
33
|
_serialize(ctx) {
|
|
37
34
|
const o = {
|
|
@@ -49,4 +46,3 @@ class FieldExpression extends base_field_js_1.BaseField {
|
|
|
49
46
|
});
|
|
50
47
|
}
|
|
51
48
|
}
|
|
52
|
-
exports.FieldExpression = FieldExpression;
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.GroupColumn = void 0;
|
|
4
|
-
const enums_js_1 = require("../enums.js");
|
|
5
|
-
const base_field_js_1 = require("./base-field.js");
|
|
1
|
+
import { SerializationType } from '../enums.js';
|
|
2
|
+
import { BaseField } from './base-field.js';
|
|
6
3
|
const GROUP_COLUMN_PATTERN = /^((?:[a-zA-Z][\w$]*\.){0,2})([\w$]*)$/;
|
|
7
|
-
class GroupColumn extends
|
|
4
|
+
export class GroupColumn extends BaseField {
|
|
8
5
|
constructor(value) {
|
|
9
6
|
super();
|
|
10
7
|
const m = value.match(GROUP_COLUMN_PATTERN);
|
|
@@ -19,7 +16,7 @@ class GroupColumn extends base_field_js_1.BaseField {
|
|
|
19
16
|
}
|
|
20
17
|
}
|
|
21
18
|
get _type() {
|
|
22
|
-
return
|
|
19
|
+
return SerializationType.GROUP_COLUMN;
|
|
23
20
|
}
|
|
24
21
|
_serialize(ctx) {
|
|
25
22
|
const o = {
|
|
@@ -33,4 +30,3 @@ class GroupColumn extends base_field_js_1.BaseField {
|
|
|
33
30
|
(o.isReservedWord ? '"' + this._field + '"' : this._field));
|
|
34
31
|
}
|
|
35
32
|
}
|
|
36
|
-
exports.GroupColumn = GroupColumn;
|
|
@@ -1,24 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const op_and_js_1 = require("./operators/op-and.js");
|
|
8
|
-
const table_name_js_1 = require("./table-name.js");
|
|
9
|
-
class JoinStatement extends serializable_js_1.Serializable {
|
|
1
|
+
import { JoinType, SerializationType } from '../enums.js';
|
|
2
|
+
import { Serializable } from '../serializable.js';
|
|
3
|
+
import { isRawStatement, isSelectQuery, isTableName } from '../typeguards.js';
|
|
4
|
+
import { OpAnd } from './operators/op-and.js';
|
|
5
|
+
import { TableName } from './table-name.js';
|
|
6
|
+
export class JoinStatement extends Serializable {
|
|
10
7
|
constructor(joinType, table) {
|
|
11
8
|
super();
|
|
12
|
-
this._conditions = new
|
|
9
|
+
this._conditions = new OpAnd();
|
|
13
10
|
// noinspection SuspiciousTypeOfGuard
|
|
14
|
-
if (!(
|
|
11
|
+
if (!(isSelectQuery(table) || isRawStatement(table) || isTableName(table) || typeof table === 'string')) {
|
|
15
12
|
throw new TypeError('Table name, select query or raw object required for Join');
|
|
16
13
|
}
|
|
17
14
|
this._joinType = joinType;
|
|
18
|
-
this._table = typeof table === 'string' ? new
|
|
15
|
+
this._table = typeof table === 'string' ? new TableName(table) : table;
|
|
19
16
|
}
|
|
20
17
|
get _type() {
|
|
21
|
-
return
|
|
18
|
+
return SerializationType.JOIN;
|
|
22
19
|
}
|
|
23
20
|
on(...conditions) {
|
|
24
21
|
this._conditions.add(...conditions);
|
|
@@ -33,25 +30,25 @@ class JoinStatement extends serializable_js_1.Serializable {
|
|
|
33
30
|
return ctx.serialize(this._type, o, () => {
|
|
34
31
|
let out;
|
|
35
32
|
switch (this._joinType) {
|
|
36
|
-
case
|
|
33
|
+
case JoinType.LEFT:
|
|
37
34
|
out = 'left join';
|
|
38
35
|
break;
|
|
39
|
-
case
|
|
36
|
+
case JoinType.LEFT_OUTER:
|
|
40
37
|
out = 'left outer join';
|
|
41
38
|
break;
|
|
42
|
-
case
|
|
39
|
+
case JoinType.RIGHT:
|
|
43
40
|
out = 'right join';
|
|
44
41
|
break;
|
|
45
|
-
case
|
|
42
|
+
case JoinType.RIGHT_OUTER:
|
|
46
43
|
out = 'right outer join';
|
|
47
44
|
break;
|
|
48
|
-
case
|
|
45
|
+
case JoinType.OUTER:
|
|
49
46
|
out = 'outer join';
|
|
50
47
|
break;
|
|
51
|
-
case
|
|
48
|
+
case JoinType.FULL_OUTER:
|
|
52
49
|
out = 'full outer join';
|
|
53
50
|
break;
|
|
54
|
-
case
|
|
51
|
+
case JoinType.CROSS:
|
|
55
52
|
out = 'cross join';
|
|
56
53
|
break;
|
|
57
54
|
default:
|
|
@@ -59,7 +56,7 @@ class JoinStatement extends serializable_js_1.Serializable {
|
|
|
59
56
|
break;
|
|
60
57
|
}
|
|
61
58
|
const lf = o.table.length > 40;
|
|
62
|
-
if (
|
|
59
|
+
if (isSelectQuery(this._table)) {
|
|
63
60
|
const alias = this._table._alias;
|
|
64
61
|
if (!alias)
|
|
65
62
|
throw new Error('Alias required for sub-select in Join');
|
|
@@ -75,9 +72,8 @@ class JoinStatement extends serializable_js_1.Serializable {
|
|
|
75
72
|
__serializeConditions(ctx, join) {
|
|
76
73
|
if (join._conditions._items.length) {
|
|
77
74
|
const s = join._conditions._serialize(ctx);
|
|
78
|
-
return ctx.serialize(
|
|
75
|
+
return ctx.serialize(SerializationType.JOIN_CONDITIONS, s, () => (s ? 'on ' + s : ''));
|
|
79
76
|
}
|
|
80
77
|
return '';
|
|
81
78
|
}
|
|
82
79
|
}
|
|
83
|
-
exports.JoinStatement = JoinStatement;
|
|
@@ -1,15 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const enums_js_1 = require("../enums.js");
|
|
5
|
-
const serializable_js_1 = require("../serializable.js");
|
|
6
|
-
class LowerStatement extends serializable_js_1.Serializable {
|
|
1
|
+
import { SerializationType } from '../enums.js';
|
|
2
|
+
import { Serializable } from '../serializable.js';
|
|
3
|
+
export class LowerStatement extends Serializable {
|
|
7
4
|
constructor(expression) {
|
|
8
5
|
super();
|
|
9
6
|
this._expression = expression;
|
|
10
7
|
}
|
|
11
8
|
get _type() {
|
|
12
|
-
return
|
|
9
|
+
return SerializationType.LOWER_STATEMENT;
|
|
13
10
|
}
|
|
14
11
|
/**
|
|
15
12
|
* Sets alias to case expression.
|
|
@@ -35,4 +32,3 @@ class LowerStatement extends serializable_js_1.Serializable {
|
|
|
35
32
|
return 'lower(' + o + ')' + (this._alias ? ' ' + this._alias : '');
|
|
36
33
|
}
|
|
37
34
|
}
|
|
38
|
-
exports.LowerStatement = LowerStatement;
|
|
@@ -1,15 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const enums_js_1 = require("../enums.js");
|
|
5
|
-
const serializable_js_1 = require("../serializable.js");
|
|
6
|
-
class MaxStatement extends serializable_js_1.Serializable {
|
|
1
|
+
import { SerializationType } from '../enums.js';
|
|
2
|
+
import { Serializable } from '../serializable.js';
|
|
3
|
+
export class MaxStatement extends Serializable {
|
|
7
4
|
constructor(expression) {
|
|
8
5
|
super();
|
|
9
6
|
this._expression = expression;
|
|
10
7
|
}
|
|
11
8
|
get _type() {
|
|
12
|
-
return
|
|
9
|
+
return SerializationType.MAX_STATEMENT;
|
|
13
10
|
}
|
|
14
11
|
/**
|
|
15
12
|
* Sets alias to case expression.
|
|
@@ -35,4 +32,3 @@ class MaxStatement extends serializable_js_1.Serializable {
|
|
|
35
32
|
return 'max(' + o + ')' + (this._alias ? ' ' + this._alias : '');
|
|
36
33
|
}
|
|
37
34
|
}
|
|
38
|
-
exports.MaxStatement = MaxStatement;
|