@sqb/builder 4.2.1 → 4.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (206) hide show
  1. package/README.md +2 -2
  2. package/cjs/classes.ns.js +41 -0
  3. package/{dist → cjs}/enums.js +6 -3
  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} +15 -13
  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} +17 -14
  15. package/{dist/Serializable.js → cjs/serializable.js} +0 -0
  16. package/{dist/SerializeContext.js → cjs/serialize-context.js} +36 -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/{dist/sql-objects/CoalesceStatement.js → cjs/sql-objects/coalesce-statement.js} +6 -4
  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/{dist/sql-objects/LowerStatement.js → cjs/sql-objects/lower-statement.js} +6 -4
  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} +17 -13
  30. package/{dist/sql-objects/operators/LogicalOperator.js → cjs/sql-objects/operators/logical-operator.js} +11 -11
  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/{dist/sql-objects/UpperStatement.js → cjs/sql-objects/upper-statement.js} +6 -4
  59. package/cjs/sqlobject.initializers.js +129 -0
  60. package/{dist → cjs}/typeguards.js +21 -21
  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 +6 -3
  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} +9 -9
  83. package/{dist/query/SelectQuery.js → esm/query/select-query.js} +38 -32
  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/{dist/sql-objects/CoalesceStatement.d.ts → esm/sql-objects/coalesce-statement.d.ts} +3 -3
  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/{dist/sql-objects/LowerStatement.d.ts → esm/sql-objects/lower-statement.d.ts} +3 -3
  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/{dist/sql-objects/StringAggStatement.d.ts → esm/sql-objects/string-agg-statement.d.ts} +4 -4
  169. package/{dist/sql-objects/StringAggStatement.js → esm/sql-objects/string-agg-statement.js} +15 -15
  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/{dist/sql-objects/UpperStatement.d.ts → esm/sql-objects/upper-statement.d.ts} +3 -3
  173. package/esm/sql-objects/upper-statement.js +37 -0
  174. package/{dist → esm}/sqlobject.initializers.d.ts +23 -16
  175. package/esm/sqlobject.initializers.js +101 -0
  176. package/{dist → esm}/typeguards.d.ts +17 -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 +48 -33
  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.js +0 -110
