@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.
Files changed (208) hide show
  1. package/README.md +2 -2
  2. package/cjs/classes.ns.js +41 -0
  3. package/{dist → cjs}/enums.js +7 -0
  4. package/{dist → cjs}/extensions.js +0 -0
  5. package/{dist → cjs}/helpers.js +0 -0
  6. package/cjs/index.js +27 -0
  7. package/{dist → cjs}/op.initializers.js +42 -42
  8. package/cjs/package.json +3 -0
  9. package/{dist/query/DeleteQuery.js → cjs/query/delete-query.js} +13 -11
  10. package/{dist/query/InsertQuery.js → cjs/query/insert-query.js} +17 -16
  11. package/{dist/query/Query.js → cjs/query/query.js} +5 -4
  12. package/{dist/query/ReturningQuery.js → cjs/query/returning-query.js} +9 -8
  13. package/cjs/query/select-query.js +294 -0
  14. package/{dist/query/UpdateQuery.js → cjs/query/update-query.js} +18 -15
  15. package/{dist/Serializable.js → cjs/serializable.js} +0 -0
  16. package/{dist/SerializeContext.js → cjs/serialize-context.js} +37 -26
  17. package/cjs/sql-objects/base-field.js +11 -0
  18. package/{dist/sql-objects/CaseStatement.js → cjs/sql-objects/case-statement.js} +10 -6
  19. package/cjs/sql-objects/coalesce-statement.js +46 -0
  20. package/{dist/sql-objects/CountStatement.js → cjs/sql-objects/count-statement.js} +5 -4
  21. package/cjs/sql-objects/expression.js +10 -0
  22. package/{dist/sql-objects/FieldExpression.js → cjs/sql-objects/field-expression.js} +5 -4
  23. package/{dist/sql-objects/GroupColumn.js → cjs/sql-objects/group-column.js} +4 -4
  24. package/{dist/sql-objects/JoinStatement.js → cjs/sql-objects/join-statement.js} +20 -18
  25. package/cjs/sql-objects/lower-statement.js +41 -0
  26. package/cjs/sql-objects/max-statement.js +41 -0
  27. package/cjs/sql-objects/min-statement.js +41 -0
  28. package/{dist/sql-objects/Operator.js → cjs/sql-objects/operator.js} +2 -2
  29. package/{dist/sql-objects/operators/CompOperator.js → cjs/sql-objects/operators/comp-operator.js} +19 -16
  30. package/{dist/sql-objects/operators/LogicalOperator.js → cjs/sql-objects/operators/logical-operator.js} +14 -13
  31. package/cjs/sql-objects/operators/op-and.js +9 -0
  32. package/{dist/sql-objects/operators/OpBetween.js → cjs/sql-objects/operators/op-between.js} +5 -5
  33. package/cjs/sql-objects/operators/op-eq.js +13 -0
  34. package/{dist/sql-objects/operators/OpExists.js → cjs/sql-objects/operators/op-exists.js} +7 -7
  35. package/cjs/sql-objects/operators/op-gt.js +13 -0
  36. package/cjs/sql-objects/operators/op-gte.js +13 -0
  37. package/cjs/sql-objects/operators/op-ilike.js +10 -0
  38. package/cjs/sql-objects/operators/op-in.js +19 -0
  39. package/cjs/sql-objects/operators/op-is-not.js +13 -0
  40. package/cjs/sql-objects/operators/op-is.js +13 -0
  41. package/{dist/sql-objects/operators/OpLike.js → cjs/sql-objects/operators/op-like.js} +7 -7
  42. package/cjs/sql-objects/operators/op-lt.js +13 -0
  43. package/cjs/sql-objects/operators/op-lte.js +13 -0
  44. package/cjs/sql-objects/operators/op-ne.js +13 -0
  45. package/cjs/sql-objects/operators/op-not-between.js +10 -0
  46. package/cjs/sql-objects/operators/op-not-exists.js +10 -0
  47. package/cjs/sql-objects/operators/op-not-ilike.js +10 -0
  48. package/cjs/sql-objects/operators/op-not-in.js +10 -0
  49. package/cjs/sql-objects/operators/op-not-like.js +10 -0
  50. package/cjs/sql-objects/operators/op-or.js +9 -0
  51. package/{dist/sql-objects/OrderColumn.js → cjs/sql-objects/order-column.js} +5 -4
  52. package/{dist/sql-objects/ParamExpression.js → cjs/sql-objects/param-expression.js} +7 -4
  53. package/{dist/sql-objects/RawStatement.js → cjs/sql-objects/raw-statement.js} +5 -4
  54. package/{dist/sql-objects/ReturningColumn.js → cjs/sql-objects/returning-column.js} +5 -4
  55. package/cjs/sql-objects/sequence-getter-statement.js +51 -0
  56. package/cjs/sql-objects/string-agg-statement.js +82 -0
  57. package/{dist/sql-objects/TableName.js → cjs/sql-objects/table-name.js} +7 -4
  58. package/cjs/sql-objects/upper-statement.js +41 -0
  59. package/cjs/sqlobject.initializers.js +129 -0
  60. package/cjs/typeguards.js +78 -0
  61. package/{dist → cjs}/types.js +0 -0
  62. package/esm/classes.ns.d.ts +38 -0
  63. package/esm/classes.ns.js +38 -0
  64. package/{dist → esm}/enums.d.ts +7 -0
  65. package/esm/enums.js +95 -0
  66. package/{dist → esm}/extensions.d.ts +1 -1
  67. package/esm/extensions.js +11 -0
  68. package/{dist → esm}/helpers.d.ts +0 -0
  69. package/esm/helpers.js +27 -0
  70. package/esm/index.d.ts +20 -0
  71. package/esm/index.js +20 -0
  72. package/{dist → esm}/op.initializers.d.ts +22 -22
  73. package/esm/op.initializers.js +126 -0
  74. package/{dist/query/DeleteQuery.d.ts → esm/query/delete-query.d.ts} +6 -6
  75. package/esm/query/delete-query.js +51 -0
  76. package/{dist/query/InsertQuery.d.ts → esm/query/insert-query.d.ts} +5 -5
  77. package/esm/query/insert-query.js +73 -0
  78. package/{dist/query/Query.d.ts → esm/query/query.d.ts} +2 -2
  79. package/esm/query/query.js +36 -0
  80. package/{dist/query/ReturningQuery.d.ts → esm/query/returning-query.d.ts} +3 -3
  81. package/esm/query/returning-query.js +41 -0
  82. package/{dist/query/SelectQuery.d.ts → esm/query/select-query.d.ts} +13 -13
  83. package/{dist/query/SelectQuery.js → esm/query/select-query.js} +41 -34
  84. package/{dist/query/UpdateQuery.d.ts → esm/query/update-query.d.ts} +6 -6
  85. package/esm/query/update-query.js +79 -0
  86. package/{dist/Serializable.d.ts → esm/serializable.d.ts} +2 -2
  87. package/esm/serializable.js +2 -0
  88. package/{dist/SerializeContext.d.ts → esm/serialize-context.d.ts} +1 -1
  89. package/esm/serialize-context.js +145 -0
  90. package/{dist/sql-objects/BaseField.d.ts → esm/sql-objects/base-field.d.ts} +1 -1
  91. package/esm/sql-objects/base-field.js +7 -0
  92. package/{dist/sql-objects/CaseStatement.d.ts → esm/sql-objects/case-statement.d.ts} +6 -6
  93. package/esm/sql-objects/case-statement.js +85 -0
  94. package/esm/sql-objects/coalesce-statement.d.ts +22 -0
  95. package/esm/sql-objects/coalesce-statement.js +42 -0
  96. package/{dist/sql-objects/CountStatement.d.ts → esm/sql-objects/count-statement.d.ts} +3 -3
  97. package/esm/sql-objects/count-statement.js +31 -0
  98. package/{dist/sql-objects/Expression.d.ts → esm/sql-objects/expression.d.ts} +2 -2
  99. package/esm/sql-objects/expression.js +6 -0
  100. package/{dist/sql-objects/FieldExpression.d.ts → esm/sql-objects/field-expression.d.ts} +3 -3
  101. package/esm/sql-objects/field-expression.js +50 -0
  102. package/{dist/sql-objects/GroupColumn.d.ts → esm/sql-objects/group-column.d.ts} +3 -3
  103. package/esm/sql-objects/group-column.js +34 -0
  104. package/{dist/sql-objects/JoinStatement.d.ts → esm/sql-objects/join-statement.d.ts} +7 -7
  105. package/esm/sql-objects/join-statement.js +79 -0
  106. package/esm/sql-objects/lower-statement.d.ts +22 -0
  107. package/esm/sql-objects/lower-statement.js +37 -0
  108. package/esm/sql-objects/max-statement.d.ts +22 -0
  109. package/esm/sql-objects/max-statement.js +37 -0
  110. package/esm/sql-objects/min-statement.d.ts +22 -0
  111. package/esm/sql-objects/min-statement.js +37 -0
  112. package/{dist/sql-objects/Operator.d.ts → esm/sql-objects/operator.d.ts} +2 -2
  113. package/esm/sql-objects/operator.js +3 -0
  114. package/{dist/sql-objects/operators/CompOperator.d.ts → esm/sql-objects/operators/comp-operator.d.ts} +4 -4
  115. package/esm/sql-objects/operators/comp-operator.js +86 -0
  116. package/{dist/sql-objects/operators/LogicalOperator.d.ts → esm/sql-objects/operators/logical-operator.d.ts} +4 -4
  117. package/esm/sql-objects/operators/logical-operator.js +79 -0
  118. package/esm/sql-objects/operators/op-and.d.ts +5 -0
  119. package/esm/sql-objects/operators/op-and.js +5 -0
  120. package/{dist/sql-objects/operators/OpBetween.d.ts → esm/sql-objects/operators/op-between.d.ts} +4 -4
  121. package/esm/sql-objects/operators/op-between.js +31 -0
  122. package/{dist/sql-objects/operators/OpEq.d.ts → esm/sql-objects/operators/op-eq.d.ts} +3 -3
  123. package/esm/sql-objects/operators/op-eq.js +9 -0
  124. package/{dist/sql-objects/operators/OpExists.d.ts → esm/sql-objects/operators/op-exists.d.ts} +4 -4
  125. package/esm/sql-objects/operators/op-exists.js +26 -0
  126. package/{dist/sql-objects/operators/OpGt.d.ts → esm/sql-objects/operators/op-gt.d.ts} +3 -3
  127. package/esm/sql-objects/operators/op-gt.js +9 -0
  128. package/{dist/sql-objects/operators/OpGte.d.ts → esm/sql-objects/operators/op-gte.d.ts} +3 -3
  129. package/esm/sql-objects/operators/op-gte.js +9 -0
  130. package/{dist/sql-objects/operators/OpILike.d.ts → esm/sql-objects/operators/op-ilike.d.ts} +2 -2
  131. package/esm/sql-objects/operators/op-ilike.js +6 -0
  132. package/{dist/sql-objects/operators/OpIn.d.ts → esm/sql-objects/operators/op-in.d.ts} +3 -3
  133. package/esm/sql-objects/operators/op-in.js +15 -0
  134. package/{dist/sql-objects/operators/OpIsNot.d.ts → esm/sql-objects/operators/op-is-not.d.ts} +3 -3
  135. package/esm/sql-objects/operators/op-is-not.js +9 -0
  136. package/{dist/sql-objects/operators/OpIs.d.ts → esm/sql-objects/operators/op-is.d.ts} +3 -3
  137. package/esm/sql-objects/operators/op-is.js +9 -0
  138. package/{dist/sql-objects/operators/OpLike.d.ts → esm/sql-objects/operators/op-like.d.ts} +4 -4
  139. package/esm/sql-objects/operators/op-like.js +18 -0
  140. package/{dist/sql-objects/operators/OpLt.d.ts → esm/sql-objects/operators/op-lt.d.ts} +3 -3
  141. package/esm/sql-objects/operators/op-lt.js +9 -0
  142. package/{dist/sql-objects/operators/OpLte.d.ts → esm/sql-objects/operators/op-lte.d.ts} +3 -3
  143. package/esm/sql-objects/operators/op-lte.js +9 -0
  144. package/{dist/sql-objects/operators/OpNe.d.ts → esm/sql-objects/operators/op-ne.d.ts} +3 -3
  145. package/esm/sql-objects/operators/op-ne.js +9 -0
  146. package/{dist/sql-objects/operators/OpNotBetween.d.ts → esm/sql-objects/operators/op-not-between.d.ts} +2 -2
  147. package/esm/sql-objects/operators/op-not-between.js +6 -0
  148. package/{dist/sql-objects/operators/OpNotExists.d.ts → esm/sql-objects/operators/op-not-exists.d.ts} +2 -2
  149. package/esm/sql-objects/operators/op-not-exists.js +6 -0
  150. package/{dist/sql-objects/operators/OpNotILike.d.ts → esm/sql-objects/operators/op-not-ilike.d.ts} +2 -2
  151. package/esm/sql-objects/operators/op-not-ilike.js +6 -0
  152. package/{dist/sql-objects/operators/OpNotIn.d.ts → esm/sql-objects/operators/op-not-in.d.ts} +2 -2
  153. package/esm/sql-objects/operators/op-not-in.js +6 -0
  154. package/{dist/sql-objects/operators/OpNotLike.d.ts → esm/sql-objects/operators/op-not-like.d.ts} +2 -2
  155. package/esm/sql-objects/operators/op-not-like.js +6 -0
  156. package/esm/sql-objects/operators/op-or.d.ts +5 -0
  157. package/esm/sql-objects/operators/op-or.js +5 -0
  158. package/{dist/sql-objects/OrderColumn.d.ts → esm/sql-objects/order-column.d.ts} +3 -3
  159. package/esm/sql-objects/order-column.js +39 -0
  160. package/{dist/sql-objects/ParamExpression.d.ts → esm/sql-objects/param-expression.d.ts} +3 -3
  161. package/esm/sql-objects/param-expression.js +52 -0
  162. package/{dist/sql-objects/RawStatement.d.ts → esm/sql-objects/raw-statement.d.ts} +3 -3
  163. package/esm/sql-objects/raw-statement.js +15 -0
  164. package/{dist/sql-objects/ReturningColumn.d.ts → esm/sql-objects/returning-column.d.ts} +3 -3
  165. package/esm/sql-objects/returning-column.js +29 -0
  166. package/esm/sql-objects/sequence-getter-statement.d.ts +24 -0
  167. package/esm/sql-objects/sequence-getter-statement.js +47 -0
  168. package/esm/sql-objects/string-agg-statement.d.ts +31 -0
  169. package/esm/sql-objects/string-agg-statement.js +78 -0
  170. package/{dist/sql-objects/TableName.d.ts → esm/sql-objects/table-name.d.ts} +3 -3
  171. package/esm/sql-objects/table-name.js +30 -0
  172. package/esm/sql-objects/upper-statement.d.ts +22 -0
  173. package/esm/sql-objects/upper-statement.js +37 -0
  174. package/esm/sqlobject.initializers.d.ts +54 -0
  175. package/esm/sqlobject.initializers.js +101 -0
  176. package/{dist → esm}/typeguards.d.ts +18 -17
  177. package/esm/typeguards.js +57 -0
  178. package/{dist → esm}/types.d.ts +2 -2
  179. package/esm/types.js +1 -0
  180. package/package.json +49 -34
  181. package/dist/classes.d.ts +0 -38
  182. package/dist/classes.js +0 -41
  183. package/dist/index.d.ts +0 -20
  184. package/dist/index.js +0 -27
  185. package/dist/sql-objects/BaseField.js +0 -11
  186. package/dist/sql-objects/Expression.js +0 -7
  187. package/dist/sql-objects/operators/OpAnd.d.ts +0 -5
  188. package/dist/sql-objects/operators/OpAnd.js +0 -12
  189. package/dist/sql-objects/operators/OpEq.js +0 -13
  190. package/dist/sql-objects/operators/OpGt.js +0 -13
  191. package/dist/sql-objects/operators/OpGte.js +0 -13
  192. package/dist/sql-objects/operators/OpILike.js +0 -13
  193. package/dist/sql-objects/operators/OpIn.js +0 -19
  194. package/dist/sql-objects/operators/OpIs.js +0 -13
  195. package/dist/sql-objects/operators/OpIsNot.js +0 -13
  196. package/dist/sql-objects/operators/OpLt.js +0 -13
  197. package/dist/sql-objects/operators/OpLte.js +0 -13
  198. package/dist/sql-objects/operators/OpNe.js +0 -13
  199. package/dist/sql-objects/operators/OpNotBetween.js +0 -13
  200. package/dist/sql-objects/operators/OpNotExists.js +0 -13
  201. package/dist/sql-objects/operators/OpNotILike.js +0 -13
  202. package/dist/sql-objects/operators/OpNotIn.js +0 -13
  203. package/dist/sql-objects/operators/OpNotLike.js +0 -13
  204. package/dist/sql-objects/operators/OpOr.d.ts +0 -5
  205. package/dist/sql-objects/operators/OpOr.js +0 -12
  206. package/dist/sqlobject.initializers.d.ts +0 -39
  207. package/dist/sqlobject.initializers.js +0 -90
  208. 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/SelectQuery';
