@sqb/builder 4.20.7 → 4.21.0
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/package.json +8 -24
- package/{types/sql-objects → sql-objects}/join-statement.d.ts +4 -4
- package/{types/typeguards.d.ts → typeguards.d.ts} +4 -3
- package/{esm/typeguards.js → typeguards.js} +4 -4
- package/cjs/classes.ns.js +0 -41
- package/cjs/enums.js +0 -102
- package/cjs/extensions.js +0 -38
- package/cjs/helpers.js +0 -30
- package/cjs/index.js +0 -25
- package/cjs/op.initializers.js +0 -163
- package/cjs/package.json +0 -3
- package/cjs/query/delete-query.js +0 -57
- package/cjs/query/insert-query.js +0 -86
- package/cjs/query/query.js +0 -41
- package/cjs/query/returning-query.js +0 -46
- package/cjs/query/select-query.js +0 -297
- package/cjs/query/union-query.js +0 -32
- package/cjs/query/update-query.js +0 -86
- package/cjs/serializable.js +0 -6
- package/cjs/serialize-context.js +0 -203
- package/cjs/sql-objects/base-field.js +0 -11
- package/cjs/sql-objects/case-statement.js +0 -91
- package/cjs/sql-objects/coalesce-statement.js +0 -48
- package/cjs/sql-objects/count-statement.js +0 -37
- package/cjs/sql-objects/expression.js +0 -10
- package/cjs/sql-objects/field-expression.js +0 -54
- package/cjs/sql-objects/group-column.js +0 -36
- package/cjs/sql-objects/join-statement.js +0 -94
- package/cjs/sql-objects/lower-statement.js +0 -40
- package/cjs/sql-objects/max-statement.js +0 -40
- package/cjs/sql-objects/min-statement.js +0 -40
- package/cjs/sql-objects/operator.js +0 -7
- package/cjs/sql-objects/operators/comp-operator.js +0 -89
- package/cjs/sql-objects/operators/logical-operator.js +0 -86
- package/cjs/sql-objects/operators/op-and.js +0 -9
- package/cjs/sql-objects/operators/op-between.js +0 -40
- package/cjs/sql-objects/operators/op-eq.js +0 -13
- package/cjs/sql-objects/operators/op-exists.js +0 -31
- package/cjs/sql-objects/operators/op-gt.js +0 -13
- package/cjs/sql-objects/operators/op-gte.js +0 -13
- package/cjs/sql-objects/operators/op-ilike.js +0 -10
- package/cjs/sql-objects/operators/op-in.js +0 -19
- package/cjs/sql-objects/operators/op-is-not.js +0 -13
- package/cjs/sql-objects/operators/op-is.js +0 -13
- package/cjs/sql-objects/operators/op-like.js +0 -20
- package/cjs/sql-objects/operators/op-lt.js +0 -13
- package/cjs/sql-objects/operators/op-lte.js +0 -13
- package/cjs/sql-objects/operators/op-ne.js +0 -13
- package/cjs/sql-objects/operators/op-not-between.js +0 -10
- package/cjs/sql-objects/operators/op-not-exists.js +0 -10
- package/cjs/sql-objects/operators/op-not-ilike.js +0 -10
- package/cjs/sql-objects/operators/op-not-in.js +0 -10
- package/cjs/sql-objects/operators/op-not-like.js +0 -10
- package/cjs/sql-objects/operators/op-not.js +0 -21
- package/cjs/sql-objects/operators/op-or.js +0 -9
- package/cjs/sql-objects/order-column.js +0 -43
- package/cjs/sql-objects/param-expression.js +0 -56
- package/cjs/sql-objects/raw-statement.js +0 -19
- package/cjs/sql-objects/returning-column.js +0 -31
- package/cjs/sql-objects/sequence-getter-statement.js +0 -54
- package/cjs/sql-objects/string-agg-statement.js +0 -88
- package/cjs/sql-objects/table-name.js +0 -35
- package/cjs/sql-objects/upper-statement.js +0 -40
- package/cjs/sqlobject.initializers.js +0 -141
- package/cjs/typeguards.js +0 -85
- package/cjs/types.js +0 -2
- package/esm/package.json +0 -3
- package/types/index.d.cts +0 -20
- /package/{types/classes.ns.d.ts → classes.ns.d.ts} +0 -0
- /package/{esm/classes.ns.js → classes.ns.js} +0 -0
- /package/{types/enums.d.ts → enums.d.ts} +0 -0
- /package/{esm/enums.js → enums.js} +0 -0
- /package/{types/extensions.d.ts → extensions.d.ts} +0 -0
- /package/{esm/extensions.js → extensions.js} +0 -0
- /package/{types/helpers.d.ts → helpers.d.ts} +0 -0
- /package/{esm/helpers.js → helpers.js} +0 -0
- /package/{types/index.d.ts → index.d.ts} +0 -0
- /package/{esm/index.js → index.js} +0 -0
- /package/{types/op.initializers.d.ts → op.initializers.d.ts} +0 -0
- /package/{esm/op.initializers.js → op.initializers.js} +0 -0
- /package/{types/query → query}/delete-query.d.ts +0 -0
- /package/{esm/query → query}/delete-query.js +0 -0
- /package/{types/query → query}/insert-query.d.ts +0 -0
- /package/{esm/query → query}/insert-query.js +0 -0
- /package/{types/query → query}/query.d.ts +0 -0
- /package/{esm/query → query}/query.js +0 -0
- /package/{types/query → query}/returning-query.d.ts +0 -0
- /package/{esm/query → query}/returning-query.js +0 -0
- /package/{types/query → query}/select-query.d.ts +0 -0
- /package/{esm/query → query}/select-query.js +0 -0
- /package/{types/query → query}/union-query.d.ts +0 -0
- /package/{esm/query → query}/union-query.js +0 -0
- /package/{types/query → query}/update-query.d.ts +0 -0
- /package/{esm/query → query}/update-query.js +0 -0
- /package/{types/serializable.d.ts → serializable.d.ts} +0 -0
- /package/{esm/serializable.js → serializable.js} +0 -0
- /package/{types/serialize-context.d.ts → serialize-context.d.ts} +0 -0
- /package/{esm/serialize-context.js → serialize-context.js} +0 -0
- /package/{types/sql-objects → sql-objects}/base-field.d.ts +0 -0
- /package/{esm/sql-objects → sql-objects}/base-field.js +0 -0
- /package/{types/sql-objects → sql-objects}/case-statement.d.ts +0 -0
- /package/{esm/sql-objects → sql-objects}/case-statement.js +0 -0
- /package/{types/sql-objects → sql-objects}/coalesce-statement.d.ts +0 -0
- /package/{esm/sql-objects → sql-objects}/coalesce-statement.js +0 -0
- /package/{types/sql-objects → sql-objects}/count-statement.d.ts +0 -0
- /package/{esm/sql-objects → sql-objects}/count-statement.js +0 -0
- /package/{types/sql-objects → sql-objects}/expression.d.ts +0 -0
- /package/{esm/sql-objects → sql-objects}/expression.js +0 -0
- /package/{types/sql-objects → sql-objects}/field-expression.d.ts +0 -0
- /package/{esm/sql-objects → sql-objects}/field-expression.js +0 -0
- /package/{types/sql-objects → sql-objects}/group-column.d.ts +0 -0
- /package/{esm/sql-objects → sql-objects}/group-column.js +0 -0
- /package/{esm/sql-objects → sql-objects}/join-statement.js +0 -0
- /package/{types/sql-objects → sql-objects}/lower-statement.d.ts +0 -0
- /package/{esm/sql-objects → sql-objects}/lower-statement.js +0 -0
- /package/{types/sql-objects → sql-objects}/max-statement.d.ts +0 -0
- /package/{esm/sql-objects → sql-objects}/max-statement.js +0 -0
- /package/{types/sql-objects → sql-objects}/min-statement.d.ts +0 -0
- /package/{esm/sql-objects → sql-objects}/min-statement.js +0 -0
- /package/{types/sql-objects → sql-objects}/operator.d.ts +0 -0
- /package/{esm/sql-objects → sql-objects}/operator.js +0 -0
- /package/{types/sql-objects → sql-objects}/operators/comp-operator.d.ts +0 -0
- /package/{esm/sql-objects → sql-objects}/operators/comp-operator.js +0 -0
- /package/{types/sql-objects → sql-objects}/operators/logical-operator.d.ts +0 -0
- /package/{esm/sql-objects → sql-objects}/operators/logical-operator.js +0 -0
- /package/{types/sql-objects → sql-objects}/operators/op-and.d.ts +0 -0
- /package/{esm/sql-objects → sql-objects}/operators/op-and.js +0 -0
- /package/{types/sql-objects → sql-objects}/operators/op-between.d.ts +0 -0
- /package/{esm/sql-objects → sql-objects}/operators/op-between.js +0 -0
- /package/{types/sql-objects → sql-objects}/operators/op-eq.d.ts +0 -0
- /package/{esm/sql-objects → sql-objects}/operators/op-eq.js +0 -0
- /package/{types/sql-objects → sql-objects}/operators/op-exists.d.ts +0 -0
- /package/{esm/sql-objects → sql-objects}/operators/op-exists.js +0 -0
- /package/{types/sql-objects → sql-objects}/operators/op-gt.d.ts +0 -0
- /package/{esm/sql-objects → sql-objects}/operators/op-gt.js +0 -0
- /package/{types/sql-objects → sql-objects}/operators/op-gte.d.ts +0 -0
- /package/{esm/sql-objects → sql-objects}/operators/op-gte.js +0 -0
- /package/{types/sql-objects → sql-objects}/operators/op-ilike.d.ts +0 -0
- /package/{esm/sql-objects → sql-objects}/operators/op-ilike.js +0 -0
- /package/{types/sql-objects → sql-objects}/operators/op-in.d.ts +0 -0
- /package/{esm/sql-objects → sql-objects}/operators/op-in.js +0 -0
- /package/{types/sql-objects → sql-objects}/operators/op-is-not.d.ts +0 -0
- /package/{esm/sql-objects → sql-objects}/operators/op-is-not.js +0 -0
- /package/{types/sql-objects → sql-objects}/operators/op-is.d.ts +0 -0
- /package/{esm/sql-objects → sql-objects}/operators/op-is.js +0 -0
- /package/{types/sql-objects → sql-objects}/operators/op-like.d.ts +0 -0
- /package/{esm/sql-objects → sql-objects}/operators/op-like.js +0 -0
- /package/{types/sql-objects → sql-objects}/operators/op-lt.d.ts +0 -0
- /package/{esm/sql-objects → sql-objects}/operators/op-lt.js +0 -0
- /package/{types/sql-objects → sql-objects}/operators/op-lte.d.ts +0 -0
- /package/{esm/sql-objects → sql-objects}/operators/op-lte.js +0 -0
- /package/{types/sql-objects → sql-objects}/operators/op-ne.d.ts +0 -0
- /package/{esm/sql-objects → sql-objects}/operators/op-ne.js +0 -0
- /package/{types/sql-objects → sql-objects}/operators/op-not-between.d.ts +0 -0
- /package/{esm/sql-objects → sql-objects}/operators/op-not-between.js +0 -0
- /package/{types/sql-objects → sql-objects}/operators/op-not-exists.d.ts +0 -0
- /package/{esm/sql-objects → sql-objects}/operators/op-not-exists.js +0 -0
- /package/{types/sql-objects → sql-objects}/operators/op-not-ilike.d.ts +0 -0
- /package/{esm/sql-objects → sql-objects}/operators/op-not-ilike.js +0 -0
- /package/{types/sql-objects → sql-objects}/operators/op-not-in.d.ts +0 -0
- /package/{esm/sql-objects → sql-objects}/operators/op-not-in.js +0 -0
- /package/{types/sql-objects → sql-objects}/operators/op-not-like.d.ts +0 -0
- /package/{esm/sql-objects → sql-objects}/operators/op-not-like.js +0 -0
- /package/{types/sql-objects → sql-objects}/operators/op-not.d.ts +0 -0
- /package/{esm/sql-objects → sql-objects}/operators/op-not.js +0 -0
- /package/{types/sql-objects → sql-objects}/operators/op-or.d.ts +0 -0
- /package/{esm/sql-objects → sql-objects}/operators/op-or.js +0 -0
- /package/{types/sql-objects → sql-objects}/order-column.d.ts +0 -0
- /package/{esm/sql-objects → sql-objects}/order-column.js +0 -0
- /package/{types/sql-objects → sql-objects}/param-expression.d.ts +0 -0
- /package/{esm/sql-objects → sql-objects}/param-expression.js +0 -0
- /package/{types/sql-objects → sql-objects}/raw-statement.d.ts +0 -0
- /package/{esm/sql-objects → sql-objects}/raw-statement.js +0 -0
- /package/{types/sql-objects → sql-objects}/returning-column.d.ts +0 -0
- /package/{esm/sql-objects → sql-objects}/returning-column.js +0 -0
- /package/{types/sql-objects → sql-objects}/sequence-getter-statement.d.ts +0 -0
- /package/{esm/sql-objects → sql-objects}/sequence-getter-statement.js +0 -0
- /package/{types/sql-objects → sql-objects}/string-agg-statement.d.ts +0 -0
- /package/{esm/sql-objects → sql-objects}/string-agg-statement.js +0 -0
- /package/{types/sql-objects → sql-objects}/table-name.d.ts +0 -0
- /package/{esm/sql-objects → sql-objects}/table-name.js +0 -0
- /package/{types/sql-objects → sql-objects}/upper-statement.d.ts +0 -0
- /package/{esm/sql-objects → sql-objects}/upper-statement.js +0 -0
- /package/{types/sqlobject.initializers.d.ts → sqlobject.initializers.d.ts} +0 -0
- /package/{esm/sqlobject.initializers.js → sqlobject.initializers.js} +0 -0
- /package/{types/types.d.ts → types.d.ts} +0 -0
- /package/{esm/types.js → types.js} +0 -0
package/cjs/query/query.js
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Query = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const events_1 = require("events");
|
|
6
|
-
const putil_flattentext_1 = tslib_1.__importDefault(require("putil-flattentext"));
|
|
7
|
-
const putil_merge_1 = tslib_1.__importDefault(require("putil-merge"));
|
|
8
|
-
const serializable_js_1 = require("../serializable.js");
|
|
9
|
-
const serialize_context_js_1 = require("../serialize-context.js");
|
|
10
|
-
class Query extends serializable_js_1.Serializable {
|
|
11
|
-
_params;
|
|
12
|
-
constructor() {
|
|
13
|
-
super();
|
|
14
|
-
events_1.EventEmitter.call(this);
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Generates Sql script
|
|
18
|
-
*/
|
|
19
|
-
generate(options) {
|
|
20
|
-
const ctx = new serialize_context_js_1.SerializeContext(options);
|
|
21
|
-
if (this._params)
|
|
22
|
-
ctx.params = { ...ctx.params, ...this._params };
|
|
23
|
-
ctx.serializeHooks = this.listeners('serialize');
|
|
24
|
-
/* generate output */
|
|
25
|
-
const sql = this._serialize(ctx);
|
|
26
|
-
return {
|
|
27
|
-
sql: (0, putil_flattentext_1.default)(sql, { noWrap: !ctx.prettyPrint }),
|
|
28
|
-
params: ctx.preparedParams,
|
|
29
|
-
paramOptions: ctx.paramOptions,
|
|
30
|
-
returningFields: ctx.returningFields,
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
values(obj) {
|
|
34
|
-
if (typeof obj !== 'object' || Array.isArray(obj))
|
|
35
|
-
throw new TypeError('Invalid argument');
|
|
36
|
-
this._params = obj;
|
|
37
|
-
return this;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
exports.Query = Query;
|
|
41
|
-
(0, putil_merge_1.default)(Query.prototype, events_1.EventEmitter.prototype, { descriptor: true });
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ReturningQuery = void 0;
|
|
4
|
-
const enums_js_1 = require("../enums.js");
|
|
5
|
-
const helpers_js_1 = require("../helpers.js");
|
|
6
|
-
const returning_column_js_1 = require("../sql-objects/returning-column.js");
|
|
7
|
-
const query_js_1 = require("./query.js");
|
|
8
|
-
class ReturningQuery extends query_js_1.Query {
|
|
9
|
-
_returningColumns;
|
|
10
|
-
/**
|
|
11
|
-
*
|
|
12
|
-
*/
|
|
13
|
-
returning(...columns) {
|
|
14
|
-
if (!columns)
|
|
15
|
-
return this;
|
|
16
|
-
// noinspection JSMismatchedCollectionQueryUpdate
|
|
17
|
-
this._returningColumns = columns.length
|
|
18
|
-
? columns.reduce((a, v) => {
|
|
19
|
-
if (v)
|
|
20
|
-
a.push(new returning_column_js_1.ReturningColumn(v));
|
|
21
|
-
return a;
|
|
22
|
-
}, [])
|
|
23
|
-
: undefined;
|
|
24
|
-
return this;
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
*
|
|
28
|
-
*/
|
|
29
|
-
__serializeReturning(ctx) {
|
|
30
|
-
if (!(this._returningColumns && this._returningColumns.length))
|
|
31
|
-
return '';
|
|
32
|
-
const arr = [];
|
|
33
|
-
ctx.returningFields = [];
|
|
34
|
-
for (const t of this._returningColumns) {
|
|
35
|
-
const s = t._serialize(ctx);
|
|
36
|
-
/* istanbul ignore else */
|
|
37
|
-
if (s)
|
|
38
|
-
arr.push(s);
|
|
39
|
-
}
|
|
40
|
-
return ctx.serialize(enums_js_1.SerializationType.RETURNING_BLOCK, arr, () => {
|
|
41
|
-
const s = (0, helpers_js_1.printArray)(arr);
|
|
42
|
-
return s ? 'returning ' + s : '';
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
exports.ReturningQuery = ReturningQuery;
|
|
@@ -1,297 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SelectQuery = void 0;
|
|
4
|
-
const putil_varhelpers_1 = require("putil-varhelpers");
|
|
5
|
-
const enums_js_1 = require("../enums.js");
|
|
6
|
-
const helpers_js_1 = require("../helpers.js");
|
|
7
|
-
const field_expression_js_1 = require("../sql-objects/field-expression.js");
|
|
8
|
-
const group_column_js_1 = require("../sql-objects/group-column.js");
|
|
9
|
-
const op_and_js_1 = require("../sql-objects/operators/op-and.js");
|
|
10
|
-
const order_column_js_1 = require("../sql-objects/order-column.js");
|
|
11
|
-
const table_name_js_1 = require("../sql-objects/table-name.js");
|
|
12
|
-
const typeguards_js_1 = require("../typeguards.js");
|
|
13
|
-
const query_js_1 = require("./query.js");
|
|
14
|
-
class SelectQuery extends query_js_1.Query {
|
|
15
|
-
_tables;
|
|
16
|
-
_columns;
|
|
17
|
-
_joins;
|
|
18
|
-
_where;
|
|
19
|
-
_groupBy;
|
|
20
|
-
_orderBy;
|
|
21
|
-
_limit;
|
|
22
|
-
_offset;
|
|
23
|
-
_alias;
|
|
24
|
-
_distinct;
|
|
25
|
-
constructor(...column) {
|
|
26
|
-
super();
|
|
27
|
-
if (column.length)
|
|
28
|
-
this.addColumn(...column);
|
|
29
|
-
}
|
|
30
|
-
get _type() {
|
|
31
|
-
return enums_js_1.SerializationType.SELECT_QUERY;
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Adds columns to query.
|
|
35
|
-
*/
|
|
36
|
-
addColumn(...column) {
|
|
37
|
-
const self = this;
|
|
38
|
-
this._columns = this._columns || [];
|
|
39
|
-
for (const arg of column) {
|
|
40
|
-
if (!arg)
|
|
41
|
-
continue;
|
|
42
|
-
if (Array.isArray(arg))
|
|
43
|
-
self.addColumn(...arg);
|
|
44
|
-
else
|
|
45
|
-
this._columns.push((0, typeguards_js_1.isSerializable)(arg) ? arg : new field_expression_js_1.FieldExpression(arg));
|
|
46
|
-
}
|
|
47
|
-
return this;
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Defines "from" part of query.
|
|
51
|
-
*/
|
|
52
|
-
from(...table) {
|
|
53
|
-
this._tables = [];
|
|
54
|
-
for (const arg of table) {
|
|
55
|
-
if (!arg)
|
|
56
|
-
continue;
|
|
57
|
-
this._tables.push(typeof arg === 'string' ? new table_name_js_1.TableName(arg) : arg);
|
|
58
|
-
}
|
|
59
|
-
return this;
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Adds "join" statements to query
|
|
63
|
-
*/
|
|
64
|
-
join(...join) {
|
|
65
|
-
this._joins = this._joins || [];
|
|
66
|
-
for (const arg of join) {
|
|
67
|
-
if (!arg)
|
|
68
|
-
continue;
|
|
69
|
-
if (!(0, typeguards_js_1.isJoinStatement)(arg))
|
|
70
|
-
throw new TypeError('Join statement required');
|
|
71
|
-
this._joins.push(arg);
|
|
72
|
-
}
|
|
73
|
-
return this;
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Defines "where" part of query
|
|
77
|
-
*/
|
|
78
|
-
where(...condition) {
|
|
79
|
-
this._where = this._where || new op_and_js_1.OpAnd();
|
|
80
|
-
this._where.add(...condition);
|
|
81
|
-
return this;
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* Defines "where" part of query
|
|
85
|
-
*/
|
|
86
|
-
groupBy(...field) {
|
|
87
|
-
this._groupBy = this._groupBy || [];
|
|
88
|
-
for (const arg of field) {
|
|
89
|
-
if (!arg)
|
|
90
|
-
continue;
|
|
91
|
-
this._groupBy.push(typeof arg === 'string' ? new group_column_js_1.GroupColumn(arg) : arg);
|
|
92
|
-
}
|
|
93
|
-
return this;
|
|
94
|
-
}
|
|
95
|
-
/**
|
|
96
|
-
* Defines "order by" part of query.
|
|
97
|
-
*/
|
|
98
|
-
orderBy(...field) {
|
|
99
|
-
this._orderBy = this._orderBy || [];
|
|
100
|
-
for (const arg of field) {
|
|
101
|
-
if (!arg)
|
|
102
|
-
continue;
|
|
103
|
-
this._orderBy.push(typeof arg === 'string' ? new order_column_js_1.OrderColumn(arg) : arg);
|
|
104
|
-
}
|
|
105
|
-
return this;
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* Sets alias for sub-select queries
|
|
109
|
-
*/
|
|
110
|
-
as(alias) {
|
|
111
|
-
this._alias = alias;
|
|
112
|
-
return this;
|
|
113
|
-
}
|
|
114
|
-
/**
|
|
115
|
-
* Sets limit for query
|
|
116
|
-
*/
|
|
117
|
-
limit(limit) {
|
|
118
|
-
this._limit = (0, putil_varhelpers_1.coerceToInt)(limit);
|
|
119
|
-
return this;
|
|
120
|
-
}
|
|
121
|
-
/**
|
|
122
|
-
* Sets offset for query
|
|
123
|
-
*/
|
|
124
|
-
offset(offset) {
|
|
125
|
-
this._offset = (0, putil_varhelpers_1.coerceToInt)(offset);
|
|
126
|
-
return this;
|
|
127
|
-
}
|
|
128
|
-
/**
|
|
129
|
-
* Enables distinct mode
|
|
130
|
-
*/
|
|
131
|
-
distinct() {
|
|
132
|
-
this._distinct = true;
|
|
133
|
-
return this;
|
|
134
|
-
}
|
|
135
|
-
onFetch(listener) {
|
|
136
|
-
this.on('fetch', listener);
|
|
137
|
-
return this;
|
|
138
|
-
}
|
|
139
|
-
onceFetch(listener) {
|
|
140
|
-
this.once('fetch', listener);
|
|
141
|
-
return this;
|
|
142
|
-
}
|
|
143
|
-
/**
|
|
144
|
-
* Performs serialization
|
|
145
|
-
*/
|
|
146
|
-
_serialize(ctx) {
|
|
147
|
-
const o = {
|
|
148
|
-
columns: this.__serializeSelectColumns(ctx),
|
|
149
|
-
from: this.__serializeFrom(ctx),
|
|
150
|
-
join: this.__serializeJoins(ctx),
|
|
151
|
-
where: this.__serializeWhere(ctx),
|
|
152
|
-
groupBy: this.__serializeGroupColumns(ctx),
|
|
153
|
-
orderBy: this.__serializeOrderColumns(ctx),
|
|
154
|
-
limit: this._limit,
|
|
155
|
-
offset: this._offset,
|
|
156
|
-
};
|
|
157
|
-
return ctx.serialize(this._type, o, () => {
|
|
158
|
-
let out = 'select';
|
|
159
|
-
if (this._distinct)
|
|
160
|
-
out += ' distinct';
|
|
161
|
-
// columns part
|
|
162
|
-
/* istanbul ignore else */
|
|
163
|
-
if (o.columns) {
|
|
164
|
-
out +=
|
|
165
|
-
o.columns.indexOf('\n') >= 0
|
|
166
|
-
? '\n\t' + o.columns + '\b'
|
|
167
|
-
: ' ' + o.columns;
|
|
168
|
-
}
|
|
169
|
-
// from part
|
|
170
|
-
if (o.from) {
|
|
171
|
-
out +=
|
|
172
|
-
(o.columns.length > 60 || o.columns.indexOf('\n') >= 0 ? '\n' : ' ') +
|
|
173
|
-
o.from;
|
|
174
|
-
}
|
|
175
|
-
// join part
|
|
176
|
-
if (o.join)
|
|
177
|
-
out += '\n' + o.join;
|
|
178
|
-
// where part
|
|
179
|
-
if (o.where)
|
|
180
|
-
out += '\n' + o.where;
|
|
181
|
-
// group by part
|
|
182
|
-
if (o.groupBy)
|
|
183
|
-
out += '\n' + o.groupBy;
|
|
184
|
-
// order by part
|
|
185
|
-
if (o.orderBy)
|
|
186
|
-
out += '\n' + o.orderBy;
|
|
187
|
-
return out;
|
|
188
|
-
});
|
|
189
|
-
}
|
|
190
|
-
/**
|
|
191
|
-
*
|
|
192
|
-
*/
|
|
193
|
-
__serializeSelectColumns(ctx) {
|
|
194
|
-
const arr = [];
|
|
195
|
-
if (this._columns) {
|
|
196
|
-
for (const t of this._columns) {
|
|
197
|
-
const s = ctx.anyToSQL(t);
|
|
198
|
-
// t._serialize(ctx);
|
|
199
|
-
if (s) {
|
|
200
|
-
if (t instanceof SelectQuery) {
|
|
201
|
-
if (!t._alias)
|
|
202
|
-
throw new TypeError('Alias required for sub-select in columns');
|
|
203
|
-
arr.push(s + ' ' + t._alias);
|
|
204
|
-
}
|
|
205
|
-
else
|
|
206
|
-
arr.push(s);
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
return ctx.serialize(enums_js_1.SerializationType.SELECT_QUERY_COLUMNS, arr, () => (0, helpers_js_1.printArray)(arr) || '*');
|
|
211
|
-
}
|
|
212
|
-
/**
|
|
213
|
-
*
|
|
214
|
-
*/
|
|
215
|
-
__serializeFrom(ctx) {
|
|
216
|
-
const arr = [];
|
|
217
|
-
if (this._tables) {
|
|
218
|
-
for (const t of this._tables) {
|
|
219
|
-
const s = t._serialize(ctx);
|
|
220
|
-
/* istanbul ignore else */
|
|
221
|
-
if (s) {
|
|
222
|
-
if (t instanceof SelectQuery) {
|
|
223
|
-
if (!t._alias)
|
|
224
|
-
throw new TypeError('Alias required for sub-select in "from"');
|
|
225
|
-
arr.push('\n\t(' + s + ') ' + t._alias);
|
|
226
|
-
}
|
|
227
|
-
else
|
|
228
|
-
arr.push(s);
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
return ctx.serialize(enums_js_1.SerializationType.SELECT_QUERY_FROM, arr, () => {
|
|
233
|
-
const s = arr.join(',');
|
|
234
|
-
return s ? 'from' + (s.substring(0, 1) !== '\n' ? ' ' : '') + s : '';
|
|
235
|
-
});
|
|
236
|
-
}
|
|
237
|
-
/**
|
|
238
|
-
*
|
|
239
|
-
*/
|
|
240
|
-
__serializeJoins(ctx) {
|
|
241
|
-
const arr = [];
|
|
242
|
-
if (this._joins) {
|
|
243
|
-
for (const t of this._joins) {
|
|
244
|
-
const s = t._serialize(ctx);
|
|
245
|
-
/* istanbul ignore else */
|
|
246
|
-
if (s)
|
|
247
|
-
arr.push(s);
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
return ctx.serialize(enums_js_1.SerializationType.SELECT_QUERY_JOIN, arr, () => arr.join('\n'));
|
|
251
|
-
}
|
|
252
|
-
/**
|
|
253
|
-
*
|
|
254
|
-
*/
|
|
255
|
-
__serializeWhere(ctx) {
|
|
256
|
-
if (!this._where)
|
|
257
|
-
return '';
|
|
258
|
-
const s = this._where._serialize(ctx);
|
|
259
|
-
return ctx.serialize(enums_js_1.SerializationType.CONDITIONS_BLOCK, s, () =>
|
|
260
|
-
/* istanbul ignore next */
|
|
261
|
-
s ? 'where ' + s : '');
|
|
262
|
-
}
|
|
263
|
-
/**
|
|
264
|
-
*
|
|
265
|
-
*/
|
|
266
|
-
__serializeGroupColumns(ctx) {
|
|
267
|
-
const arr = [];
|
|
268
|
-
if (this._groupBy) {
|
|
269
|
-
for (const t of this._groupBy) {
|
|
270
|
-
const s = t._serialize(ctx);
|
|
271
|
-
/* istanbul ignore else */
|
|
272
|
-
if (s)
|
|
273
|
-
arr.push(s);
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
return ctx.serialize(enums_js_1.SerializationType.SELECT_QUERY_GROUPBY, arr, () => {
|
|
277
|
-
const s = (0, helpers_js_1.printArray)(arr);
|
|
278
|
-
return s ? 'group by ' + s : '';
|
|
279
|
-
});
|
|
280
|
-
}
|
|
281
|
-
__serializeOrderColumns(ctx) {
|
|
282
|
-
const arr = [];
|
|
283
|
-
if (this._orderBy) {
|
|
284
|
-
for (const t of this._orderBy) {
|
|
285
|
-
const s = t._serialize(ctx);
|
|
286
|
-
/* istanbul ignore else */
|
|
287
|
-
if (s)
|
|
288
|
-
arr.push(s);
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
return ctx.serialize(enums_js_1.SerializationType.SELECT_QUERY_ORDERBY, arr, () => {
|
|
292
|
-
const s = (0, helpers_js_1.printArray)(arr);
|
|
293
|
-
return s ? 'order by ' + s : '';
|
|
294
|
-
});
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
exports.SelectQuery = SelectQuery;
|
package/cjs/query/union-query.js
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.UnionQuery = void 0;
|
|
4
|
-
const enums_js_1 = require("../enums.js");
|
|
5
|
-
const query_js_1 = require("./query.js");
|
|
6
|
-
class UnionQuery extends query_js_1.Query {
|
|
7
|
-
_queries;
|
|
8
|
-
_unionType;
|
|
9
|
-
constructor(queries, unionType) {
|
|
10
|
-
super();
|
|
11
|
-
this._queries = queries;
|
|
12
|
-
this._unionType = unionType;
|
|
13
|
-
}
|
|
14
|
-
get _type() {
|
|
15
|
-
return enums_js_1.SerializationType.UNION_QUERY;
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* Performs serialization
|
|
19
|
-
*/
|
|
20
|
-
_serialize(ctx) {
|
|
21
|
-
const queries = this._queries.map(q => q._serialize(ctx));
|
|
22
|
-
const q = {
|
|
23
|
-
queries,
|
|
24
|
-
unionType: this._unionType,
|
|
25
|
-
};
|
|
26
|
-
return ctx.serialize(this._type, q, () => this.__defaultSerialize(ctx, q));
|
|
27
|
-
}
|
|
28
|
-
__defaultSerialize(ctx, o) {
|
|
29
|
-
return o.queries.join(o.unionType === 'all' ? '\nUNION ALL\n' : '\nUNION\n');
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
exports.UnionQuery = UnionQuery;
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.UpdateQuery = void 0;
|
|
4
|
-
const enums_js_1 = require("../enums.js");
|
|
5
|
-
const helpers_js_1 = require("../helpers.js");
|
|
6
|
-
const op_and_js_1 = require("../sql-objects/operators/op-and.js");
|
|
7
|
-
const table_name_js_1 = require("../sql-objects/table-name.js");
|
|
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 {
|
|
11
|
-
_table;
|
|
12
|
-
_input;
|
|
13
|
-
_where;
|
|
14
|
-
constructor(tableName, input) {
|
|
15
|
-
super();
|
|
16
|
-
if (!tableName ||
|
|
17
|
-
!(typeof tableName === 'string' || (0, typeguards_js_1.isRawStatement)(tableName))) {
|
|
18
|
-
throw new TypeError('String or Raw instance required as first argument (tableName) for UpdateQuery');
|
|
19
|
-
}
|
|
20
|
-
if (!input ||
|
|
21
|
-
!((typeof input === 'object' && !Array.isArray(input)) || input.isSelect)) {
|
|
22
|
-
throw new TypeError('Object or Raw instance required as second argument (input) for UpdateQuery');
|
|
23
|
-
}
|
|
24
|
-
this._table =
|
|
25
|
-
typeof tableName === 'string' ? new table_name_js_1.TableName(tableName) : tableName;
|
|
26
|
-
this._input = input;
|
|
27
|
-
}
|
|
28
|
-
get _type() {
|
|
29
|
-
return enums_js_1.SerializationType.UPDATE_QUERY;
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Defines "where" part of query
|
|
33
|
-
*/
|
|
34
|
-
where(...operator) {
|
|
35
|
-
this._where = this._where || new op_and_js_1.OpAnd();
|
|
36
|
-
this._where.add(...operator);
|
|
37
|
-
return this;
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Performs serialization
|
|
41
|
-
*/
|
|
42
|
-
_serialize(ctx) {
|
|
43
|
-
const o = {
|
|
44
|
-
table: this._table._serialize(ctx),
|
|
45
|
-
values: this.__serializeValues(ctx),
|
|
46
|
-
where: this.__serializeWhere(ctx),
|
|
47
|
-
returning: this.__serializeReturning(ctx),
|
|
48
|
-
};
|
|
49
|
-
let out = 'update ' + o.table + ' set \n\t' + o.values + '\b';
|
|
50
|
-
if (o.where)
|
|
51
|
-
out += '\n' + o.where;
|
|
52
|
-
if (o.returning)
|
|
53
|
-
out += '\n' + o.returning;
|
|
54
|
-
return out;
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
*
|
|
58
|
-
*/
|
|
59
|
-
__serializeValues(ctx) {
|
|
60
|
-
const arr = [];
|
|
61
|
-
const allValues = this._input;
|
|
62
|
-
for (const n of Object.getOwnPropertyNames(allValues)) {
|
|
63
|
-
const value = ctx.anyToSQL(allValues[n]);
|
|
64
|
-
arr.push({
|
|
65
|
-
field: n,
|
|
66
|
-
value,
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
return ctx.serialize(enums_js_1.SerializationType.UPDATE_QUERY_VALUES, arr, () => {
|
|
70
|
-
const a = arr.map(o => o.field + ' = ' + o.value);
|
|
71
|
-
return (0, helpers_js_1.printArray)(a, ',');
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
*
|
|
76
|
-
*/
|
|
77
|
-
__serializeWhere(ctx) {
|
|
78
|
-
if (!this._where)
|
|
79
|
-
return '';
|
|
80
|
-
const s = this._where._serialize(ctx);
|
|
81
|
-
return ctx.serialize(enums_js_1.SerializationType.CONDITIONS_BLOCK, s, () =>
|
|
82
|
-
/* istanbul ignore next */
|
|
83
|
-
s ? 'where ' + s : '');
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
exports.UpdateQuery = UpdateQuery;
|