@sqb/builder 4.20.6 → 4.21.0

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