@@ -0,0 +1,294 @@
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 += (o.columns.indexOf('\n') >= 0) ?
165
+ '\n\t' + o.columns + '\b' :
166
+ ' ' + o.columns;
167
+ }
168
+ // from part
169
+ if (o.from) {
170
+ out += (o.columns.length > 60 ||
171
+ o.columns.indexOf('\n') >= 0 ? '\n' : ' ') +
172
+ o.from;
173
+ }
174
+ // join part
175
+ if (o.join)
176
+ out += '\n' + o.join;
177
+ // where part
178
+ if (o.where)
179
+ out += '\n' + o.where;
180
+ // group by part
181
+ if (o.groupBy)
182
+ out += '\n' + o.groupBy;
183
+ // order by part
184
+ if (o.orderBy)
185
+ out += '\n' + o.orderBy;
186
+ return out;
187
+ });
188
+ }
189
+ /**
190
+ *
191
+ */
192
+ __serializeSelectColumns(ctx) {
193
+ const arr = [];
194
+ if (this._columns)
195
+ for (const t of this._columns) {
196
+ const s = ctx.anyToSQL(t);
197
+ // t._serialize(ctx);
198
+ if (s) {
199
+ if (t instanceof SelectQuery) {
200
+ if (!t._alias)
201
+ throw new TypeError('Alias required for sub-select in columns');
202
+ arr.push(s + ' ' + t._alias);
203
+ }
204
+ else
205
+ arr.push(s);
206
+ }
207
+ }
208
+ return ctx.serialize(enums_js_1.SerializationType.SELECT_QUERY_COLUMNS, arr, () => (0, helpers_js_1.printArray)(arr) || '*');
209
+ }
210
+ /**
211
+ *
212
+ */
213
+ __serializeFrom(ctx) {
214
+ const arr = [];
215
+ if (this._tables)
216
+ for (const t of this._tables) {
217
+ const s = t._serialize(ctx);
218
+ /* istanbul ignore else */
219
+ if (s) {
220
+ if (t instanceof SelectQuery) {
221
+ if (!t._alias)
222
+ throw new TypeError('Alias required for sub-select in "from"');
223
+ arr.push('\n\t(' + s + ') ' + t._alias);
224
+ }
225
+ else
226
+ arr.push(s);
227
+ }
228
+ }
229
+ return ctx.serialize(enums_js_1.SerializationType.SELECT_QUERY_FROM, arr, () => {
230
+ const s = arr.join(',');
231
+ return s ? ('from' + (s.substring(0, 1) !== '\n' ? ' ' : '') + s) : '';
232
+ });
233
+ }
234
+ /**
235
+ *
236
+ */
237
+ __serializeJoins(ctx) {
238
+ const arr = [];
239
+ if (this._joins)
240
+ for (const t of this._joins) {
241
+ const s = t._serialize(ctx);
242
+ /* istanbul ignore else */
243
+ if (s)
244
+ arr.push(s);
245
+ }
246
+ return ctx.serialize(enums_js_1.SerializationType.SELECT_QUERY_JOIN, arr, () => {
247
+ return arr.join('\n');
248
+ });
249
+ }
250
+ /**
251
+ *
252
+ */
253
+ __serializeWhere(ctx) {
254
+ if (!this._where)
255
+ return '';
256
+ const s = this._where._serialize(ctx);
257
+ return ctx.serialize(enums_js_1.SerializationType.CONDITIONS_BLOCK, s, () => {
258
+ /* istanbul ignore next */
259
+ return s ? 'where ' + s : '';
260
+ });
261
+ }
262
+ /**
263
+ *
264
+ */
265
+ __serializeGroupColumns(ctx) {
266
+ const arr = [];
267
+ if (this._groupBy)
268
+ for (const t of this._groupBy) {
269
+ const s = t._serialize(ctx);
270
+ /* istanbul ignore else */
271
+ if (s)
272
+ arr.push(s);
273
+ }
274
+ return ctx.serialize(enums_js_1.SerializationType.SELECT_QUERY_GROUPBY, arr, () => {
275
+ const s = (0, helpers_js_1.printArray)(arr);
276
+ return s ? 'group by ' + s : '';
277
+ });
278
+ }
279
+ __serializeOrderColumns(ctx) {
280
+ const arr = [];
281
+ if (this._orderBy)
282
+ for (const t of this._orderBy) {
283
+ const s = t._serialize(ctx);
284
+ /* istanbul ignore else */
285
+ if (s)
286
+ arr.push(s);
287
+ }
288
+ return ctx.serialize(enums_js_1.SerializationType.SELECT_QUERY_ORDERBY, arr, () => {
289
+ const s = (0, helpers_js_1.printArray)(arr);
290
+ return s ? 'order by ' + s : '';
291
+ });
292
+ }
293
+ }
294
+ exports.SelectQuery = SelectQuery;
@@ -1,31 +1,34 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.UpdateQuery = void 0;
4
- const enums_1 = require("../enums");
5
- const helpers_1 = require("../helpers");
6
- const OpAnd_1 = require("../sql-objects/operators/OpAnd");
7
- const TableName_1 = require("../sql-objects/TableName");
8
- const typeguards_1 = require("../typeguards");
9
- const ReturningQuery_1 = require("./ReturningQuery");
10
- class UpdateQuery extends ReturningQuery_1.ReturningQuery {
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;
11
14
  constructor(tableName, input) {
12
15
  super();
13
- if (!tableName || !(typeof tableName === 'string' || (0, typeguards_1.isRawStatement)(tableName)))
16
+ if (!tableName || !(typeof tableName === 'string' || (0, typeguards_js_1.isRawStatement)(tableName)))
14
17
  throw new TypeError('String or Raw instance required as first argument (tableName) for UpdateQuery');
15
18
  if (!input || !((typeof input === 'object' && !Array.isArray(input)) ||
16
19
  input.isSelect))
17
20
  throw new TypeError('Object or Raw instance required as second argument (input) for UpdateQuery');
18
- this._table = typeof tableName === 'string' ? new TableName_1.TableName(tableName) : tableName;
21
+ this._table = typeof tableName === 'string' ? new table_name_js_1.TableName(tableName) : tableName;
19
22
  this._input = input;
20
23
  }
21
24
  get _type() {
22
- return enums_1.SerializationType.UPDATE_QUERY;
25
+ return enums_js_1.SerializationType.UPDATE_QUERY;
23
26
  }
24
27
  /**
25
28
  * Defines "where" part of query
26
29
  */
27
30
  where(...operator) {
28
- this._where = this._where || new OpAnd_1.OpAnd();
31
+ this._where = this._where || new op_and_js_1.OpAnd();
29
32
  this._where.add(...operator);
30
33
  return this;
31
34
  }
@@ -59,9 +62,9 @@ class UpdateQuery extends ReturningQuery_1.ReturningQuery {
59
62
  value
60
63
  });
