@sqb/builder 4.1.5 → 4.5.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/README.md +2 -2
- package/cjs/classes.ns.js +41 -0
- package/{dist → cjs}/enums.js +7 -0
- package/{dist → cjs}/extensions.js +0 -0
- package/{dist → cjs}/helpers.js +0 -0
- package/cjs/index.js +27 -0
- package/{dist → cjs}/op.initializers.js +42 -42
- package/cjs/package.json +3 -0
- package/{dist/query/DeleteQuery.js → cjs/query/delete-query.js} +13 -11
- package/{dist/query/InsertQuery.js → cjs/query/insert-query.js} +17 -16
- package/{dist/query/Query.js → cjs/query/query.js} +5 -4
- package/{dist/query/ReturningQuery.js → cjs/query/returning-query.js} +9 -8
- package/cjs/query/select-query.js +294 -0
- package/{dist/query/UpdateQuery.js → cjs/query/update-query.js} +18 -15
- package/{dist/Serializable.js → cjs/serializable.js} +0 -0
- package/{dist/SerializeContext.js → cjs/serialize-context.js} +37 -26
- package/cjs/sql-objects/base-field.js +11 -0
- package/{dist/sql-objects/CaseStatement.js → cjs/sql-objects/case-statement.js} +10 -6
- package/cjs/sql-objects/coalesce-statement.js +46 -0
- package/{dist/sql-objects/CountStatement.js → cjs/sql-objects/count-statement.js} +5 -4
- package/cjs/sql-objects/expression.js +10 -0
- package/{dist/sql-objects/FieldExpression.js → cjs/sql-objects/field-expression.js} +5 -4
- package/{dist/sql-objects/GroupColumn.js → cjs/sql-objects/group-column.js} +4 -4
- package/{dist/sql-objects/JoinStatement.js → cjs/sql-objects/join-statement.js} +20 -18
- package/cjs/sql-objects/lower-statement.js +41 -0
- package/cjs/sql-objects/max-statement.js +41 -0
- package/cjs/sql-objects/min-statement.js +41 -0
- package/{dist/sql-objects/Operator.js → cjs/sql-objects/operator.js} +2 -2
- package/{dist/sql-objects/operators/CompOperator.js → cjs/sql-objects/operators/comp-operator.js} +19 -16
- package/{dist/sql-objects/operators/LogicalOperator.js → cjs/sql-objects/operators/logical-operator.js} +14 -13
- package/cjs/sql-objects/operators/op-and.js +9 -0
- package/{dist/sql-objects/operators/OpBetween.js → cjs/sql-objects/operators/op-between.js} +5 -5
- package/cjs/sql-objects/operators/op-eq.js +13 -0
- package/{dist/sql-objects/operators/OpExists.js → cjs/sql-objects/operators/op-exists.js} +7 -7
- package/cjs/sql-objects/operators/op-gt.js +13 -0
- package/cjs/sql-objects/operators/op-gte.js +13 -0
- package/cjs/sql-objects/operators/op-ilike.js +10 -0
- package/cjs/sql-objects/operators/op-in.js +19 -0
- package/cjs/sql-objects/operators/op-is-not.js +13 -0
- package/cjs/sql-objects/operators/op-is.js +13 -0
- package/{dist/sql-objects/operators/OpLike.js → cjs/sql-objects/operators/op-like.js} +7 -7
- package/cjs/sql-objects/operators/op-lt.js +13 -0
- package/cjs/sql-objects/operators/op-lte.js +13 -0
- package/cjs/sql-objects/operators/op-ne.js +13 -0
- package/cjs/sql-objects/operators/op-not-between.js +10 -0
- package/cjs/sql-objects/operators/op-not-exists.js +10 -0
- package/cjs/sql-objects/operators/op-not-ilike.js +10 -0
- package/cjs/sql-objects/operators/op-not-in.js +10 -0
- package/cjs/sql-objects/operators/op-not-like.js +10 -0
- package/cjs/sql-objects/operators/op-or.js +9 -0
- package/{dist/sql-objects/OrderColumn.js → cjs/sql-objects/order-column.js} +5 -4
- package/{dist/sql-objects/ParamExpression.js → cjs/sql-objects/param-expression.js} +7 -4
- package/{dist/sql-objects/RawStatement.js → cjs/sql-objects/raw-statement.js} +5 -4
- package/{dist/sql-objects/ReturningColumn.js → cjs/sql-objects/returning-column.js} +5 -4
- package/cjs/sql-objects/sequence-getter-statement.js +51 -0
- package/cjs/sql-objects/string-agg-statement.js +82 -0
- package/{dist/sql-objects/TableName.js → cjs/sql-objects/table-name.js} +7 -4
- package/cjs/sql-objects/upper-statement.js +41 -0
- package/cjs/sqlobject.initializers.js +129 -0
- package/cjs/typeguards.js +78 -0
- package/{dist → cjs}/types.js +0 -0
- package/esm/classes.ns.d.ts +38 -0
- package/esm/classes.ns.js +38 -0
- package/{dist → esm}/enums.d.ts +7 -0
- package/esm/enums.js +95 -0
- package/{dist → esm}/extensions.d.ts +1 -1
- package/esm/extensions.js +11 -0
- package/{dist → esm}/helpers.d.ts +0 -0
- package/esm/helpers.js +27 -0
- package/esm/index.d.ts +20 -0
- package/esm/index.js +20 -0
- package/{dist → esm}/op.initializers.d.ts +22 -22
- package/esm/op.initializers.js +126 -0
- package/{dist/query/DeleteQuery.d.ts → esm/query/delete-query.d.ts} +6 -6
- package/esm/query/delete-query.js +51 -0
- package/{dist/query/InsertQuery.d.ts → esm/query/insert-query.d.ts} +5 -5
- package/esm/query/insert-query.js +73 -0
- package/{dist/query/Query.d.ts → esm/query/query.d.ts} +2 -2
- package/esm/query/query.js +36 -0
- package/{dist/query/ReturningQuery.d.ts → esm/query/returning-query.d.ts} +3 -3
- package/esm/query/returning-query.js +41 -0
- package/{dist/query/SelectQuery.d.ts → esm/query/select-query.d.ts} +13 -13
- package/{dist/query/SelectQuery.js → esm/query/select-query.js} +41 -34
- package/{dist/query/UpdateQuery.d.ts → esm/query/update-query.d.ts} +6 -6
- package/esm/query/update-query.js +79 -0
- package/{dist/Serializable.d.ts → esm/serializable.d.ts} +2 -2
- package/esm/serializable.js +2 -0
- package/{dist/SerializeContext.d.ts → esm/serialize-context.d.ts} +1 -1
- package/esm/serialize-context.js +145 -0
- package/{dist/sql-objects/BaseField.d.ts → esm/sql-objects/base-field.d.ts} +1 -1
- package/esm/sql-objects/base-field.js +7 -0
- package/{dist/sql-objects/CaseStatement.d.ts → esm/sql-objects/case-statement.d.ts} +6 -6
- package/esm/sql-objects/case-statement.js +85 -0
- package/esm/sql-objects/coalesce-statement.d.ts +22 -0
- package/esm/sql-objects/coalesce-statement.js +42 -0
- package/{dist/sql-objects/CountStatement.d.ts → esm/sql-objects/count-statement.d.ts} +3 -3
- package/esm/sql-objects/count-statement.js +31 -0
- package/{dist/sql-objects/Expression.d.ts → esm/sql-objects/expression.d.ts} +2 -2
- package/esm/sql-objects/expression.js +6 -0
- package/{dist/sql-objects/FieldExpression.d.ts → esm/sql-objects/field-expression.d.ts} +3 -3
- package/esm/sql-objects/field-expression.js +50 -0
- package/{dist/sql-objects/GroupColumn.d.ts → esm/sql-objects/group-column.d.ts} +3 -3
- package/esm/sql-objects/group-column.js +34 -0
- package/{dist/sql-objects/JoinStatement.d.ts → esm/sql-objects/join-statement.d.ts} +7 -7
- package/esm/sql-objects/join-statement.js +79 -0
- package/esm/sql-objects/lower-statement.d.ts +22 -0
- package/esm/sql-objects/lower-statement.js +37 -0
- package/esm/sql-objects/max-statement.d.ts +22 -0
- package/esm/sql-objects/max-statement.js +37 -0
- package/esm/sql-objects/min-statement.d.ts +22 -0
- package/esm/sql-objects/min-statement.js +37 -0
- package/{dist/sql-objects/Operator.d.ts → esm/sql-objects/operator.d.ts} +2 -2
- package/esm/sql-objects/operator.js +3 -0
- package/{dist/sql-objects/operators/CompOperator.d.ts → esm/sql-objects/operators/comp-operator.d.ts} +4 -4
- package/esm/sql-objects/operators/comp-operator.js +86 -0
- package/{dist/sql-objects/operators/LogicalOperator.d.ts → esm/sql-objects/operators/logical-operator.d.ts} +4 -4
- package/esm/sql-objects/operators/logical-operator.js +79 -0
- package/esm/sql-objects/operators/op-and.d.ts +5 -0
- package/esm/sql-objects/operators/op-and.js +5 -0
- package/{dist/sql-objects/operators/OpBetween.d.ts → esm/sql-objects/operators/op-between.d.ts} +4 -4
- package/esm/sql-objects/operators/op-between.js +31 -0
- package/{dist/sql-objects/operators/OpEq.d.ts → esm/sql-objects/operators/op-eq.d.ts} +3 -3
- package/esm/sql-objects/operators/op-eq.js +9 -0
- package/{dist/sql-objects/operators/OpExists.d.ts → esm/sql-objects/operators/op-exists.d.ts} +4 -4
- package/esm/sql-objects/operators/op-exists.js +26 -0
- package/{dist/sql-objects/operators/OpGt.d.ts → esm/sql-objects/operators/op-gt.d.ts} +3 -3
- package/esm/sql-objects/operators/op-gt.js +9 -0
- package/{dist/sql-objects/operators/OpGte.d.ts → esm/sql-objects/operators/op-gte.d.ts} +3 -3
- package/esm/sql-objects/operators/op-gte.js +9 -0
- package/{dist/sql-objects/operators/OpILike.d.ts → esm/sql-objects/operators/op-ilike.d.ts} +2 -2
- package/esm/sql-objects/operators/op-ilike.js +6 -0
- package/{dist/sql-objects/operators/OpIn.d.ts → esm/sql-objects/operators/op-in.d.ts} +3 -3
- package/esm/sql-objects/operators/op-in.js +15 -0
- package/{dist/sql-objects/operators/OpIsNot.d.ts → esm/sql-objects/operators/op-is-not.d.ts} +3 -3
- package/esm/sql-objects/operators/op-is-not.js +9 -0
- package/{dist/sql-objects/operators/OpIs.d.ts → esm/sql-objects/operators/op-is.d.ts} +3 -3
- package/esm/sql-objects/operators/op-is.js +9 -0
- package/{dist/sql-objects/operators/OpLike.d.ts → esm/sql-objects/operators/op-like.d.ts} +4 -4
- package/esm/sql-objects/operators/op-like.js +18 -0
- package/{dist/sql-objects/operators/OpLt.d.ts → esm/sql-objects/operators/op-lt.d.ts} +3 -3
- package/esm/sql-objects/operators/op-lt.js +9 -0
- package/{dist/sql-objects/operators/OpLte.d.ts → esm/sql-objects/operators/op-lte.d.ts} +3 -3
- package/esm/sql-objects/operators/op-lte.js +9 -0
- package/{dist/sql-objects/operators/OpNe.d.ts → esm/sql-objects/operators/op-ne.d.ts} +3 -3
- package/esm/sql-objects/operators/op-ne.js +9 -0
- package/{dist/sql-objects/operators/OpNotBetween.d.ts → esm/sql-objects/operators/op-not-between.d.ts} +2 -2
- package/esm/sql-objects/operators/op-not-between.js +6 -0
- package/{dist/sql-objects/operators/OpNotExists.d.ts → esm/sql-objects/operators/op-not-exists.d.ts} +2 -2
- package/esm/sql-objects/operators/op-not-exists.js +6 -0
- package/{dist/sql-objects/operators/OpNotILike.d.ts → esm/sql-objects/operators/op-not-ilike.d.ts} +2 -2
- package/esm/sql-objects/operators/op-not-ilike.js +6 -0
- package/{dist/sql-objects/operators/OpNotIn.d.ts → esm/sql-objects/operators/op-not-in.d.ts} +2 -2
- package/esm/sql-objects/operators/op-not-in.js +6 -0
- package/{dist/sql-objects/operators/OpNotLike.d.ts → esm/sql-objects/operators/op-not-like.d.ts} +2 -2
- package/esm/sql-objects/operators/op-not-like.js +6 -0
- package/esm/sql-objects/operators/op-or.d.ts +5 -0
- package/esm/sql-objects/operators/op-or.js +5 -0
- package/{dist/sql-objects/OrderColumn.d.ts → esm/sql-objects/order-column.d.ts} +3 -3
- package/esm/sql-objects/order-column.js +39 -0
- package/{dist/sql-objects/ParamExpression.d.ts → esm/sql-objects/param-expression.d.ts} +3 -3
- package/esm/sql-objects/param-expression.js +52 -0
- package/{dist/sql-objects/RawStatement.d.ts → esm/sql-objects/raw-statement.d.ts} +3 -3
- package/esm/sql-objects/raw-statement.js +15 -0
- package/{dist/sql-objects/ReturningColumn.d.ts → esm/sql-objects/returning-column.d.ts} +3 -3
- package/esm/sql-objects/returning-column.js +29 -0
- package/esm/sql-objects/sequence-getter-statement.d.ts +24 -0
- package/esm/sql-objects/sequence-getter-statement.js +47 -0
- package/esm/sql-objects/string-agg-statement.d.ts +31 -0
- package/esm/sql-objects/string-agg-statement.js +78 -0
- package/{dist/sql-objects/TableName.d.ts → esm/sql-objects/table-name.d.ts} +3 -3
- package/esm/sql-objects/table-name.js +30 -0
- package/esm/sql-objects/upper-statement.d.ts +22 -0
- package/esm/sql-objects/upper-statement.js +37 -0
- package/esm/sqlobject.initializers.d.ts +54 -0
- package/esm/sqlobject.initializers.js +101 -0
- package/{dist → esm}/typeguards.d.ts +18 -17
- package/esm/typeguards.js +57 -0
- package/{dist → esm}/types.d.ts +2 -2
- package/esm/types.js +1 -0
- package/package.json +49 -34
- package/dist/classes.d.ts +0 -38
- package/dist/classes.js +0 -41
- package/dist/index.d.ts +0 -20
- package/dist/index.js +0 -27
- package/dist/sql-objects/BaseField.js +0 -11
- package/dist/sql-objects/Expression.js +0 -7
- package/dist/sql-objects/operators/OpAnd.d.ts +0 -5
- package/dist/sql-objects/operators/OpAnd.js +0 -12
- package/dist/sql-objects/operators/OpEq.js +0 -13
- package/dist/sql-objects/operators/OpGt.js +0 -13
- package/dist/sql-objects/operators/OpGte.js +0 -13
- package/dist/sql-objects/operators/OpILike.js +0 -13
- package/dist/sql-objects/operators/OpIn.js +0 -19
- package/dist/sql-objects/operators/OpIs.js +0 -13
- package/dist/sql-objects/operators/OpIsNot.js +0 -13
- package/dist/sql-objects/operators/OpLt.js +0 -13
- package/dist/sql-objects/operators/OpLte.js +0 -13
- package/dist/sql-objects/operators/OpNe.js +0 -13
- package/dist/sql-objects/operators/OpNotBetween.js +0 -13
- package/dist/sql-objects/operators/OpNotExists.js +0 -13
- package/dist/sql-objects/operators/OpNotILike.js +0 -13
- package/dist/sql-objects/operators/OpNotIn.js +0 -13
- package/dist/sql-objects/operators/OpNotLike.js +0 -13
- package/dist/sql-objects/operators/OpOr.d.ts +0 -5
- package/dist/sql-objects/operators/OpOr.js +0 -12
- package/dist/sqlobject.initializers.d.ts +0 -39
- package/dist/sqlobject.initializers.js +0 -90
- package/dist/typeguards.js +0 -73
package/esm/enums.js
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
export var JoinType;
|
|
2
|
+
(function (JoinType) {
|
|
3
|
+
JoinType["INNER"] = "inner";
|
|
4
|
+
JoinType["LEFT"] = "left";
|
|
5
|
+
JoinType["LEFT_OUTER"] = "left outer";
|
|
6
|
+
JoinType["RIGHT"] = "right";
|
|
7
|
+
JoinType["RIGHT_OUTER"] = "right outer";
|
|
8
|
+
JoinType["OUTER"] = "outer";
|
|
9
|
+
JoinType["FULL_OUTER"] = "full outer";
|
|
10
|
+
})(JoinType || (JoinType = {}));
|
|
11
|
+
export var SerializationType;
|
|
12
|
+
(function (SerializationType) {
|
|
13
|
+
SerializationType["SELECT_QUERY"] = "select_query";
|
|
14
|
+
SerializationType["SELECT_QUERY_COLUMNS"] = "select_query.columns";
|
|
15
|
+
SerializationType["SELECT_QUERY_FROM"] = "select_query.from";
|
|
16
|
+
SerializationType["SELECT_QUERY_JOIN"] = "select_query.join";
|
|
17
|
+
SerializationType["SELECT_QUERY_GROUPBY"] = "select_query.groupby";
|
|
18
|
+
SerializationType["SELECT_QUERY_ORDERBY"] = "select_query.orderby";
|
|
19
|
+
SerializationType["INSERT_QUERY"] = "insert_query";
|
|
20
|
+
SerializationType["INSERT_QUERY_COLUMNS"] = "insert_query.columns";
|
|
21
|
+
SerializationType["INSERT_QUERY_VALUES"] = "insert_query.values";
|
|
22
|
+
SerializationType["UPDATE_QUERY"] = "update_query";
|
|
23
|
+
SerializationType["UPDATE_QUERY_VALUES"] = "update_query.values";
|
|
24
|
+
SerializationType["DELETE_QUERY"] = "delete_query";
|
|
25
|
+
SerializationType["SELECT_COLUMN"] = "select_column";
|
|
26
|
+
SerializationType["GROUP_COLUMN"] = "group_column";
|
|
27
|
+
SerializationType["ORDER_COLUMN"] = "order_column";
|
|
28
|
+
SerializationType["RETURNING_COLUMN"] = "returning_column";
|
|
29
|
+
SerializationType["TABLE_NAME"] = "table_name";
|
|
30
|
+
SerializationType["JOIN"] = "join";
|
|
31
|
+
SerializationType["JOIN_CONDITIONS"] = "join_conditions";
|
|
32
|
+
SerializationType["RAW"] = "raw";
|
|
33
|
+
SerializationType["CASE_STATEMENT"] = "case_expression";
|
|
34
|
+
SerializationType["COALESCE_STATEMENT"] = "coalesce_expression";
|
|
35
|
+
SerializationType["LOWER_STATEMENT"] = "lower_expression";
|
|
36
|
+
SerializationType["UPPER_STATEMENT"] = "upper_expression";
|
|
37
|
+
SerializationType["MAX_STATEMENT"] = "max_expression";
|
|
38
|
+
SerializationType["MIN_STATEMENT"] = "min_expression";
|
|
39
|
+
SerializationType["SEQUENCE_GETTER_STATEMENT"] = "sequence_getter_statement";
|
|
40
|
+
SerializationType["STRINGAGG_STATEMENT"] = "StringAGG_expression";
|
|
41
|
+
SerializationType["COUNT_STATEMENT"] = "count_expression";
|
|
42
|
+
SerializationType["CONDITIONS_BLOCK"] = "conditions_block";
|
|
43
|
+
SerializationType["COMPARISON_EXPRESSION"] = "comparison_expression";
|
|
44
|
+
SerializationType["LOGICAL_EXPRESSION"] = "logical_expression";
|
|
45
|
+
SerializationType["RETURNING_BLOCK"] = "returning_block";
|
|
46
|
+
SerializationType["DATE_VALUE"] = "date_value";
|
|
47
|
+
SerializationType["STRING_VALUE"] = "string_value";
|
|
48
|
+
SerializationType["BOOLEAN_VALUE"] = "boolean_value";
|
|
49
|
+
SerializationType["NUMBER_VALUE"] = "number_value";
|
|
50
|
+
SerializationType["EXTERNAL_PARAMETER"] = "external_parameter";
|
|
51
|
+
SerializationType["ARRAY"] = "array";
|
|
52
|
+
})(SerializationType || (SerializationType = {}));
|
|
53
|
+
export var OperatorType;
|
|
54
|
+
(function (OperatorType) {
|
|
55
|
+
OperatorType["and"] = "and";
|
|
56
|
+
OperatorType["or"] = "or";
|
|
57
|
+
OperatorType["eq"] = "eq";
|
|
58
|
+
OperatorType["ne"] = "ne";
|
|
59
|
+
OperatorType["gt"] = "gt";
|
|
60
|
+
OperatorType["gte"] = "gte";
|
|
61
|
+
OperatorType["lt"] = "lt";
|
|
62
|
+
OperatorType["lte"] = "lte";
|
|
63
|
+
OperatorType["between"] = "between";
|
|
64
|
+
OperatorType["notBetween"] = "notBetween";
|
|
65
|
+
OperatorType["in"] = "in";
|
|
66
|
+
OperatorType["notIn"] = "notIn";
|
|
67
|
+
OperatorType["like"] = "like";
|
|
68
|
+
OperatorType["notLike"] = "nlike";
|
|
69
|
+
OperatorType["iLike"] = "iLike";
|
|
70
|
+
OperatorType["notILike"] = "nIlike";
|
|
71
|
+
OperatorType["is"] = "is";
|
|
72
|
+
OperatorType["isNot"] = "isNot";
|
|
73
|
+
OperatorType["exists"] = "exists";
|
|
74
|
+
OperatorType["notExists"] = "notExists";
|
|
75
|
+
})(OperatorType || (OperatorType = {}));
|
|
76
|
+
export var DataType;
|
|
77
|
+
(function (DataType) {
|
|
78
|
+
DataType["BOOL"] = "BOOL";
|
|
79
|
+
DataType["CHAR"] = "CHAR";
|
|
80
|
+
DataType["VARCHAR"] = "VARCHAR";
|
|
81
|
+
DataType["SMALLINT"] = "SMALLINT";
|
|
82
|
+
DataType["INTEGER"] = "INTEGER";
|
|
83
|
+
DataType["BIGINT"] = "BIGINT";
|
|
84
|
+
DataType["FLOAT"] = "FLOAT";
|
|
85
|
+
DataType["DOUBLE"] = "DOUBLE";
|
|
86
|
+
DataType["NUMBER"] = "NUMBER";
|
|
87
|
+
DataType["DATE"] = "DATE";
|
|
88
|
+
DataType["TIMESTAMP"] = "TIMESTAMP";
|
|
89
|
+
DataType["TIMESTAMPTZ"] = "TIMESTAMPTZ";
|
|
90
|
+
DataType["TIME"] = "TIME";
|
|
91
|
+
DataType["BINARY"] = "BINARY";
|
|
92
|
+
DataType["TEXT"] = "TEXT";
|
|
93
|
+
DataType["GUID"] = "GUID";
|
|
94
|
+
DataType["JSON"] = "JSON";
|
|
95
|
+
})(DataType || (DataType = {}));
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SerializerExtension } from './types';
|
|
1
|
+
import { SerializerExtension } from './types.js';
|
|
2
2
|
export declare let serializers: SerializerExtension[];
|
|
3
3
|
export declare function registerSerializer(...extension: SerializerExtension[]): void;
|
|
4
4
|
export declare function unRegisterSerializer(...extension: SerializerExtension[]): void;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export let serializers = [];
|
|
2
|
+
export function registerSerializer(...extension) {
|
|
3
|
+
for (const ext of extension) {
|
|
4
|
+
if (!ext.dialect)
|
|
5
|
+
throw new TypeError('A SerializerExtension must contain "dialect" property');
|
|
6
|
+
serializers.push(ext);
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
export function unRegisterSerializer(...extension) {
|
|
10
|
+
serializers = serializers.filter(x => !extension.includes(x));
|
|
11
|
+
}
|
|
File without changes
|
package/esm/helpers.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Prints array with line feeding
|
|
3
|
+
*/
|
|
4
|
+
export function printArray(arr, sep, lfLen) {
|
|
5
|
+
let out = '';
|
|
6
|
+
let line = '';
|
|
7
|
+
let k = 0;
|
|
8
|
+
lfLen = lfLen || 60;
|
|
9
|
+
sep = sep || ',';
|
|
10
|
+
for (const s of arr) {
|
|
11
|
+
/* istanbul ignore next */
|
|
12
|
+
if (s === undefined)
|
|
13
|
+
continue;
|
|
14
|
+
line += (k > 0 ? sep : '');
|
|
15
|
+
if (line.length > lfLen) {
|
|
16
|
+
out += (out ? '\n' : '') + line;
|
|
17
|
+
line = '';
|
|
18
|
+
}
|
|
19
|
+
else
|
|
20
|
+
line += line ? ' ' : '';
|
|
21
|
+
line += s;
|
|
22
|
+
k++;
|
|
23
|
+
}
|
|
24
|
+
if (line)
|
|
25
|
+
out += (out ? '\n' : '') + line;
|
|
26
|
+
return out;
|
|
27
|
+
}
|
package/esm/index.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export { registerSerializer, unRegisterSerializer } from './extensions.js';
|
|
2
|
+
export * from './helpers.js';
|
|
3
|
+
export * from './serializable.js';
|
|
4
|
+
export * from './serialize-context.js';
|
|
5
|
+
export * from './query/query.js';
|
|
6
|
+
export * from './query/select-query.js';
|
|
7
|
+
export * from './query/insert-query.js';
|
|
8
|
+
export * from './query/update-query.js';
|
|
9
|
+
export * from './query/delete-query.js';
|
|
10
|
+
export * from './sql-objects/operator.js';
|
|
11
|
+
export * from './sql-objects/operators/logical-operator.js';
|
|
12
|
+
export * from './sql-objects/operators/comp-operator.js';
|
|
13
|
+
export * from './sql-objects/join-statement.js';
|
|
14
|
+
export * from './types.js';
|
|
15
|
+
export * from './enums.js';
|
|
16
|
+
export * from './sqlobject.initializers.js';
|
|
17
|
+
export * from './op.initializers.js';
|
|
18
|
+
export * from './typeguards.js';
|
|
19
|
+
export { op } from './op.initializers.js';
|
|
20
|
+
export * as classes from './classes.ns.js';
|
package/esm/index.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export { registerSerializer, unRegisterSerializer } from './extensions.js';
|
|
2
|
+
export * from './helpers.js';
|
|
3
|
+
export * from './serializable.js';
|
|
4
|
+
export * from './serialize-context.js';
|
|
5
|
+
export * from './query/query.js';
|
|
6
|
+
export * from './query/select-query.js';
|
|
7
|
+
export * from './query/insert-query.js';
|
|
8
|
+
export * from './query/update-query.js';
|
|
9
|
+
export * from './query/delete-query.js';
|
|
10
|
+
export * from './sql-objects/operator.js';
|
|
11
|
+
export * from './sql-objects/operators/logical-operator.js';
|
|
12
|
+
export * from './sql-objects/operators/comp-operator.js';
|
|
13
|
+
export * from './sql-objects/join-statement.js';
|
|
14
|
+
export * from './types.js';
|
|
15
|
+
export * from './enums.js';
|
|
16
|
+
export * from './sqlobject.initializers.js';
|
|
17
|
+
export * from './op.initializers.js';
|
|
18
|
+
export * from './typeguards.js';
|
|
19
|
+
export { op } from './op.initializers.js';
|
|
20
|
+
export * as classes from './classes.ns.js';
|
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
import { SelectQuery } from './query/
|
|
2
|
-
import { Serializable } from './
|
|
3
|
-
import { Operator } from './sql-objects/
|
|
4
|
-
import { OpAnd } from './sql-objects/operators/
|
|
5
|
-
import { OpEq } from './sql-objects/operators/
|
|
6
|
-
import { OpExists } from './sql-objects/operators/
|
|
7
|
-
import { OpGt } from './sql-objects/operators/
|
|
8
|
-
import { OpGte } from './sql-objects/operators/
|
|
9
|
-
import { OpILike } from './sql-objects/operators/
|
|
10
|
-
import { OpIn } from './sql-objects/operators/
|
|
11
|
-
import { OpIs } from './sql-objects/operators/
|
|
12
|
-
import { OpIsNot } from './sql-objects/operators/
|
|
13
|
-
import { OpLike } from './sql-objects/operators/
|
|
14
|
-
import { OpLt } from './sql-objects/operators/
|
|
15
|
-
import { OpLte } from './sql-objects/operators/
|
|
16
|
-
import { OpNe } from './sql-objects/operators/
|
|
17
|
-
import { OpNotExists } from './sql-objects/operators/
|
|
18
|
-
import { OpNotILike } from './sql-objects/operators/
|
|
19
|
-
import { OpNotIn } from './sql-objects/operators/
|
|
20
|
-
import { OpNotLike } from './sql-objects/operators/
|
|
21
|
-
import { OpOr } from './sql-objects/operators/
|
|
22
|
-
import { RawStatement } from './sql-objects/
|
|
1
|
+
import { SelectQuery } from './query/select-query.js';
|
|
2
|
+
import { Serializable } from './serializable.js';
|
|
3
|
+
import { Operator } from './sql-objects/operator.js';
|
|
4
|
+
import { OpAnd } from './sql-objects/operators/op-and.js';
|
|
5
|
+
import { OpEq } from './sql-objects/operators/op-eq.js';
|
|
6
|
+
import { OpExists } from './sql-objects/operators/op-exists.js';
|
|
7
|
+
import { OpGt } from './sql-objects/operators/op-gt.js';
|
|
8
|
+
import { OpGte } from './sql-objects/operators/op-gte.js';
|
|
9
|
+
import { OpILike } from './sql-objects/operators/op-ilike.js';
|
|
10
|
+
import { OpIn } from './sql-objects/operators/op-in.js';
|
|
11
|
+
import { OpIs } from './sql-objects/operators/op-is.js';
|
|
12
|
+
import { OpIsNot } from './sql-objects/operators/op-is-not.js';
|
|
13
|
+
import { OpLike } from './sql-objects/operators/op-like.js';
|
|
14
|
+
import { OpLt } from './sql-objects/operators/op-lt.js';
|
|
15
|
+
import { OpLte } from './sql-objects/operators/op-lte.js';
|
|
16
|
+
import { OpNe } from './sql-objects/operators/op-ne.js';
|
|
17
|
+
import { OpNotExists } from './sql-objects/operators/op-not-exists.js';
|
|
18
|
+
import { OpNotILike } from './sql-objects/operators/op-not-ilike.js';
|
|
19
|
+
import { OpNotIn } from './sql-objects/operators/op-not-in.js';
|
|
20
|
+
import { OpNotLike } from './sql-objects/operators/op-not-like.js';
|
|
21
|
+
import { OpOr } from './sql-objects/operators/op-or.js';
|
|
22
|
+
import { RawStatement } from './sql-objects/raw-statement.js';
|
|
23
23
|
declare function And(...args: (Operator | RawStatement)[]): OpAnd;
|
|
24
24
|
declare function Or(...args: (Operator | RawStatement)[]): OpOr;
|
|
25
25
|
declare function Eq(expression: string | Serializable, value: any): OpEq;
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { WrapOps } from './sql-objects/operators/logical-operator.js';
|
|
2
|
+
import { OpAnd } from './sql-objects/operators/op-and.js';
|
|
3
|
+
import { OpBetween } from './sql-objects/operators/op-between.js';
|
|
4
|
+
import { OpEq } from './sql-objects/operators/op-eq.js';
|
|
5
|
+
import { OpExists } from './sql-objects/operators/op-exists.js';
|
|
6
|
+
import { OpGt } from './sql-objects/operators/op-gt.js';
|
|
7
|
+
import { OpGte } from './sql-objects/operators/op-gte.js';
|
|
8
|
+
import { OpILike } from './sql-objects/operators/op-ilike.js';
|
|
9
|
+
import { OpIn } from './sql-objects/operators/op-in.js';
|
|
10
|
+
import { OpIs } from './sql-objects/operators/op-is.js';
|
|
11
|
+
import { OpIsNot } from './sql-objects/operators/op-is-not.js';
|
|
12
|
+
import { OpLike } from './sql-objects/operators/op-like.js';
|
|
13
|
+
import { OpLt } from './sql-objects/operators/op-lt.js';
|
|
14
|
+
import { OpLte } from './sql-objects/operators/op-lte.js';
|
|
15
|
+
import { OpNe } from './sql-objects/operators/op-ne.js';
|
|
16
|
+
import { OpNotBetween } from './sql-objects/operators/op-not-between.js';
|
|
17
|
+
import { OpNotExists } from './sql-objects/operators/op-not-exists.js';
|
|
18
|
+
import { OpNotILike } from './sql-objects/operators/op-not-ilike.js';
|
|
19
|
+
import { OpNotIn } from './sql-objects/operators/op-not-in.js';
|
|
20
|
+
import { OpNotLike } from './sql-objects/operators/op-not-like.js';
|
|
21
|
+
import { OpOr } from './sql-objects/operators/op-or.js';
|
|
22
|
+
function And(...args) {
|
|
23
|
+
return new OpAnd(...args);
|
|
24
|
+
}
|
|
25
|
+
function Or(...args) {
|
|
26
|
+
return new OpOr(...args);
|
|
27
|
+
}
|
|
28
|
+
function Eq(expression, value) {
|
|
29
|
+
return new OpEq(expression, value);
|
|
30
|
+
}
|
|
31
|
+
function Ne(expression, value) {
|
|
32
|
+
return new OpNe(expression, value);
|
|
33
|
+
}
|
|
34
|
+
function Gt(expression, value) {
|
|
35
|
+
return new OpGt(expression, value);
|
|
36
|
+
}
|
|
37
|
+
function Gte(expression, value) {
|
|
38
|
+
return new OpGte(expression, value);
|
|
39
|
+
}
|
|
40
|
+
function Lt(expression, value) {
|
|
41
|
+
return new OpLt(expression, value);
|
|
42
|
+
}
|
|
43
|
+
function Lte(expression, value) {
|
|
44
|
+
return new OpLte(expression, value);
|
|
45
|
+
}
|
|
46
|
+
function Between(expression, value1, value2) {
|
|
47
|
+
const values = Array.isArray(value1) ? value1 : [value1, value2];
|
|
48
|
+
return new OpBetween(expression, values);
|
|
49
|
+
}
|
|
50
|
+
function NotBetween(expression, value1, value2) {
|
|
51
|
+
const values = Array.isArray(value1) ? value1 : [value1, value2];
|
|
52
|
+
return new OpNotBetween(expression, values);
|
|
53
|
+
}
|
|
54
|
+
function In(expression, value) {
|
|
55
|
+
return new OpIn(expression, value);
|
|
56
|
+
}
|
|
57
|
+
function NotIn(expression, value) {
|
|
58
|
+
return new OpNotIn(expression, value);
|
|
59
|
+
}
|
|
60
|
+
function Like(expression, value) {
|
|
61
|
+
return new OpLike(expression, value);
|
|
62
|
+
}
|
|
63
|
+
function NotLike(expression, value) {
|
|
64
|
+
return new OpNotLike(expression, value);
|
|
65
|
+
}
|
|
66
|
+
function Ilike(expression, value) {
|
|
67
|
+
return new OpILike(expression, value);
|
|
68
|
+
}
|
|
69
|
+
function NotILike(expression, value) {
|
|
70
|
+
return new OpNotILike(expression, value);
|
|
71
|
+
}
|
|
72
|
+
function Is(expression, value) {
|
|
73
|
+
return new OpIs(expression, value);
|
|
74
|
+
}
|
|
75
|
+
function IsNot(expression, value) {
|
|
76
|
+
return new OpIsNot(expression, value);
|
|
77
|
+
}
|
|
78
|
+
function Exists(expression) {
|
|
79
|
+
return new OpExists(expression);
|
|
80
|
+
}
|
|
81
|
+
function NotExists(expression) {
|
|
82
|
+
return new OpNotExists(expression);
|
|
83
|
+
}
|
|
84
|
+
const op = {
|
|
85
|
+
and: And,
|
|
86
|
+
or: Or,
|
|
87
|
+
eq: Eq,
|
|
88
|
+
'=': Eq,
|
|
89
|
+
ne: Ne,
|
|
90
|
+
'!=': Ne,
|
|
91
|
+
gt: Gt,
|
|
92
|
+
'>': Gt,
|
|
93
|
+
gte: Gte,
|
|
94
|
+
'>=': Gte,
|
|
95
|
+
lt: Lt,
|
|
96
|
+
'<': Lt,
|
|
97
|
+
lte: Lte,
|
|
98
|
+
'<=': Lte,
|
|
99
|
+
between: Between,
|
|
100
|
+
btw: Between,
|
|
101
|
+
notBetween: NotBetween,
|
|
102
|
+
nbtw: NotBetween,
|
|
103
|
+
'!between': NotBetween,
|
|
104
|
+
'!btw': NotBetween,
|
|
105
|
+
in: In,
|
|
106
|
+
notIn: NotIn,
|
|
107
|
+
nin: NotIn,
|
|
108
|
+
'!in': NotIn,
|
|
109
|
+
like: Like,
|
|
110
|
+
notLike: NotLike,
|
|
111
|
+
nlike: NotLike,
|
|
112
|
+
'!like': NotLike,
|
|
113
|
+
ilike: Ilike,
|
|
114
|
+
notILike: NotILike,
|
|
115
|
+
nilike: NotILike,
|
|
116
|
+
'!ilike': NotILike,
|
|
117
|
+
is: Is,
|
|
118
|
+
isNot: IsNot,
|
|
119
|
+
'!is': IsNot,
|
|
120
|
+
exists: Exists,
|
|
121
|
+
notExists: NotExists,
|
|
122
|
+
'!exists': NotExists
|
|
123
|
+
};
|
|
124
|
+
Object.assign(WrapOps, op);
|
|
125
|
+
export { op };
|
|
126
|
+
export { And, Or, Eq, Eq as Equal, Ne, Ne as NotEqual, Gt, Gt as GreaterThan, Gte, Gte as GreaterAnEqualTo, Lt, Lt as LowerThan, Lte, Lte as LowerAndEqualTo, Between, NotBetween, In, NotIn, NotIn as Nin, Like, NotLike, NotLike as NLike, Ilike, NotILike, NotILike as Nilike, Is, IsNot, Exists, NotExists };
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { SerializationType } from '../enums';
|
|
2
|
-
import { SerializeContext } from '../
|
|
3
|
-
import { LogicalOperator } from '../sql-objects/operators/
|
|
4
|
-
import { RawStatement } from '../sql-objects/
|
|
5
|
-
import { TableName } from '../sql-objects/
|
|
6
|
-
import { Query } from './
|
|
1
|
+
import { SerializationType } from '../enums.js';
|
|
2
|
+
import { SerializeContext } from '../serialize-context.js';
|
|
3
|
+
import { LogicalOperator } from '../sql-objects/operators/logical-operator.js';
|
|
4
|
+
import { RawStatement } from '../sql-objects/raw-statement.js';
|
|
5
|
+
import { TableName } from '../sql-objects/table-name.js';
|
|
6
|
+
import { Query } from './query.js';
|
|
7
7
|
export declare class DeleteQuery extends Query {
|
|
8
8
|
_table: TableName | RawStatement;
|
|
9
9
|
_where?: LogicalOperator;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { SerializationType } from '../enums.js';
|
|
2
|
+
import { OpAnd } from '../sql-objects/operators/op-and.js';
|
|
3
|
+
import { TableName } from '../sql-objects/table-name.js';
|
|
4
|
+
import { isRawStatement } from '../typeguards.js';
|
|
5
|
+
import { Query } from './query.js';
|
|
6
|
+
export class DeleteQuery extends Query {
|
|
7
|
+
_table;
|
|
8
|
+
_where;
|
|
9
|
+
constructor(tableName) {
|
|
10
|
+
super();
|
|
11
|
+
if (!tableName || !(typeof tableName === 'string' || isRawStatement(tableName)))
|
|
12
|
+
throw new TypeError('String or Raw instance required as first argument (tableName) for UpdateQuery');
|
|
13
|
+
this._table = typeof tableName === 'string' ? new TableName(tableName) : tableName;
|
|
14
|
+
}
|
|
15
|
+
get _type() {
|
|
16
|
+
return SerializationType.DELETE_QUERY;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Defines "where" part of query
|
|
20
|
+
*/
|
|
21
|
+
where(...operator) {
|
|
22
|
+
this._where = this._where || new OpAnd();
|
|
23
|
+
this._where.add(...operator);
|
|
24
|
+
return this;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Performs serialization
|
|
28
|
+
*/
|
|
29
|
+
_serialize(ctx) {
|
|
30
|
+
const o = {
|
|
31
|
+
table: this._table._serialize(ctx),
|
|
32
|
+
where: this._serializeWhere(ctx)
|
|
33
|
+
};
|
|
34
|
+
let out = 'delete from ' + o.table;
|
|
35
|
+
if (o.where)
|
|
36
|
+
out += '\n' + o.where;
|
|
37
|
+
return out;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
*
|
|
41
|
+
*/
|
|
42
|
+
_serializeWhere(ctx) {
|
|
43
|
+
if (!this._where)
|
|
44
|
+
return '';
|
|
45
|
+
const s = this._where._serialize(ctx);
|
|
46
|
+
return ctx.serialize(SerializationType.CONDITIONS_BLOCK, s, () => {
|
|
47
|
+
/* istanbul ignore next */
|
|
48
|
+
return s ? 'where ' + s : '';
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { SerializationType } from '../enums';
|
|
2
|
-
import { SerializeContext } from '../
|
|
3
|
-
import type { RawStatement } from '../sql-objects/
|
|
4
|
-
import { TableName } from '../sql-objects/
|
|
5
|
-
import { ReturningQuery } from './
|
|
1
|
+
import { SerializationType } from '../enums.js';
|
|
2
|
+
import { SerializeContext } from '../serialize-context.js';
|
|
3
|
+
import type { RawStatement } from '../sql-objects/raw-statement.js';
|
|
4
|
+
import { TableName } from '../sql-objects/table-name.js';
|
|
5
|
+
import { ReturningQuery } from './returning-query.js';
|
|
6
6
|
export declare class InsertQuery extends ReturningQuery {
|
|
7
7
|
_table: TableName | RawStatement;
|
|
8
8
|
_input: any;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { SerializationType } from '../enums.js';
|
|
2
|
+
import { printArray } from '../helpers.js';
|
|
3
|
+
import { TableName } from '../sql-objects/table-name.js';
|
|
4
|
+
import { isRawStatement, isSelectQuery, isSerializable } from '../typeguards.js';
|
|
5
|
+
import { ReturningQuery } from './returning-query.js';
|
|
6
|
+
export class InsertQuery extends ReturningQuery {
|
|
7
|
+
_table;
|
|
8
|
+
_input;
|
|
9
|
+
constructor(tableName, input) {
|
|
10
|
+
super();
|
|
11
|
+
if (!tableName || !(typeof tableName === 'string' || isRawStatement(tableName)))
|
|
12
|
+
throw new TypeError('String or Raw instance required as first argument (tableName) for InsertQuery');
|
|
13
|
+
if (!input || !((typeof input === 'object' && !Array.isArray(input)) ||
|
|
14
|
+
input.isSelect))
|
|
15
|
+
throw new TypeError('Object or SelectQuery instance required as second argument (input) for InsertQuery');
|
|
16
|
+
this._table = typeof tableName === 'string' ? new TableName(tableName) : tableName;
|
|
17
|
+
this._input = input;
|
|
18
|
+
}
|
|
19
|
+
get _type() {
|
|
20
|
+
return SerializationType.INSERT_QUERY;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Performs serialization
|
|
24
|
+
*/
|
|
25
|
+
_serialize(ctx) {
|
|
26
|
+
const o = {
|
|
27
|
+
table: this._table._serialize(ctx),
|
|
28
|
+
columns: this.__serializeColumns(ctx),
|
|
29
|
+
values: this.__serializeValues(ctx),
|
|
30
|
+
returning: this.__serializeReturning(ctx)
|
|
31
|
+
};
|
|
32
|
+
let out = 'insert into ' + o.table + '\n\t(' +
|
|
33
|
+
o.columns + ')\n\bvalues\n\t(' + o.values + ')\b';
|
|
34
|
+
if (o.returning)
|
|
35
|
+
out += '\n' + o.returning;
|
|
36
|
+
return out;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
*
|
|
40
|
+
*/
|
|
41
|
+
__serializeColumns(ctx) {
|
|
42
|
+
let arr;
|
|
43
|
+
if (isSelectQuery(this._input)) {
|
|
44
|
+
arr = [];
|
|
45
|
+
const cols = this._input._columns;
|
|
46
|
+
if (cols) {
|
|
47
|
+
for (const col of cols) {
|
|
48
|
+
if (col._alias)
|
|
49
|
+
arr.push(col._alias);
|
|
50
|
+
else if (col._field)
|
|
51
|
+
arr.push(col._field);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
else
|
|
56
|
+
arr = Object.keys(this._input);
|
|
57
|
+
return ctx.serialize(SerializationType.INSERT_QUERY_COLUMNS, arr, () => printArray(arr));
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
*
|
|
61
|
+
*/
|
|
62
|
+
__serializeValues(ctx) {
|
|
63
|
+
if (isSerializable(this._input))
|
|
64
|
+
return this._input._serialize(ctx);
|
|
65
|
+
const arr = [];
|
|
66
|
+
const allValues = this._input;
|
|
67
|
+
for (const n of Object.keys(allValues)) {
|
|
68
|
+
const s = ctx.anyToSQL(allValues[n]) || 'null';
|
|
69
|
+
arr.push(s);
|
|
70
|
+
}
|
|
71
|
+
return ctx.serialize(SerializationType.INSERT_QUERY_VALUES, arr, () => printArray(arr));
|
|
72
|
+
}
|
|
73
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { EventEmitter } from 'events';
|
|
3
|
-
import { Serializable } from '../
|
|
4
|
-
import { GenerateOptions, GenerateResult } from '../types';
|
|
3
|
+
import { Serializable } from '../serializable.js';
|
|
4
|
+
import { GenerateOptions, GenerateResult } from '../types.js';
|
|
5
5
|
export declare interface Query extends EventEmitter {
|
|
6
6
|
}
|
|
7
7
|
export declare abstract class Query extends Serializable {
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { EventEmitter } from 'events';
|
|
2
|
+
import flattenText from 'putil-flattentext';
|
|
3
|
+
import merge from 'putil-merge';
|
|
4
|
+
import { Serializable } from '../serializable.js';
|
|
5
|
+
import { SerializeContext } from '../serialize-context.js';
|
|
6
|
+
export class Query extends Serializable {
|
|
7
|
+
_params;
|
|
8
|
+
constructor() {
|
|
9
|
+
super();
|
|
10
|
+
EventEmitter.call(this);
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Generates Sql script
|
|
14
|
+
*/
|
|
15
|
+
generate(options) {
|
|
16
|
+
const ctx = new SerializeContext(options);
|
|
17
|
+
if (this._params)
|
|
18
|
+
ctx.params = { ...ctx.params, ...this._params };
|
|
19
|
+
ctx.serializeHooks = this.listeners('serialize');
|
|
20
|
+
/* generate output */
|
|
21
|
+
const sql = this._serialize(ctx);
|
|
22
|
+
return {
|
|
23
|
+
sql: flattenText(sql, { noWrap: !ctx.prettyPrint }),
|
|
24
|
+
params: ctx.preparedParams,
|
|
25
|
+
paramOptions: ctx.paramOptions,
|
|
26
|
+
returningFields: ctx.returningFields
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
values(obj) {
|
|
30
|
+
if (typeof obj !== 'object' || Array.isArray(obj))
|
|
31
|
+
throw new TypeError('Invalid argument');
|
|
32
|
+
this._params = obj;
|
|
33
|
+
return this;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
merge(Query.prototype, EventEmitter.prototype, { descriptor: true });
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { SerializeContext } from '../
|
|
2
|
-
import { ReturningColumn } from '../sql-objects/
|
|
3
|
-
import { Query } from './
|
|
1
|
+
import { SerializeContext } from '../serialize-context.js';
|
|
2
|
+
import { ReturningColumn } from '../sql-objects/returning-column.js';
|
|
3
|
+
import { Query } from './query.js';
|
|
4
4
|
export declare abstract class ReturningQuery extends Query {
|
|
5
5
|
_returningColumns?: ReturningColumn[];
|
|
6
6
|
/**
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { SerializationType } from '../enums.js';
|
|
2
|
+
import { printArray } from '../helpers.js';
|
|
3
|
+
import { ReturningColumn } from '../sql-objects/returning-column.js';
|
|
4
|
+
import { Query } from './query.js';
|
|
5
|
+
export class ReturningQuery extends Query {
|
|
6
|
+
_returningColumns;
|
|
7
|
+
/**
|
|
8
|
+
*
|
|
9
|
+
*/
|
|
10
|
+
returning(...columns) {
|
|
11
|
+
if (!columns)
|
|
12
|
+
return this;
|
|
13
|
+
// noinspection JSMismatchedCollectionQueryUpdate
|
|
14
|
+
this._returningColumns = columns.length ?
|
|
15
|
+
columns.reduce((a, v) => {
|
|
16
|
+
if (v)
|
|
17
|
+
a.push(new ReturningColumn(v));
|
|
18
|
+
return a;
|
|
19
|
+
}, []) : undefined;
|
|
20
|
+
return this;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
*
|
|
24
|
+
*/
|
|
25
|
+
__serializeReturning(ctx) {
|
|
26
|
+
if (!(this._returningColumns && this._returningColumns.length))
|
|
27
|
+
return '';
|
|
28
|
+
const arr = [];
|
|
29
|
+
ctx.returningFields = [];
|
|
30
|
+
for (const t of this._returningColumns) {
|
|
31
|
+
const s = t._serialize(ctx);
|
|
32
|
+
/* istanbul ignore else */
|
|
33
|
+
if (s)
|
|
34
|
+
arr.push(s);
|
|
35
|
+
}
|
|
36
|
+
return ctx.serialize(SerializationType.RETURNING_BLOCK, arr, () => {
|
|
37
|
+
const s = printArray(arr);
|
|
38
|
+
return s ? 'returning ' + s : '';
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
}
|