@sqb/builder 4.11.3 → 4.12.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/README.md +9 -24
- package/cjs/helpers.js +1 -1
- package/cjs/op.initializers.js +1 -1
- package/cjs/query/delete-query.js +2 -3
- package/cjs/query/insert-query.js +3 -5
- package/cjs/query/query.js +1 -1
- package/cjs/query/returning-query.js +4 -3
- package/cjs/query/select-query.js +4 -8
- package/cjs/query/union-query.js +1 -1
- package/cjs/query/update-query.js +3 -4
- package/cjs/serialize-context.js +60 -18
- package/cjs/sql-objects/case-statement.js +3 -4
- package/cjs/sql-objects/coalesce-statement.js +1 -2
- package/cjs/sql-objects/count-statement.js +3 -1
- package/cjs/sql-objects/field-expression.js +4 -5
- package/cjs/sql-objects/group-column.js +3 -3
- package/cjs/sql-objects/join-statement.js +4 -6
- package/cjs/sql-objects/lower-statement.js +1 -2
- package/cjs/sql-objects/max-statement.js +1 -2
- package/cjs/sql-objects/min-statement.js +1 -2
- package/cjs/sql-objects/operators/comp-operator.js +4 -6
- package/cjs/sql-objects/operators/logical-operator.js +1 -1
- package/cjs/sql-objects/operators/op-between.js +3 -7
- package/cjs/sql-objects/operators/op-exists.js +1 -1
- package/cjs/sql-objects/order-column.js +4 -4
- package/cjs/sql-objects/param-expression.js +1 -2
- package/cjs/sql-objects/returning-column.js +2 -3
- package/cjs/sql-objects/sequence-getter-statement.js +2 -3
- package/cjs/sql-objects/string-agg-statement.js +9 -5
- package/cjs/sql-objects/table-name.js +2 -3
- package/cjs/sql-objects/upper-statement.js +1 -2
- package/cjs/sqlobject.initializers.js +1 -1
- package/esm/helpers.js +1 -1
- package/esm/op.initializers.js +2 -2
- package/esm/query/delete-query.js +2 -3
- package/esm/query/insert-query.js +3 -5
- package/esm/query/query.js +1 -1
- package/esm/query/returning-query.js +4 -3
- package/esm/query/select-query.js +4 -8
- package/esm/query/union-query.js +1 -1
- package/esm/query/update-query.js +3 -4
- package/esm/serialize-context.js +60 -18
- package/esm/sql-objects/case-statement.js +3 -4
- package/esm/sql-objects/coalesce-statement.js +1 -2
- package/esm/sql-objects/count-statement.js +3 -1
- package/esm/sql-objects/field-expression.js +4 -5
- package/esm/sql-objects/group-column.js +3 -3
- package/esm/sql-objects/join-statement.js +4 -6
- package/esm/sql-objects/lower-statement.js +1 -2
- package/esm/sql-objects/max-statement.js +1 -2
- package/esm/sql-objects/min-statement.js +1 -2
- package/esm/sql-objects/operators/comp-operator.js +4 -6
- package/esm/sql-objects/operators/logical-operator.js +1 -1
- package/esm/sql-objects/operators/op-between.js +3 -7
- package/esm/sql-objects/operators/op-exists.js +1 -1
- package/esm/sql-objects/order-column.js +4 -4
- package/esm/sql-objects/param-expression.js +1 -2
- package/esm/sql-objects/returning-column.js +2 -3
- package/esm/sql-objects/sequence-getter-statement.js +2 -3
- package/esm/sql-objects/string-agg-statement.js +9 -5
- package/esm/sql-objects/table-name.js +2 -3
- package/esm/sql-objects/upper-statement.js +1 -2
- package/esm/sqlobject.initializers.js +1 -1
- package/package.json +4 -2
- package/types/op.initializers.d.ts +1 -1
package/README.md
CHANGED
|
@@ -18,12 +18,12 @@ SQB is an extensible, multi-dialect SQL query builder and Database connection wr
|
|
|
18
18
|
|
|
19
19
|
## Main goals
|
|
20
20
|
|
|
21
|
-
-
|
|
22
|
-
-
|
|
23
|
-
-
|
|
24
|
-
-
|
|
25
|
-
-
|
|
26
|
-
-
|
|
21
|
+
- Single code base for any sql based database
|
|
22
|
+
- Powerful and simplified query coding scheme
|
|
23
|
+
- Fast applications with low memory requirements
|
|
24
|
+
- Let applications work with large data tables efficiently
|
|
25
|
+
- Support latest JavaScript language standards
|
|
26
|
+
- Lightweight and extensible framework.
|
|
27
27
|
|
|
28
28
|
You can report bugs and discuss features on the [GitHub issues](https://github.com/sqbjs/sqb/issues) page
|
|
29
29
|
|
|
@@ -39,40 +39,25 @@ $ npm install @sqb/builder --save
|
|
|
39
39
|
|
|
40
40
|
## Node Compatibility
|
|
41
41
|
|
|
42
|
-
-
|
|
42
|
+
- node >= 16.x
|
|
43
43
|
|
|
44
44
|
### License
|
|
45
45
|
|
|
46
46
|
SQB is available under [MIT](LICENSE) license.
|
|
47
47
|
|
|
48
48
|
[npm-image]: https://img.shields.io/npm/v/@sqb/builder.svg
|
|
49
|
-
|
|
50
49
|
[npm-url]: https://npmjs.org/package/@sqb/builder
|
|
51
|
-
|
|
52
50
|
[travis-image]: https://img.shields.io/travis/sqbjs/@sqb/builder/master.svg
|
|
53
|
-
|
|
54
51
|
[travis-url]: https://travis-ci.org/sqbjs/@sqb/builder
|
|
55
|
-
|
|
56
52
|
[coveralls-image]: https://img.shields.io/coveralls/sqbjs/@sqb/builder/master.svg
|
|
57
|
-
|
|
58
53
|
[coveralls-url]: https://coveralls.io/r/sqbjs/@sqb/builder
|
|
59
|
-
|
|
60
54
|
[downloads-image]: https://img.shields.io/npm/dm/@sqb/builder.svg
|
|
61
|
-
|
|
62
55
|
[downloads-url]: https://npmjs.org/package/@sqb/builder
|
|
63
|
-
|
|
64
56
|
[gitter-image]: https://badges.gitter.im/sqbjs/@sqb/builder.svg
|
|
65
|
-
|
|
66
57
|
[gitter-url]: https://gitter.im/sqbjs/@sqb/builder?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge
|
|
67
|
-
|
|
68
58
|
[dependencies-image]: https://david-dm.org/sqbjs/@sqb/builder/status.svg
|
|
69
|
-
|
|
70
|
-
[dependencies-url]:https://david-dm.org/sqbjs/@sqb/builder
|
|
71
|
-
|
|
59
|
+
[dependencies-url]: https://david-dm.org/sqbjs/@sqb/builder
|
|
72
60
|
[devdependencies-image]: https://david-dm.org/sqbjs/@sqb/builder/dev-status.svg
|
|
73
|
-
|
|
74
|
-
[devdependencies-url]:https://david-dm.org/sqbjs/@sqb/builder?type=dev
|
|
75
|
-
|
|
61
|
+
[devdependencies-url]: https://david-dm.org/sqbjs/@sqb/builder?type=dev
|
|
76
62
|
[quality-image]: http://npm.packagequality.com/shield/@sqb/builder.png
|
|
77
|
-
|
|
78
63
|
[quality-url]: http://packagequality.com/#?package=@sqb/builder
|
package/cjs/helpers.js
CHANGED
package/cjs/op.initializers.js
CHANGED
|
@@ -30,13 +30,12 @@ class DeleteQuery extends query_js_1.Query {
|
|
|
30
30
|
_serialize(ctx) {
|
|
31
31
|
const o = {
|
|
32
32
|
table: this._table._serialize(ctx),
|
|
33
|
-
where: this._serializeWhere(ctx)
|
|
33
|
+
where: this._serializeWhere(ctx),
|
|
34
34
|
};
|
|
35
35
|
return ctx.serialize(this._type, o, () => this.__defaultSerialize(ctx, o));
|
|
36
36
|
}
|
|
37
37
|
__defaultSerialize(ctx, o) {
|
|
38
|
-
return 'delete from ' + o.table +
|
|
39
|
-
(o.where ? '\n' + o.where : '');
|
|
38
|
+
return 'delete from ' + o.table + (o.where ? '\n' + o.where : '');
|
|
40
39
|
}
|
|
41
40
|
/**
|
|
42
41
|
*
|
|
@@ -11,8 +11,7 @@ class InsertQuery extends returning_query_js_1.ReturningQuery {
|
|
|
11
11
|
super();
|
|
12
12
|
if (!tableName || !(typeof tableName === 'string' || (0, typeguards_js_1.isRawStatement)(tableName)))
|
|
13
13
|
throw new TypeError('String or Raw instance required as first argument (tableName) for InsertQuery');
|
|
14
|
-
if (!input || !((typeof input === 'object' && !Array.isArray(input)) ||
|
|
15
|
-
input.isSelect))
|
|
14
|
+
if (!input || !((typeof input === 'object' && !Array.isArray(input)) || input.isSelect))
|
|
16
15
|
throw new TypeError('Object or SelectQuery instance required as second argument (input) for InsertQuery');
|
|
17
16
|
this._table = typeof tableName === 'string' ? new table_name_js_1.TableName(tableName) : tableName;
|
|
18
17
|
this._input = input;
|
|
@@ -28,10 +27,9 @@ class InsertQuery extends returning_query_js_1.ReturningQuery {
|
|
|
28
27
|
table: this._table._serialize(ctx),
|
|
29
28
|
columns: this.__serializeColumns(ctx),
|
|
30
29
|
values: this.__serializeValues(ctx),
|
|
31
|
-
returning: this.__serializeReturning(ctx)
|
|
30
|
+
returning: this.__serializeReturning(ctx),
|
|
32
31
|
};
|
|
33
|
-
let out = 'insert into ' + o.table + '\n\t(' +
|
|
34
|
-
o.columns + ')\n\bvalues\n\t(' + o.values + ')\b';
|
|
32
|
+
let out = 'insert into ' + o.table + '\n\t(' + o.columns + ')\n\bvalues\n\t(' + o.values + ')\b';
|
|
35
33
|
if (o.returning)
|
|
36
34
|
out += '\n' + o.returning;
|
|
37
35
|
return out;
|
package/cjs/query/query.js
CHANGED
|
@@ -26,7 +26,7 @@ class Query extends serializable_js_1.Serializable {
|
|
|
26
26
|
sql: (0, putil_flattentext_1.default)(sql, { noWrap: !ctx.prettyPrint }),
|
|
27
27
|
params: ctx.preparedParams,
|
|
28
28
|
paramOptions: ctx.paramOptions,
|
|
29
|
-
returningFields: ctx.returningFields
|
|
29
|
+
returningFields: ctx.returningFields,
|
|
30
30
|
};
|
|
31
31
|
}
|
|
32
32
|
values(obj) {
|
|
@@ -13,12 +13,13 @@ class ReturningQuery extends query_js_1.Query {
|
|
|
13
13
|
if (!columns)
|
|
14
14
|
return this;
|
|
15
15
|
// noinspection JSMismatchedCollectionQueryUpdate
|
|
16
|
-
this._returningColumns = columns.length
|
|
17
|
-
columns.reduce((a, v) => {
|
|
16
|
+
this._returningColumns = columns.length
|
|
17
|
+
? columns.reduce((a, v) => {
|
|
18
18
|
if (v)
|
|
19
19
|
a.push(new returning_column_js_1.ReturningColumn(v));
|
|
20
20
|
return a;
|
|
21
|
-
}, [])
|
|
21
|
+
}, [])
|
|
22
|
+
: undefined;
|
|
22
23
|
return this;
|
|
23
24
|
}
|
|
24
25
|
/**
|
|
@@ -142,7 +142,7 @@ class SelectQuery extends query_js_1.Query {
|
|
|
142
142
|
groupBy: this.__serializeGroupColumns(ctx),
|
|
143
143
|
orderBy: this.__serializeOrderColumns(ctx),
|
|
144
144
|
limit: this._limit,
|
|
145
|
-
offset: this._offset
|
|
145
|
+
offset: this._offset,
|
|
146
146
|
};
|
|
147
147
|
return ctx.serialize(this._type, o, () => {
|
|
148
148
|
let out = 'select';
|
|
@@ -151,15 +151,11 @@ class SelectQuery extends query_js_1.Query {
|
|
|
151
151
|
// columns part
|
|
152
152
|
/* istanbul ignore else */
|
|
153
153
|
if (o.columns) {
|
|
154
|
-
out +=
|
|
155
|
-
'\n\t' + o.columns + '\b' :
|
|
156
|
-
' ' + o.columns;
|
|
154
|
+
out += o.columns.indexOf('\n') >= 0 ? '\n\t' + o.columns + '\b' : ' ' + o.columns;
|
|
157
155
|
}
|
|
158
156
|
// from part
|
|
159
157
|
if (o.from) {
|
|
160
|
-
out += (o.columns.length > 60 ||
|
|
161
|
-
o.columns.indexOf('\n') >= 0 ? '\n' : ' ') +
|
|
162
|
-
o.from;
|
|
158
|
+
out += (o.columns.length > 60 || o.columns.indexOf('\n') >= 0 ? '\n' : ' ') + o.from;
|
|
163
159
|
}
|
|
164
160
|
// join part
|
|
165
161
|
if (o.join)
|
|
@@ -218,7 +214,7 @@ class SelectQuery extends query_js_1.Query {
|
|
|
218
214
|
}
|
|
219
215
|
return ctx.serialize(enums_js_1.SerializationType.SELECT_QUERY_FROM, arr, () => {
|
|
220
216
|
const s = arr.join(',');
|
|
221
|
-
return s ?
|
|
217
|
+
return s ? 'from' + (s.substring(0, 1) !== '\n' ? ' ' : '') + s : '';
|
|
222
218
|
});
|
|
223
219
|
}
|
|
224
220
|
/**
|
package/cjs/query/union-query.js
CHANGED
|
@@ -19,7 +19,7 @@ class UnionQuery extends query_js_1.Query {
|
|
|
19
19
|
const queries = this._queries.map(q => q._serialize(ctx));
|
|
20
20
|
const q = {
|
|
21
21
|
queries,
|
|
22
|
-
unionType: this._unionType
|
|
22
|
+
unionType: this._unionType,
|
|
23
23
|
};
|
|
24
24
|
return ctx.serialize(this._type, q, () => this.__defaultSerialize(ctx, q));
|
|
25
25
|
}
|
|
@@ -12,8 +12,7 @@ class UpdateQuery extends returning_query_js_1.ReturningQuery {
|
|
|
12
12
|
super();
|
|
13
13
|
if (!tableName || !(typeof tableName === 'string' || (0, typeguards_js_1.isRawStatement)(tableName)))
|
|
14
14
|
throw new TypeError('String or Raw instance required as first argument (tableName) for UpdateQuery');
|
|
15
|
-
if (!input || !((typeof input === 'object' && !Array.isArray(input)) ||
|
|
16
|
-
input.isSelect))
|
|
15
|
+
if (!input || !((typeof input === 'object' && !Array.isArray(input)) || input.isSelect))
|
|
17
16
|
throw new TypeError('Object or Raw instance required as second argument (input) for UpdateQuery');
|
|
18
17
|
this._table = typeof tableName === 'string' ? new table_name_js_1.TableName(tableName) : tableName;
|
|
19
18
|
this._input = input;
|
|
@@ -37,7 +36,7 @@ class UpdateQuery extends returning_query_js_1.ReturningQuery {
|
|
|
37
36
|
table: this._table._serialize(ctx),
|
|
38
37
|
values: this.__serializeValues(ctx),
|
|
39
38
|
where: this.__serializeWhere(ctx),
|
|
40
|
-
returning: this.__serializeReturning(ctx)
|
|
39
|
+
returning: this.__serializeReturning(ctx),
|
|
41
40
|
};
|
|
42
41
|
let out = 'update ' + o.table + ' set \n\t' + o.values + '\b';
|
|
43
42
|
if (o.where)
|
|
@@ -56,7 +55,7 @@ class UpdateQuery extends returning_query_js_1.ReturningQuery {
|
|
|
56
55
|
const value = ctx.anyToSQL(allValues[n]);
|
|
57
56
|
arr.push({
|
|
58
57
|
field: n,
|
|
59
|
-
value
|
|
58
|
+
value,
|
|
60
59
|
});
|
|
61
60
|
}
|
|
62
61
|
return ctx.serialize(enums_js_1.SerializationType.UPDATE_QUERY_VALUES, arr, () => {
|
package/cjs/serialize-context.js
CHANGED
|
@@ -8,16 +8,62 @@ const typeguards_js_1 = require("./typeguards.js");
|
|
|
8
8
|
class SerializeContext {
|
|
9
9
|
constructor(opts) {
|
|
10
10
|
this.reservedWords = [
|
|
11
|
-
'schema',
|
|
12
|
-
'
|
|
13
|
-
'
|
|
14
|
-
'
|
|
15
|
-
'
|
|
16
|
-
'
|
|
17
|
-
'
|
|
18
|
-
'
|
|
19
|
-
'
|
|
20
|
-
'
|
|
11
|
+
'schema',
|
|
12
|
+
'table',
|
|
13
|
+
'field',
|
|
14
|
+
'index',
|
|
15
|
+
'foreign',
|
|
16
|
+
'key',
|
|
17
|
+
'select',
|
|
18
|
+
'insert',
|
|
19
|
+
'update',
|
|
20
|
+
'delete',
|
|
21
|
+
'with',
|
|
22
|
+
'merge',
|
|
23
|
+
'join',
|
|
24
|
+
'inner',
|
|
25
|
+
'outer',
|
|
26
|
+
'left',
|
|
27
|
+
'right',
|
|
28
|
+
'full',
|
|
29
|
+
'from',
|
|
30
|
+
'where',
|
|
31
|
+
'order',
|
|
32
|
+
'by',
|
|
33
|
+
'group',
|
|
34
|
+
'having',
|
|
35
|
+
'acs',
|
|
36
|
+
'ascending',
|
|
37
|
+
'dsc',
|
|
38
|
+
'descending',
|
|
39
|
+
'distinct',
|
|
40
|
+
'and',
|
|
41
|
+
'or',
|
|
42
|
+
'not',
|
|
43
|
+
'between',
|
|
44
|
+
'null',
|
|
45
|
+
'like',
|
|
46
|
+
'ilike',
|
|
47
|
+
'count',
|
|
48
|
+
'sum',
|
|
49
|
+
'average',
|
|
50
|
+
'avg',
|
|
51
|
+
'cascade',
|
|
52
|
+
'authorization',
|
|
53
|
+
'create',
|
|
54
|
+
'add',
|
|
55
|
+
'drop',
|
|
56
|
+
'alter',
|
|
57
|
+
'index',
|
|
58
|
+
'private',
|
|
59
|
+
'sequence',
|
|
60
|
+
'default',
|
|
61
|
+
'constraint',
|
|
62
|
+
'references',
|
|
63
|
+
'primary',
|
|
64
|
+
'foreign',
|
|
65
|
+
'user',
|
|
66
|
+
'password',
|
|
21
67
|
];
|
|
22
68
|
if (opts)
|
|
23
69
|
Object.assign(this, opts);
|
|
@@ -55,9 +101,7 @@ class SerializeContext {
|
|
|
55
101
|
if (typeof v === 'object') {
|
|
56
102
|
if ((0, typeguards_js_1.isSerializable)(v)) {
|
|
57
103
|
const s = v._serialize(this);
|
|
58
|
-
return s ? ((0, typeguards_js_1.isQuery)(v) || (0, typeguards_js_1.isLogicalOperator)(v) ? '(' + s + ')' : s) :
|
|
59
|
-
/* istanbul ignore next */
|
|
60
|
-
'';
|
|
104
|
+
return s ? ((0, typeguards_js_1.isQuery)(v) || (0, typeguards_js_1.isLogicalOperator)(v) ? '(' + s + ')' : s) : /* istanbul ignore next */ '';
|
|
61
105
|
}
|
|
62
106
|
if (v instanceof Date) {
|
|
63
107
|
return this.serialize(enums_js_1.SerializationType.DATE_VALUE, v, () => this.dateToSQL(v));
|
|
@@ -81,7 +125,7 @@ class SerializeContext {
|
|
|
81
125
|
*
|
|
82
126
|
*/
|
|
83
127
|
stringToSQL(val) {
|
|
84
|
-
return '
|
|
128
|
+
return "'" + String(val).replace(/'/g, "''") + "'";
|
|
85
129
|
}
|
|
86
130
|
/**
|
|
87
131
|
*
|
|
@@ -108,10 +152,8 @@ class SerializeContext {
|
|
|
108
152
|
let str = y + '-' + (m <= 9 ? '0' + m : m) + '-' + (d <= 9 ? '0' + d : d);
|
|
109
153
|
/* istanbul ignore else */
|
|
110
154
|
if (h + n + s)
|
|
111
|
-
str += ' ' + (h <= 9 ? '0' + h : h) + ':' +
|
|
112
|
-
|
|
113
|
-
(s <= 9 ? '0' + s : s);
|
|
114
|
-
return '\'' + str + '\'';
|
|
155
|
+
str += ' ' + (h <= 9 ? '0' + h : h) + ':' + (n <= 9 ? '0' + n : n) + ':' + (s <= 9 ? '0' + s : s);
|
|
156
|
+
return "'" + str + "'";
|
|
115
157
|
}
|
|
116
158
|
/**
|
|
117
159
|
* Check if a string value is a reserved word
|
|
@@ -29,7 +29,7 @@ class CaseStatement extends serializable_js_1.Serializable {
|
|
|
29
29
|
if (this._condition)
|
|
30
30
|
this._expressions.push({
|
|
31
31
|
condition: this._condition,
|
|
32
|
-
value
|
|
32
|
+
value,
|
|
33
33
|
});
|
|
34
34
|
return this;
|
|
35
35
|
}
|
|
@@ -59,13 +59,12 @@ class CaseStatement extends serializable_js_1.Serializable {
|
|
|
59
59
|
return '';
|
|
60
60
|
const q = {
|
|
61
61
|
expressions: [],
|
|
62
|
-
elseValue: this._elseValue !== undefined ?
|
|
63
|
-
ctx.anyToSQL(this._elseValue) : undefined
|
|
62
|
+
elseValue: this._elseValue !== undefined ? ctx.anyToSQL(this._elseValue) : undefined,
|
|
64
63
|
};
|
|
65
64
|
for (const x of this._expressions) {
|
|
66
65
|
const o = {
|
|
67
66
|
condition: x.condition._serialize(ctx),
|
|
68
|
-
value: ctx.anyToSQL(x.value)
|
|
67
|
+
value: ctx.anyToSQL(x.value),
|
|
69
68
|
};
|
|
70
69
|
q.expressions.push(o);
|
|
71
70
|
}
|
|
@@ -37,8 +37,7 @@ class CoalesceStatement extends serializable_js_1.Serializable {
|
|
|
37
37
|
return ctx.serialize(this._type, q, () => this.__defaultSerialize(ctx, q));
|
|
38
38
|
}
|
|
39
39
|
__defaultSerialize(ctx, o) {
|
|
40
|
-
return 'coalesce(' + o.expressions.join(', ') + ')' +
|
|
41
|
-
(this._alias ? ' ' + this._alias : '');
|
|
40
|
+
return 'coalesce(' + o.expressions.join(', ') + ')' + (this._alias ? ' ' + this._alias : '');
|
|
42
41
|
}
|
|
43
42
|
}
|
|
44
43
|
exports.CoalesceStatement = CoalesceStatement;
|
|
@@ -39,14 +39,13 @@ class FieldExpression extends base_field_js_1.BaseField {
|
|
|
39
39
|
table: this._table,
|
|
40
40
|
field: this._field,
|
|
41
41
|
alias: this._alias,
|
|
42
|
-
isReservedWord: !!(this._field && ctx.isReservedWord(this._field))
|
|
42
|
+
isReservedWord: !!(this._field && ctx.isReservedWord(this._field)),
|
|
43
43
|
};
|
|
44
44
|
return ctx.serialize(this._type, o, () => {
|
|
45
|
-
const prefix = ctx.escapeReserved(this._schema ? this._schema + '.' : '') +
|
|
46
|
-
|
|
47
|
-
return prefix +
|
|
45
|
+
const prefix = ctx.escapeReserved(this._schema ? this._schema + '.' : '') + (this._table ? this._table + '.' : '');
|
|
46
|
+
return (prefix +
|
|
48
47
|
(!prefix && o.isReservedWord ? '"' + this._field + '"' : this._field) +
|
|
49
|
-
(this._alias ? ' as ' + this._alias : '');
|
|
48
|
+
(this._alias ? ' as ' + this._alias : ''));
|
|
50
49
|
});
|
|
51
50
|
}
|
|
52
51
|
}
|
|
@@ -26,12 +26,12 @@ class GroupColumn extends base_field_js_1.BaseField {
|
|
|
26
26
|
schema: this._schema,
|
|
27
27
|
table: this._table,
|
|
28
28
|
field: this._field,
|
|
29
|
-
isReservedWord: !!(this._field && ctx.isReservedWord(this._field))
|
|
29
|
+
isReservedWord: !!(this._field && ctx.isReservedWord(this._field)),
|
|
30
30
|
};
|
|
31
31
|
return ctx.serialize(this._type, o, () => {
|
|
32
|
-
return (this._schema ? this._schema + '.' : '') +
|
|
32
|
+
return ((this._schema ? this._schema + '.' : '') +
|
|
33
33
|
(this._table ? this._table + '.' : '') +
|
|
34
|
-
(o.isReservedWord ? '"' + this._field + '"' : this._field);
|
|
34
|
+
(o.isReservedWord ? '"' + this._field + '"' : this._field));
|
|
35
35
|
});
|
|
36
36
|
}
|
|
37
37
|
}
|
|
@@ -11,8 +11,7 @@ class JoinStatement extends serializable_js_1.Serializable {
|
|
|
11
11
|
super();
|
|
12
12
|
this._conditions = new op_and_js_1.OpAnd();
|
|
13
13
|
// noinspection SuspiciousTypeOfGuard
|
|
14
|
-
if (!((0, typeguards_js_1.isSelectQuery)(table) || (0, typeguards_js_1.isRawStatement)(table) || (0, typeguards_js_1.isTableName)(table) ||
|
|
15
|
-
typeof table === 'string'))
|
|
14
|
+
if (!((0, typeguards_js_1.isSelectQuery)(table) || (0, typeguards_js_1.isRawStatement)(table) || (0, typeguards_js_1.isTableName)(table) || typeof table === 'string'))
|
|
16
15
|
throw new TypeError('Table name, select query or raw object required for Join');
|
|
17
16
|
this._joinType = joinType;
|
|
18
17
|
this._table = typeof table === 'string' ? new table_name_js_1.TableName(table) : table;
|
|
@@ -28,7 +27,7 @@ class JoinStatement extends serializable_js_1.Serializable {
|
|
|
28
27
|
const o = {
|
|
29
28
|
joinType: this._joinType,
|
|
30
29
|
table: this._table._serialize(ctx),
|
|
31
|
-
conditions: this.__serializeConditions(ctx, this)
|
|
30
|
+
conditions: this.__serializeConditions(ctx, this),
|
|
32
31
|
};
|
|
33
32
|
return ctx.serialize(this._type, o, () => {
|
|
34
33
|
let out;
|
|
@@ -63,8 +62,7 @@ class JoinStatement extends serializable_js_1.Serializable {
|
|
|
63
62
|
const alias = this._table._alias;
|
|
64
63
|
if (!alias)
|
|
65
64
|
throw new Error('Alias required for sub-select in Join');
|
|
66
|
-
out += ' (' + (lf ? '\n\t' : '') + o.table + (lf ? '\n\b' : '') + ')' +
|
|
67
|
-
' ' + alias;
|
|
65
|
+
out += ' (' + (lf ? '\n\t' : '') + o.table + (lf ? '\n\b' : '') + ')' + ' ' + alias;
|
|
68
66
|
}
|
|
69
67
|
else
|
|
70
68
|
out += ' ' + o.table;
|
|
@@ -76,7 +74,7 @@ class JoinStatement extends serializable_js_1.Serializable {
|
|
|
76
74
|
__serializeConditions(ctx, join) {
|
|
77
75
|
if (join._conditions._items.length) {
|
|
78
76
|
const s = join._conditions._serialize(ctx);
|
|
79
|
-
return ctx.serialize(enums_js_1.SerializationType.JOIN_CONDITIONS, s, () => s ? 'on ' + s : '');
|
|
77
|
+
return ctx.serialize(enums_js_1.SerializationType.JOIN_CONDITIONS, s, () => (s ? 'on ' + s : ''));
|
|
80
78
|
}
|
|
81
79
|
return '';
|
|
82
80
|
}
|
|
@@ -32,8 +32,7 @@ class LowerStatement extends serializable_js_1.Serializable {
|
|
|
32
32
|
return ctx.serialize(this._type, q, () => this.__defaultSerialize(ctx, q));
|
|
33
33
|
}
|
|
34
34
|
__defaultSerialize(ctx, o) {
|
|
35
|
-
return 'lower(' + o + ')' +
|
|
36
|
-
(this._alias ? ' ' + this._alias : '');
|
|
35
|
+
return 'lower(' + o + ')' + (this._alias ? ' ' + this._alias : '');
|
|
37
36
|
}
|
|
38
37
|
}
|
|
39
38
|
exports.LowerStatement = LowerStatement;
|
|
@@ -32,8 +32,7 @@ class MaxStatement extends serializable_js_1.Serializable {
|
|
|
32
32
|
return ctx.serialize(this._type, q, () => this.__defaultSerialize(ctx, q));
|
|
33
33
|
}
|
|
34
34
|
__defaultSerialize(ctx, o) {
|
|
35
|
-
return 'max(' + o + ')' +
|
|
36
|
-
(this._alias ? ' ' + this._alias : '');
|
|
35
|
+
return 'max(' + o + ')' + (this._alias ? ' ' + this._alias : '');
|
|
37
36
|
}
|
|
38
37
|
}
|
|
39
38
|
exports.MaxStatement = MaxStatement;
|
|
@@ -32,8 +32,7 @@ class MinStatement extends serializable_js_1.Serializable {
|
|
|
32
32
|
return ctx.serialize(this._type, q, () => this.__defaultSerialize(ctx, q));
|
|
33
33
|
}
|
|
34
34
|
__defaultSerialize(ctx, o) {
|
|
35
|
-
return 'min(' + o + ')' +
|
|
36
|
-
(this._alias ? ' ' + this._alias : '');
|
|
35
|
+
return 'min(' + o + ')' + (this._alias ? ' ' + this._alias : '');
|
|
37
36
|
}
|
|
38
37
|
}
|
|
39
38
|
exports.MinStatement = MinStatement;
|
|
@@ -34,13 +34,12 @@ class CompOperator extends operator_js_1.Operator {
|
|
|
34
34
|
operatorType: this._operatorType,
|
|
35
35
|
symbol: this._symbol,
|
|
36
36
|
left,
|
|
37
|
-
right
|
|
37
|
+
right,
|
|
38
38
|
};
|
|
39
39
|
return this.__serialize(ctx, o);
|
|
40
40
|
}
|
|
41
41
|
__serializeItem(ctx, x, isRight) {
|
|
42
|
-
if (ctx.strictParams && !(x instanceof serializable_js_1.Serializable) &&
|
|
43
|
-
(typeof x !== 'string' || isRight)) {
|
|
42
|
+
if (ctx.strictParams && !(x instanceof serializable_js_1.Serializable) && (typeof x !== 'string' || isRight)) {
|
|
44
43
|
ctx.strictParamGenId = ctx.strictParamGenId || 0;
|
|
45
44
|
const name = 'P$_' + ++ctx.strictParamGenId;
|
|
46
45
|
ctx.params = ctx.params || {};
|
|
@@ -50,7 +49,7 @@ class CompOperator extends operator_js_1.Operator {
|
|
|
50
49
|
if (x instanceof serializable_js_1.Serializable) {
|
|
51
50
|
const expression = ctx.anyToSQL(x);
|
|
52
51
|
const result = {
|
|
53
|
-
expression
|
|
52
|
+
expression,
|
|
54
53
|
};
|
|
55
54
|
if (x instanceof field_expression_js_1.FieldExpression) {
|
|
56
55
|
result.dataType = result._dataType;
|
|
@@ -68,8 +67,7 @@ class CompOperator extends operator_js_1.Operator {
|
|
|
68
67
|
}
|
|
69
68
|
else {
|
|
70
69
|
const result = {
|
|
71
|
-
expression:
|
|
72
|
-
ctx.anyToSQL(x) : x
|
|
70
|
+
expression: isRight || typeof x !== 'string' ? ctx.anyToSQL(x) : x,
|
|
73
71
|
};
|
|
74
72
|
if (isRight || typeof x !== 'string')
|
|
75
73
|
result.isArray = Array.isArray(x);
|
|
@@ -50,7 +50,7 @@ class LogicalOperator extends operator_js_1.Operator {
|
|
|
50
50
|
}
|
|
51
51
|
return ctx.serialize(enums_js_1.SerializationType.LOGICAL_EXPRESSION, arr, () => {
|
|
52
52
|
const s = (0, helpers_js_1.printArray)(arr, ' ' + String(this._operatorType));
|
|
53
|
-
return
|
|
53
|
+
return s.indexOf('\n') > 0 ? s.replace('\n', '\n\t') + '\b' : s;
|
|
54
54
|
});
|
|
55
55
|
}
|
|
56
56
|
// noinspection JSMethodCanBeStatic
|
|
@@ -15,21 +15,17 @@ class OpBetween extends comp_operator_js_1.CompOperator {
|
|
|
15
15
|
if (!(this._right && this._right.length > 0))
|
|
16
16
|
return '';
|
|
17
17
|
const left = this.__serializeItem(ctx, this._left);
|
|
18
|
-
const right = [
|
|
19
|
-
this.__serializeItem(ctx, this._right[0], true),
|
|
20
|
-
this.__serializeItem(ctx, this._right[1], true)
|
|
21
|
-
];
|
|
18
|
+
const right = [this.__serializeItem(ctx, this._right[0], true), this.__serializeItem(ctx, this._right[1], true)];
|
|
22
19
|
const o = {
|
|
23
20
|
operatorType: this._operatorType,
|
|
24
21
|
symbol: this._symbol,
|
|
25
22
|
left,
|
|
26
|
-
right
|
|
23
|
+
right,
|
|
27
24
|
};
|
|
28
25
|
return this.__serialize(ctx, o);
|
|
29
26
|
}
|
|
30
27
|
__defaultSerialize(ctx, o) {
|
|
31
|
-
return o.left.expression + ' ' + o.symbol + ' ' +
|
|
32
|
-
o.right[0].expression + ' and ' + o.right[1].expression;
|
|
28
|
+
return o.left.expression + ' ' + o.symbol + ' ' + o.right[0].expression + ' and ' + o.right[1].expression;
|
|
33
29
|
}
|
|
34
30
|
}
|
|
35
31
|
exports.OpBetween = OpBetween;
|
|
@@ -17,7 +17,7 @@ class OrderColumn extends base_field_js_1.BaseField {
|
|
|
17
17
|
this._table = a.pop();
|
|
18
18
|
this._schema = a.pop();
|
|
19
19
|
}
|
|
20
|
-
this._descending = !!(
|
|
20
|
+
this._descending = !!(m[1] === '-' ||
|
|
21
21
|
(!m[1] && m[4] && ['dsc', 'desc', 'descending'].includes(m[4].toLowerCase())));
|
|
22
22
|
}
|
|
23
23
|
get _type() {
|
|
@@ -29,13 +29,13 @@ class OrderColumn extends base_field_js_1.BaseField {
|
|
|
29
29
|
table: this._table,
|
|
30
30
|
field: this._field,
|
|
31
31
|
descending: !!this._descending,
|
|
32
|
-
isReservedWord: !!(this._field && ctx.isReservedWord(this._field))
|
|
32
|
+
isReservedWord: !!(this._field && ctx.isReservedWord(this._field)),
|
|
33
33
|
};
|
|
34
34
|
return ctx.serialize(this._type, o, () => {
|
|
35
|
-
return (o.schema ? o.schema + '.' : '') +
|
|
35
|
+
return ((o.schema ? o.schema + '.' : '') +
|
|
36
36
|
(o.table ? o.table + '.' : '') +
|
|
37
37
|
(o.isReservedWord ? '"' + o.field + '"' : o.field) +
|
|
38
|
-
(o.descending ? ' desc' : '');
|
|
38
|
+
(o.descending ? ' desc' : ''));
|
|
39
39
|
});
|
|
40
40
|
}
|
|
41
41
|
}
|
|
@@ -41,8 +41,7 @@ class ParamExpression extends serializable_js_1.Serializable {
|
|
|
41
41
|
dataType: this._dataType,
|
|
42
42
|
isArray: this._isArray,
|
|
43
43
|
};
|
|
44
|
-
ctx.paramOptions = ctx.paramOptions ||
|
|
45
|
-
(Array.isArray(ctx.preparedParams) ? [] : {});
|
|
44
|
+
ctx.paramOptions = ctx.paramOptions || (Array.isArray(ctx.preparedParams) ? [] : {});
|
|
46
45
|
if (Array.isArray(ctx.paramOptions))
|
|
47
46
|
ctx.paramOptions.push(paramOps);
|
|
48
47
|
else
|
|
@@ -19,13 +19,12 @@ class ReturningColumn extends base_field_js_1.BaseField {
|
|
|
19
19
|
_serialize(ctx) {
|
|
20
20
|
const o = {
|
|
21
21
|
field: this._field,
|
|
22
|
-
alias: this._alias
|
|
22
|
+
alias: this._alias,
|
|
23
23
|
};
|
|
24
24
|
ctx.returningFields = ctx.returningFields || [];
|
|
25
25
|
ctx.returningFields.push(o);
|
|
26
26
|
return ctx.serialize(this._type, o, () => {
|
|
27
|
-
return ctx.escapeReserved(o.field) +
|
|
28
|
-
(o.alias ? ' as ' + ctx.escapeReserved(o.alias) : '');
|
|
27
|
+
return ctx.escapeReserved(o.field) + (o.alias ? ' as ' + ctx.escapeReserved(o.alias) : '');
|
|
29
28
|
});
|
|
30
29
|
}
|
|
31
30
|
}
|
|
@@ -36,13 +36,12 @@ class SequenceGetterStatement extends serializable_js_1.Serializable {
|
|
|
36
36
|
const q = {
|
|
37
37
|
genName: this._expression,
|
|
38
38
|
next: this._next,
|
|
39
|
-
alias: this._alias
|
|
39
|
+
alias: this._alias,
|
|
40
40
|
};
|
|
41
41
|
return ctx.serialize(this._type, q, () => this.__defaultSerialize(ctx, q));
|
|
42
42
|
}
|
|
43
43
|
__defaultSerialize(ctx, o) {
|
|
44
|
-
return (o.next ? 'nextval' : 'currval') +
|
|
45
|
-
(o.alias ? ' ' + o.alias : '');
|
|
44
|
+
return (o.next ? 'nextval' : 'currval') + "('" + o.genName + "')" + (o.alias ? ' ' + o.alias : '');
|
|
46
45
|
}
|
|
47
46
|
}
|
|
48
47
|
exports.SequenceGetterStatement = SequenceGetterStatement;
|