61
64
  }
62
- return ctx.serialize(enums_1.SerializationType.UPDATE_QUERY_VALUES, arr, () => {
65
+ return ctx.serialize(enums_js_1.SerializationType.UPDATE_QUERY_VALUES, arr, () => {
63
66
  const a = arr.map(o => o.field + ' = ' + o.value);
64
- return (0, helpers_1.printArray)(a, ',');
67
+ return (0, helpers_js_1.printArray)(a, ',');
65
68
  });
66
69
  }
67
70
  /**
@@ -71,7 +74,7 @@ class UpdateQuery extends ReturningQuery_1.ReturningQuery {
71
74
  if (!this._where)
72
75
  return '';
73
76
  const s = this._where._serialize(ctx);
74
- return ctx.serialize(enums_1.SerializationType.CONDITIONS_BLOCK, s, () => {
77
+ return ctx.serialize(enums_js_1.SerializationType.CONDITIONS_BLOCK, s, () => {
75
78
  /* istanbul ignore next */
76
79
  return s ? 'where ' + s : '';
77
80
  });
File without changes
@@ -1,24 +1,34 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SerializeContext = void 0;
4
- const enums_1 = require("./enums");
5
- const extensions_1 = require("./extensions");
6
- const Serializable_1 = require("./Serializable");
7
- const typeguards_1 = require("./typeguards");
4
+ const enums_js_1 = require("./enums.js");
5
+ const extensions_js_1 = require("./extensions.js");
6
+ const serializable_js_1 = require("./serializable.js");
7
+ const typeguards_js_1 = require("./typeguards.js");
8
8
  class SerializeContext {
9
+ reservedWords = [
10
+ 'schema', 'table', 'field', 'index', 'foreign', 'key',
11
+ 'select', 'insert', 'update', 'delete', 'with', 'merge',
12
+ 'join', 'inner', 'outer', 'left', 'right', 'full',
13
+ 'from', 'where', 'order', 'by', 'group', 'having',
14
+ 'acs', 'ascending', 'dsc', 'descending', 'distinct',
15
+ 'and', 'or', 'not', 'between', 'null', 'like', 'ilike',
16
+ 'count', 'sum', 'average', 'avg', 'cascade', 'authorization',
17
+ 'create', 'add', 'drop', 'alter', 'index', 'private', 'sequence',
18
+ 'default', 'constraint', 'references', 'primary', 'foreign',
19
+ 'user', 'password'
20
+ ];
21
+ dialect;
22
+ prettyPrint;
23
+ params;
24
+ dialectVersion;
25
+ strictParams;
26
+ serializeHooks;
27
+ paramOptions;
28
+ preparedParams;
29
+ returningFields;
30
+ strictParamGenId;
9
31
  constructor(opts) {
10
- this.reservedWords = [
11
- 'schema', 'table', 'field', 'index', 'foreign', 'key',
12
- 'select', 'insert', 'update', 'delete', 'with', 'merge',
13
- 'join', 'inner', 'outer', 'left', 'right', 'full',
14
- 'from', 'where', 'order', 'by', 'group', 'having',
15
- 'acs', 'ascending', 'dsc', 'descending', 'distinct',
16
- 'and', 'or', 'not', 'between', 'null', 'like', 'ilike',
17
- 'count', 'sum', 'average', 'avg', 'cascade', 'authorization',
18
- 'create', 'add', 'drop', 'alter', 'index', 'private', 'sequence',
19
- 'default', 'constraint', 'references', 'primary', 'foreign',
20
- 'user', 'password'
21
- ];
22
32
  if (opts)
23
33
  Object.assign(this, opts);
24
34
  }
@@ -33,7 +43,7 @@ class SerializeContext {
33
43
  return s;
34
44
  }
35
45
  }