2
- import { Serializable } from './Serializable';
3
- import { Operator } from './sql-objects/Operator';
4
- import { OpAnd } from './sql-objects/operators/OpAnd';
5
- import { OpEq } from './sql-objects/operators/OpEq';
6
- import { OpExists } from './sql-objects/operators/OpExists';
7
- import { OpGt } from './sql-objects/operators/OpGt';
8
- import { OpGte } from './sql-objects/operators/OpGte';
9
- import { OpILike } from './sql-objects/operators/OpILike';
10
- import { OpIn } from './sql-objects/operators/OpIn';
11
- import { OpIs } from './sql-objects/operators/OpIs';
12
- import { OpIsNot } from './sql-objects/operators/OpIsNot';
13
- import { OpLike } from './sql-objects/operators/OpLike';
14
- import { OpLt } from './sql-objects/operators/OpLt';
15
- import { OpLte } from './sql-objects/operators/OpLte';
16
- import { OpNe } from './sql-objects/operators/OpNe';
17
- import { OpNotExists } from './sql-objects/operators/OpNotExists';
18
- import { OpNotILike } from './sql-objects/operators/OpNotILike';
19
- import { OpNotIn } from './sql-objects/operators/OpNotIn';
20
- import { OpNotLike } from './sql-objects/operators/OpNotLike';
21
- import { OpOr } from './sql-objects/operators/OpOr';
22
- import { RawStatement } from './sql-objects/RawStatement';
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 '../SerializeContext';
3
- import { LogicalOperator } from '../sql-objects/operators/LogicalOperator';
4
- import { RawStatement } from '../sql-objects/RawStatement';
5
- import { TableName } from '../sql-objects/TableName';
6
- import { Query } from './Query';
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 '../SerializeContext';
3
- import type { RawStatement } from '../sql-objects/RawStatement';
4
- import { TableName } from '../sql-objects/TableName';
5
- import { ReturningQuery } from './ReturningQuery';
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 '../Serializable';
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 '../SerializeContext';
2
- import { ReturningColumn } from '../sql-objects/ReturningColumn';
3
- import { Query } from './Query';
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
+ }