36
- for (const ext of extensions_1.serializers) {
46
+ for (const ext of extensions_js_1.serializers) {
37
47
  if (ext.dialect === this.dialect && ext.serialize) {
38
48
  const s = ext.serialize(this, type, o, fallback);
39
49
  if (s != null)
@@ -50,29 +60,29 @@ class SerializeContext {
50
60
  return 'null';
51
61
  if (Array.isArray(v)) {
52
62
  const vv = v.map(x => this.anyToSQL(x));
53
- return this.serialize(enums_1.SerializationType.ARRAY, vv, () => '(' + v.join(',')) + ')';
63
+ return this.serialize(enums_js_1.SerializationType.ARRAY, vv, () => '(' + v.join(',')) + ')';
54
64
  }
55
65
  if (typeof v === 'object') {
56
- if ((0, typeguards_1.isSerializable)(v)) {
66
+ if ((0, typeguards_js_1.isSerializable)(v)) {
57
67
  const s = v._serialize(this);
58
- return s ? ((0, typeguards_1.isQuery)(v) || (0, typeguards_1.isLogicalOperator)(v) ? '(' + s + ')' : s) :
68
+ return s ? ((0, typeguards_js_1.isQuery)(v) || (0, typeguards_js_1.isLogicalOperator)(v) ? '(' + s + ')' : s) :
59
69
  /* istanbul ignore next */
60
70
  '';
61
71
  }
62
72
  if (v instanceof Date) {
63
- return this.serialize(enums_1.SerializationType.DATE_VALUE, v, () => this.dateToSQL(v));
73
+ return this.serialize(enums_js_1.SerializationType.DATE_VALUE, v, () => this.dateToSQL(v));
64
74
  }
65
75
  }
66
76
  if (typeof v === 'string') {
67
- return this.serialize(enums_1.SerializationType.STRING_VALUE, v, () => this.stringToSQL(v));
77
+ return this.serialize(enums_js_1.SerializationType.STRING_VALUE, v, () => this.stringToSQL(v));
68
78
  }
69
79
  if (typeof v === 'boolean') {
70
- return this.serialize(enums_1.SerializationType.BOOLEAN_VALUE, v, () => this.booleanToSQL(v));
80
+ return this.serialize(enums_js_1.SerializationType.BOOLEAN_VALUE, v, () => this.booleanToSQL(v));
71
81
  }
72
82
  if (typeof v === 'number') {
73
- return this.serialize(enums_1.SerializationType.NUMBER_VALUE, v, () => this.numberToSQL(v));
83
+ return this.serialize(enums_js_1.SerializationType.NUMBER_VALUE, v, () => this.numberToSQL(v));
74
84
  }
75
- if (v instanceof Serializable_1.Serializable)
85
+ if (v instanceof serializable_js_1.Serializable)
76
86
  return v._serialize(this);
77
87
  return v;
78
88
  }
@@ -120,7 +130,7 @@ class SerializeContext {
120
130
  return false;
121
131
  if (this.reservedWords.includes(s.toLowerCase()))
122
132
  return true;
123
- for (const ext of extensions_1.serializers) {
133
+ for (const ext of extensions_js_1.serializers) {
124
134
  if (ext.dialect === this.dialect && ext.isReservedWord) {
125
135
  if (ext.isReservedWord(this, s))
126
136
  return true;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BaseField = void 0;
4
+ const expression_js_1 = require("./expression.js");
5
+ class BaseField extends expression_js_1.Expression {
6
+ _field = '';
7
+ _schema;
8
+ _table;
9
+ _descending;
10
+ }
11
+ exports.BaseField = BaseField;
@@ -1,23 +1,27 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.CaseStatement = void 0;
4
- const enums_1 = require("../enums");
5
- const Serializable_1 = require("../Serializable");
6
- const OpAnd_1 = require("./operators/OpAnd");
7
- class CaseStatement extends Serializable_1.Serializable {
4
+ const enums_js_1 = require("../enums.js");
5
+ const serializable_js_1 = require("../serializable.js");
6
+ const op_and_js_1 = require("./operators/op-and.js");
7
+ class CaseStatement extends serializable_js_1.Serializable {
8
+ _expressions;
9
+ _elseValue;
10
+ _condition;
11
+ _alias;
8
12
  constructor() {
9
13
  super();
10
14
  this._expressions = [];
11
15
  }
12
16
  get _type() {
13
- return enums_1.SerializationType.CASE_STATEMENT;
17
+ return enums_js_1.SerializationType.CASE_STATEMENT;
14
18
  }
15
19
  /**
16
20
  * Defines "when" part of Case expression.
17
21
  */
18
22
  when(...condition) {
19
23
  if (condition.length)
20
- this._condition = new OpAnd_1.OpAnd(...condition);
24
+ this._condition = new op_and_js_1.OpAnd(...condition);
21
25
  else
22
26
  this._condition = undefined;
23
27
  return this;
@@ -1,15 +1,17 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.CoalesceStatement = void 0;
4
- const enums_1 = require("../enums");
5
- const Serializable_1 = require("../Serializable");
6
- class CoalesceStatement extends Serializable_1.Serializable {
4
+ const enums_js_1 = require("../enums.js");
5
+ const serializable_js_1 = require("../serializable.js");
6
+ class CoalesceStatement extends serializable_js_1.Serializable {
7
+ _expressions;
8
+ _alias;
7
9
  constructor(...expressions) {
8
10
  super();
9
11
  this._expressions = expressions;
10
12
  }
11
13
  get _type() {
12
- return enums_1.SerializationType.COALESCE_STATEMENT;
14
+ return enums_js_1.SerializationType.COALESCE_STATEMENT;
13
15
  }
14
16
  /**
15
17
  * Sets alias to case expression.
@@ -1,11 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.CountStatement = void 0;
4
- const enums_1 = require("../enums");
5
- const Serializable_1 = require("../Serializable");
6
- class CountStatement extends Serializable_1.Serializable {
4
+ const enums_js_1 = require("../enums.js");
5
+ const serializable_js_1 = require("../serializable.js");
6
+ class CountStatement extends serializable_js_1.Serializable {
7
+ _alias;
7
8
  get _type() {
8
- return enums_1.SerializationType.COUNT_STATEMENT;
9
+ return enums_js_1.SerializationType.COUNT_STATEMENT;
9
10
  }
10
11
  /**
11
12
  * Sets alias to case expression.
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Expression = void 0;
4
+ const serializable_js_1 = require("../serializable.js");
5
+ class Expression extends serializable_js_1.Serializable {
6
+ _dataType;
7
+ _isArray;
8
+ _isDataSet;
9
+ }
10
+ exports.Expression = Expression;
@@ -1,10 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.FieldExpression = void 0;
4
- const enums_1 = require("../enums");
5
- const BaseField_1 = require("./BaseField");
4
+ const enums_js_1 = require("../enums.js");
5
+ const base_field_js_1 = require("./base-field.js");
6
6
  const TABLE_COLUMN_PATTERN = /^((?:[a-zA-Z_][\w$_]*\.){0,2}) *([0-9a-zA-Z_][\w$_]*|\*) *(?:as)? *([a-zA-Z_][\w$_]*)?$/;
7
- class FieldExpression extends BaseField_1.BaseField {
7
+ class FieldExpression extends base_field_js_1.BaseField {
8
+ _alias;
8
9
  constructor(arg0, arg1, arg2) {
9
10
  super();
10
11
  let expression;
@@ -31,7 +32,7 @@ class FieldExpression extends BaseField_1.BaseField {
31
32
  this._alias = this._field !== '*' ? m[3] : '';
32
33
  }
33
34
  get _type() {
34
- return enums_1.SerializationType.SELECT_COLUMN;
35
+ return enums_js_1.SerializationType.FIELD_NAME;
35
36
  }
36
37
  _serialize(ctx) {
37
38
  const o = {
@@ -1,10 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.GroupColumn = void 0;
4
- const enums_1 = require("../enums");
5
- const BaseField_1 = require("./BaseField");
4
+ const enums_js_1 = require("../enums.js");
5
+ const base_field_js_1 = require("./base-field.js");
6
6
  const GROUP_COLUMN_PATTERN = /^((?:[a-zA-Z][\w$]*\.){0,2})([\w$]*)$/;
7
- class GroupColumn extends BaseField_1.BaseField {
7
+ class GroupColumn extends base_field_js_1.BaseField {
8
8
  constructor(value) {
9
9
  super();
10
10
  const m = value.match(GROUP_COLUMN_PATTERN);
@@ -19,7 +19,7 @@ class GroupColumn extends BaseField_1.BaseField {
19
19
  }
20
20
  }
21
21
  get _type() {
22
- return enums_1.SerializationType.GROUP_COLUMN;
22
+ return enums_js_1.SerializationType.GROUP_COLUMN;
23
23
  }
24
24
  _serialize(ctx) {
25
25
  const o = {