@riao/dbal 3.8.0 → 3.9.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 (269) hide show
  1. package/CHANGELOG.md +3 -3
  2. package/LICENSE.md +20 -20
  3. package/README.md +148 -148
  4. package/builder/builder.d.ts +7 -7
  5. package/builder/builder.js +19 -19
  6. package/builder/index.d.ts +2 -2
  7. package/builder/index.js +7 -7
  8. package/builder/sql-builder.d.ts +54 -53
  9. package/builder/sql-builder.js +161 -157
  10. package/builder/sql-builder.js.map +1 -1
  11. package/builder/statement-builder.d.ts +12 -12
  12. package/builder/statement-builder.js +32 -32
  13. package/column/column-options.d.ts +156 -156
  14. package/column/column-options.js +2 -2
  15. package/column/column-type.d.ts +18 -18
  16. package/column/column-type.js +27 -27
  17. package/column/column-values.d.ts +34 -34
  18. package/column/column-values.js +2 -2
  19. package/column/create-column-template.d.ts +11 -0
  20. package/column/create-column-template.js +57 -0
  21. package/column/create-column-template.js.map +1 -0
  22. package/column/index.d.ts +4 -3
  23. package/column/index.js +20 -19
  24. package/column/index.js.map +1 -1
  25. package/column-pack/date-time/create-timestamp-column.d.ts +2 -2
  26. package/column-pack/date-time/create-timestamp-column.js +10 -10
  27. package/column-pack/date-time/index.d.ts +2 -2
  28. package/column-pack/date-time/index.js +7 -7
  29. package/column-pack/date-time/update-timestamp-column.d.ts +2 -2
  30. package/column-pack/date-time/update-timestamp-column.js +14 -14
  31. package/column-pack/index.d.ts +6 -6
  32. package/column-pack/index.js +22 -22
  33. package/column-pack/keys/big-int-key-column.d.ts +2 -2
  34. package/column-pack/keys/big-int-key-column.js +10 -10
  35. package/column-pack/keys/index.d.ts +3 -3
  36. package/column-pack/keys/index.js +9 -9
  37. package/column-pack/keys/int-key-column.d.ts +2 -2
  38. package/column-pack/keys/int-key-column.js +10 -10
  39. package/column-pack/keys/uuid-key-column.d.ts +2 -2
  40. package/column-pack/keys/uuid-key-column.js +11 -11
  41. package/column-pack/person/date-of-birth-column.d.ts +2 -2
  42. package/column-pack/person/date-of-birth-column.js +8 -8
  43. package/column-pack/person/first-name-column.d.ts +2 -2
  44. package/column-pack/person/first-name-column.js +9 -9
  45. package/column-pack/person/index.d.ts +3 -3
  46. package/column-pack/person/index.js +9 -9
  47. package/column-pack/person/last-name-column.d.ts +2 -2
  48. package/column-pack/person/last-name-column.js +9 -9
  49. package/column-pack/resource/content-column.d.ts +2 -2
  50. package/column-pack/resource/content-column.js +9 -9
  51. package/column-pack/resource/description-column.d.ts +2 -2
  52. package/column-pack/resource/description-column.js +9 -9
  53. package/column-pack/resource/index.d.ts +6 -6
  54. package/column-pack/resource/index.js +15 -15
  55. package/column-pack/resource/is-active-column.d.ts +2 -2
  56. package/column-pack/resource/is-active-column.js +9 -9
  57. package/column-pack/resource/name-column.d.ts +2 -2
  58. package/column-pack/resource/name-column.js +10 -10
  59. package/column-pack/resource/path-column.d.ts +2 -2
  60. package/column-pack/resource/path-column.js +11 -11
  61. package/column-pack/resource/title-column.d.ts +2 -2
  62. package/column-pack/resource/title-column.js +10 -10
  63. package/column-pack/system/filename-column.d.ts +2 -2
  64. package/column-pack/system/filename-column.js +9 -9
  65. package/column-pack/system/filepath-column.d.ts +2 -2
  66. package/column-pack/system/filepath-column.js +9 -9
  67. package/column-pack/system/index.d.ts +4 -4
  68. package/column-pack/system/index.js +11 -11
  69. package/column-pack/system/ip-address-column.d.ts +2 -2
  70. package/column-pack/system/ip-address-column.js +9 -9
  71. package/column-pack/system/url-column.d.ts +3 -3
  72. package/column-pack/system/url-column.js +13 -13
  73. package/column-pack/user/email-column.d.ts +2 -2
  74. package/column-pack/user/email-column.js +11 -11
  75. package/column-pack/user/index.d.ts +4 -4
  76. package/column-pack/user/index.js +11 -11
  77. package/column-pack/user/password-column.d.ts +2 -2
  78. package/column-pack/user/password-column.js +10 -10
  79. package/column-pack/user/temp-email-column.d.ts +2 -2
  80. package/column-pack/user/temp-email-column.js +5 -5
  81. package/column-pack/user/username-column.d.ts +2 -2
  82. package/column-pack/user/username-column.js +11 -11
  83. package/comparison/comparison-aliases.d.ts +10 -10
  84. package/comparison/comparison-aliases.js +40 -40
  85. package/comparison/comparison-token.d.ts +17 -17
  86. package/comparison/comparison-token.js +15 -15
  87. package/comparison/comparison.d.ts +13 -13
  88. package/comparison/comparison.js +71 -71
  89. package/comparison/index.d.ts +4 -4
  90. package/comparison/index.js +24 -24
  91. package/comparison/is-comparison-token.d.ts +2 -2
  92. package/comparison/is-comparison-token.js +8 -8
  93. package/config/configure-db.d.ts +14 -14
  94. package/config/configure-db.js +18 -18
  95. package/config/database-env.d.ts +16 -16
  96. package/config/database-env.js +14 -14
  97. package/config/index.d.ts +2 -2
  98. package/config/index.js +7 -7
  99. package/database/connection-options.d.ts +7 -7
  100. package/database/connection-options.js +2 -2
  101. package/database/database.d.ts +204 -204
  102. package/database/database.js +330 -330
  103. package/database/driver-query.d.ts +10 -10
  104. package/database/driver-query.js +2 -2
  105. package/database/driver.d.ts +12 -12
  106. package/database/driver.js +47 -47
  107. package/database/get-database-path.d.ts +6 -6
  108. package/database/get-database-path.js +12 -12
  109. package/database/index.d.ts +7 -7
  110. package/database/index.js +26 -26
  111. package/database/load-database.d.ts +9 -9
  112. package/database/load-database.js +36 -36
  113. package/database/transaction.d.ts +8 -8
  114. package/database/transaction.js +2 -2
  115. package/ddl/alter-table.d.ts +26 -26
  116. package/ddl/alter-table.js +2 -2
  117. package/ddl/create-database.d.ts +3 -3
  118. package/ddl/create-database.js +2 -2
  119. package/ddl/create-index.d.ts +5 -5
  120. package/ddl/create-index.js +2 -2
  121. package/ddl/create-table.d.ts +8 -8
  122. package/ddl/create-table.js +2 -2
  123. package/ddl/create-user.d.ts +4 -4
  124. package/ddl/create-user.js +2 -2
  125. package/ddl/ddl-builder.d.ts +96 -96
  126. package/ddl/ddl-builder.js +565 -565
  127. package/ddl/ddl-repository.d.ts +135 -135
  128. package/ddl/ddl-repository.js +228 -228
  129. package/ddl/drop-database.d.ts +4 -4
  130. package/ddl/drop-database.js +2 -2
  131. package/ddl/drop-table.d.ts +4 -4
  132. package/ddl/drop-table.js +2 -2
  133. package/ddl/drop-user.d.ts +4 -4
  134. package/ddl/drop-user.js +2 -2
  135. package/ddl/foreign-key-constraint.d.ts +19 -19
  136. package/ddl/foreign-key-constraint.js +2 -2
  137. package/ddl/grant.d.ts +12 -12
  138. package/ddl/grant.js +2 -2
  139. package/ddl/index.d.ts +13 -13
  140. package/ddl/index.js +23 -23
  141. package/ddl/truncate.d.ts +3 -3
  142. package/ddl/truncate.js +2 -2
  143. package/dml/case-expression.d.ts +16 -16
  144. package/dml/case-expression.js +11 -11
  145. package/dml/delete.d.ts +8 -8
  146. package/dml/delete.js +2 -2
  147. package/dml/from.d.ts +4 -4
  148. package/dml/from.js +2 -2
  149. package/dml/group-by.d.ts +4 -4
  150. package/dml/group-by.js +2 -2
  151. package/dml/index.d.ts +11 -11
  152. package/dml/index.js +30 -30
  153. package/dml/insert.d.ts +14 -14
  154. package/dml/insert.js +2 -2
  155. package/dml/join.d.ts +7 -7
  156. package/dml/join.js +2 -2
  157. package/dml/order-by.d.ts +2 -2
  158. package/dml/order-by.js +2 -2
  159. package/dml/query-builder.d.ts +125 -106
  160. package/dml/query-builder.js +991 -793
  161. package/dml/query-builder.js.map +1 -1
  162. package/dml/query-repository.d.ts +84 -84
  163. package/dml/query-repository.js +239 -225
  164. package/dml/query-repository.js.map +1 -1
  165. package/dml/select.d.ts +44 -29
  166. package/dml/select.js +2 -2
  167. package/dml/set-options.d.ts +5 -5
  168. package/dml/set-options.js +2 -2
  169. package/dml/subquery.d.ts +5 -5
  170. package/dml/subquery.js +10 -10
  171. package/dml/update.d.ts +11 -11
  172. package/dml/update.js +2 -2
  173. package/expression/expression-token.d.ts +11 -11
  174. package/expression/expression-token.js +12 -12
  175. package/expression/expression.d.ts +6 -6
  176. package/expression/expression.js +2 -2
  177. package/expression/identifier.d.ts +7 -7
  178. package/expression/identifier.js +15 -15
  179. package/expression/index.d.ts +7 -7
  180. package/expression/index.js +25 -25
  181. package/expression/is-expression-token.d.ts +2 -2
  182. package/expression/is-expression-token.js +7 -7
  183. package/expression/key-val-expression.d.ts +7 -7
  184. package/expression/key-val-expression.js +2 -2
  185. package/expression/literal.d.ts +3 -3
  186. package/expression/literal.js +2 -2
  187. package/expression/logical.d.ts +28 -18
  188. package/expression/logical.js +54 -30
  189. package/expression/logical.js.map +1 -1
  190. package/expression/math.d.ts +17 -17
  191. package/expression/math.js +36 -36
  192. package/expression/raw.d.ts +8 -8
  193. package/expression/raw.js +16 -16
  194. package/expression/simple-expression.d.ts +8 -8
  195. package/expression/simple-expression.js +2 -2
  196. package/functions/function-aliases.d.ts +6 -4
  197. package/functions/function-aliases.js +16 -12
  198. package/functions/function-aliases.js.map +1 -1
  199. package/functions/function-token.d.ts +33 -29
  200. package/functions/function-token.js +19 -15
  201. package/functions/function-token.js.map +1 -1
  202. package/functions/functions.d.ts +23 -19
  203. package/functions/functions.js +126 -94
  204. package/functions/functions.js.map +1 -1
  205. package/functions/index.d.ts +4 -4
  206. package/functions/index.js +22 -22
  207. package/functions/is-database-function.d.ts +8 -8
  208. package/functions/is-database-function.js +14 -14
  209. package/functions/signatures/count.d.ts +14 -11
  210. package/functions/signatures/count.js +2 -2
  211. package/index.d.ts +16 -16
  212. package/index.js +32 -32
  213. package/migration/index.d.ts +3 -3
  214. package/migration/index.js +9 -9
  215. package/migration/migration-package.d.ts +14 -14
  216. package/migration/migration-package.js +10 -10
  217. package/migration/migration-record.d.ts +10 -10
  218. package/migration/migration-record.js +2 -2
  219. package/migration/migration-runner.d.ts +33 -33
  220. package/migration/migration-runner.js +180 -180
  221. package/migration/migration.d.ts +12 -12
  222. package/migration/migration.js +27 -27
  223. package/migration/migrations/001-create-migration-table.d.ts +8 -8
  224. package/migration/migrations/001-create-migration-table.js +54 -54
  225. package/migration/migrations/002-add-migration-package-column.d.ts +9 -9
  226. package/migration/migrations/002-add-migration-package-column.js +44 -44
  227. package/package.json +1 -1
  228. package/record/index.d.ts +1 -1
  229. package/record/index.js +17 -17
  230. package/record/record.d.ts +2 -2
  231. package/record/record.js +2 -2
  232. package/repository/index.d.ts +2 -2
  233. package/repository/index.js +5 -5
  234. package/repository/repository-options.d.ts +6 -6
  235. package/repository/repository-options.js +2 -2
  236. package/repository/repository.d.ts +29 -29
  237. package/repository/repository.js +68 -68
  238. package/schema/index.d.ts +3 -3
  239. package/schema/index.js +5 -5
  240. package/schema/schema-query-repository.d.ts +54 -54
  241. package/schema/schema-query-repository.js +159 -159
  242. package/schema/schema-table.d.ts +9 -9
  243. package/schema/schema-table.js +2 -2
  244. package/schema/schema.d.ts +4 -4
  245. package/schema/schema.js +2 -2
  246. package/seed/auto-seed.d.ts +9 -9
  247. package/seed/auto-seed.js +61 -61
  248. package/seed/create-seed-table.d.ts +8 -8
  249. package/seed/create-seed-table.js +64 -64
  250. package/seed/index.d.ts +4 -4
  251. package/seed/index.js +9 -9
  252. package/seed/seed-record.d.ts +11 -11
  253. package/seed/seed-record.js +2 -2
  254. package/seed/seed-runner.d.ts +20 -20
  255. package/seed/seed-runner.js +91 -91
  256. package/seed/seed.d.ts +12 -12
  257. package/seed/seed.js +27 -27
  258. package/tokens/index.d.ts +1 -1
  259. package/tokens/index.js +5 -5
  260. package/triggers/index.d.ts +2 -2
  261. package/triggers/index.js +18 -18
  262. package/triggers/prebuilt/index.d.ts +1 -1
  263. package/triggers/prebuilt/index.js +5 -5
  264. package/triggers/prebuilt/update-timestamp-trigger.d.ts +16 -16
  265. package/triggers/prebuilt/update-timestamp-trigger.js +24 -24
  266. package/triggers/trigger-options.d.ts +22 -22
  267. package/triggers/trigger-options.js +2 -2
  268. package/triggers/trigger.d.ts +19 -19
  269. package/triggers/trigger.js +23 -23
@@ -1,794 +1,992 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DatabaseQueryBuilder = void 0;
4
- const statement_builder_1 = require("../builder/statement-builder");
5
- const comparison_1 = require("../comparison");
6
- const tokens_1 = require("../tokens");
7
- const functions_1 = require("../functions");
8
- const expression_1 = require("../expression");
9
- const function_token_1 = require("../functions/function-token");
10
- const subquery_1 = require("./subquery");
11
- const case_expression_1 = require("./case-expression");
12
- class DatabaseQueryBuilder extends statement_builder_1.StatementBuilder {
13
- // ------------------------------------------------------------------------
14
- // Expression
15
- // ------------------------------------------------------------------------
16
- expression(expr) {
17
- if (Array.isArray(expr)) {
18
- this.sql.openParens();
19
- for (const e of expr) {
20
- this.expression(e);
21
- }
22
- this.sql.closeParens();
23
- }
24
- else if ((0, expression_1.isExpressionToken)(expr)) {
25
- const token = expr;
26
- if ((0, comparison_1.isComparisonToken)(token)) {
27
- this.buildComparisonToken(token);
28
- }
29
- else if ((0, expression_1.isLogicalToken)(token)) {
30
- this.logical(token);
31
- }
32
- else if ((0, expression_1.isIdentifierToken)(token)) {
33
- this.sql.columnName(token.name);
34
- }
35
- else if ((0, functions_1.isDatabaseFunction)(token)) {
36
- this.databaseFunction(token);
37
- }
38
- else if ((0, expression_1.isMathToken)(token)) {
39
- this.math(token);
40
- }
41
- else if ((0, expression_1.isRawExprToken)(token)) {
42
- this.rawExpression(token);
43
- }
44
- }
45
- else if (expr && typeof expr === 'object') {
46
- if (expr instanceof Buffer || expr instanceof Date) {
47
- this.sql.placeholder(expr);
48
- }
49
- else if (expr instanceof subquery_1.Subquery) {
50
- this.subquery(expr);
51
- }
52
- else if (expr instanceof case_expression_1.CaseExpression) {
53
- this.caseExpression(expr);
54
- }
55
- else {
56
- this.keyValueExpression(expr);
57
- }
58
- }
59
- else {
60
- this.sql.placeholder(expr);
61
- }
62
- }
63
- subquery(subquery) {
64
- this.sql.openParens();
65
- this.select(subquery.query);
66
- this.sql.closeParens();
67
- this.sql.trimEnd(' ');
68
- }
69
- caseExpression(expr) {
70
- this.sql.openParens();
71
- this.sql.append('CASE ');
72
- if (expr.value) {
73
- this.expression(expr.value);
74
- this.sql.space();
75
- }
76
- for (const condition of expr.case) {
77
- this.sql.append('WHEN ');
78
- this.expression(condition.when);
79
- this.sql.append('THEN ');
80
- this.expression(condition.then);
81
- }
82
- if (expr.else) {
83
- this.sql.append('ELSE ');
84
- this.expression(expr.else);
85
- }
86
- this.sql.append('END');
87
- this.sql.closeParens();
88
- this.sql.trimEnd(' ');
89
- }
90
- rawExpression(expr) {
91
- this.sql.append(expr.sql);
92
- if (expr.params) {
93
- this.sql.appendParams(expr.params);
94
- }
95
- return this;
96
- }
97
- keyValueExpression(kv) {
98
- if (!Object.keys(kv).length) {
99
- return this;
100
- }
101
- this.sql.openParens();
102
- for (const key in kv) {
103
- const value = kv[key];
104
- this.sql.columnName(key);
105
- this.sql.space();
106
- if (value === null) {
107
- this.isNull();
108
- }
109
- else if ((0, expression_1.isExpressionToken)(value)) {
110
- const token = value;
111
- if ((0, comparison_1.isComparisonToken)(token)) {
112
- this.expression(value);
113
- }
114
- else if ((0, expression_1.isLogicalToken)(token)) {
115
- this.expression(value);
116
- }
117
- else if ((0, expression_1.isIdentifierToken)(token)) {
118
- this.equal(value);
119
- }
120
- else if ((0, functions_1.isDatabaseFunction)(token)) {
121
- this.equal(value);
122
- }
123
- else if ((0, expression_1.isRawExprToken)(token)) {
124
- this.equal(value);
125
- }
126
- }
127
- else {
128
- this.equal(value);
129
- }
130
- this.and();
131
- }
132
- this.sql.trimEnd(this.sql.operators.and);
133
- this.sql.closeParens();
134
- return this;
135
- }
136
- // ------------------------------------------------------------------------
137
- // Set
138
- // ------------------------------------------------------------------------
139
- set(options) {
140
- this.setStatement();
141
- this.setColumn(options);
142
- return this;
143
- }
144
- setStatement() {
145
- this.sql.append('SET ');
146
- return this;
147
- }
148
- setColumn(options) {
149
- this.sql.columnName(options.column);
150
- this.sql.append(' = ');
151
- this.expression(options.value);
152
- return this;
153
- }
154
- // ------------------------------------------------------------------------
155
- // Select
156
- // ------------------------------------------------------------------------
157
- selectColumn(column) {
158
- if (typeof column === 'string') {
159
- this.sql.columnName(column);
160
- }
161
- else if (typeof column === 'object') {
162
- if ('column' in column) {
163
- this.sql.columnName(column.column);
164
- }
165
- else if ('query' in column) {
166
- this.expression(column.query);
167
- }
168
- if (column.as) {
169
- this.sql.append(' AS ');
170
- this.sql.columnName(column.as);
171
- }
172
- }
173
- return this;
174
- }
175
- selectColumnList(columns) {
176
- if (columns) {
177
- for (const column of columns) {
178
- this.selectColumn(column);
179
- this.sql.append(', ');
180
- }
181
- this.sql.trimEnd(', ');
182
- this.sql.space();
183
- }
184
- else {
185
- this.sql.append('* ');
186
- }
187
- return this;
188
- }
189
- selectFrom(from) {
190
- this.sql.append('FROM ');
191
- if (typeof from === 'string') {
192
- this.sql.tableName(from);
193
- }
194
- else if (typeof from === 'object') {
195
- for (const alias in from) {
196
- const expr = from[alias];
197
- if (typeof expr === 'string') {
198
- this.sql.tableName(expr);
199
- }
200
- else {
201
- this.expression(expr);
202
- }
203
- this.sql.append(' ');
204
- this.sql.columnName(alias);
205
- this.sql.append(', ');
206
- }
207
- this.sql.trimEnd(', ');
208
- }
209
- this.sql.space();
210
- return this;
211
- }
212
- tableAlias(alias) {
213
- this.sql.append('AS ');
214
- this.sql.tableName(alias);
215
- this.sql.space();
216
- return this;
217
- }
218
- selectStatement() {
219
- this.sql.append('SELECT ');
220
- return this;
221
- }
222
- distinctStatement() {
223
- this.sql.append('DISTINCT ');
224
- return this;
225
- }
226
- selectTop(limit) {
227
- // This will be overridden in mssql for LIMIT func
228
- return this;
229
- }
230
- // ------------------------------------------------------------------------
231
- // Comparisons
232
- // ------------------------------------------------------------------------
233
- equal(value) {
234
- this.sql.append(this.sql.operators.equals + ' ');
235
- this.expression(value);
236
- }
237
- like(value) {
238
- this.sql.append(this.sql.operators.like + ' ');
239
- this.expression(value);
240
- }
241
- lt(value) {
242
- this.sql.append(this.sql.operators.lt + ' ');
243
- this.expression(value);
244
- }
245
- lte(value) {
246
- this.sql.append(this.sql.operators.lte + ' ');
247
- this.expression(value);
248
- }
249
- gt(value) {
250
- this.sql.append(this.sql.operators.gt + ' ');
251
- this.expression(value);
252
- }
253
- gte(value) {
254
- this.sql.append(this.sql.operators.gte + ' ');
255
- this.expression(value);
256
- }
257
- notEqual(value) {
258
- this.sql.append(this.sql.operators.notEqual + ' ');
259
- this.expression(value);
260
- }
261
- isNull() {
262
- this.sql.append(this.sql.operators.is + ' ' + this.sql.operators.null + ' ');
263
- }
264
- inArray(values) {
265
- this.sql.append(this.sql.operators.in + ' ');
266
- this.sql.openParens();
267
- for (const value of values) {
268
- this.expression(value);
269
- this.sql.append(', ');
270
- }
271
- this.sql.trimEnd(', ');
272
- this.sql.closeParens();
273
- }
274
- between(a, b) {
275
- this.sql.append(this.sql.operators.between + ' ');
276
- this.expression(a);
277
- this.sql.append('AND ');
278
- this.expression(b);
279
- }
280
- notNull() {
281
- this.sql.append('NOT NULL ');
282
- }
283
- buildComparisonToken(condition) {
284
- if (condition.op === comparison_1.ComparisonOperator.EQUALS) {
285
- this.equal(condition.value);
286
- }
287
- else if (condition.op === comparison_1.ComparisonOperator.NOT_EQUAL) {
288
- this.notEqual(condition.value);
289
- }
290
- else if (condition.op === comparison_1.ComparisonOperator.LIKE) {
291
- this.like(condition.value);
292
- }
293
- else if (condition.op === comparison_1.ComparisonOperator.LT) {
294
- this.lt(condition.value);
295
- }
296
- else if (condition.op === comparison_1.ComparisonOperator.LTE) {
297
- this.lte(condition.value);
298
- }
299
- else if (condition.op === comparison_1.ComparisonOperator.GT) {
300
- this.gt(condition.value);
301
- }
302
- else if (condition.op === comparison_1.ComparisonOperator.GTE) {
303
- this.gte(condition.value);
304
- }
305
- else if (condition.op === comparison_1.ComparisonOperator.IN_ARRAY) {
306
- this.inArray(condition.value);
307
- }
308
- else if (condition.op === comparison_1.ComparisonOperator.BETWEEN) {
309
- this.between(condition.value.a, condition.value.b);
310
- }
311
- return this;
312
- }
313
- // ------------------------------------------------------------------------
314
- // Logical
315
- // ------------------------------------------------------------------------
316
- and() {
317
- this.sql.append(this.sql.operators.and + ' ');
318
- }
319
- or() {
320
- this.sql.append(this.sql.operators.or + ' ');
321
- }
322
- not(value) {
323
- if (value === null) {
324
- this.sql.append(this.sql.operators.is + ' ');
325
- this.notNull();
326
- return;
327
- }
328
- const isComparison = (0, expression_1.isExpressionToken)(value) &&
329
- (0, comparison_1.isComparisonToken)(value);
330
- const conditionType = isComparison
331
- ? value === null || value === void 0 ? void 0 : value.op
332
- : null;
333
- if (isComparison &&
334
- (conditionType === comparison_1.ComparisonOperator.LIKE ||
335
- conditionType === comparison_1.ComparisonOperator.IN_ARRAY)) {
336
- this.sql.append('NOT ');
337
- this.buildComparisonToken(value);
338
- }
339
- else if (isComparison) {
340
- throw new Error('Cannot use not() with ' + conditionType);
341
- }
342
- else if (typeof value === 'object' || Array.isArray(value)) {
343
- this.sql.append('!');
344
- this.expression(value);
345
- }
346
- else {
347
- this.notEqual(value);
348
- }
349
- }
350
- logical(token) {
351
- if (token.op === expression_1.LogicalOperator.AND) {
352
- this.and();
353
- }
354
- else if (token.op === expression_1.LogicalOperator.OR) {
355
- this.or();
356
- }
357
- else if (token.op === expression_1.LogicalOperator.NOT) {
358
- this.not(token.expr);
359
- }
360
- }
361
- // ------------------------------------------------------------------------
362
- // Math
363
- // ------------------------------------------------------------------------
364
- addition() {
365
- this.sql.append(this.sql.operators.addition + ' ');
366
- }
367
- subtraction() {
368
- this.sql.append(this.sql.operators.subtraction + ' ');
369
- }
370
- multiplication() {
371
- this.sql.append(this.sql.operators.multiplication + ' ');
372
- }
373
- division() {
374
- this.sql.append(this.sql.operators.division + ' ');
375
- }
376
- modulo() {
377
- this.sql.append(this.sql.operators.modulo + ' ');
378
- }
379
- math(token) {
380
- if (token.op === expression_1.MathOperation.ADD) {
381
- this.addition();
382
- }
383
- if (token.op === expression_1.MathOperation.SUB) {
384
- this.subtraction();
385
- }
386
- if (token.op === expression_1.MathOperation.MUL) {
387
- this.multiplication();
388
- }
389
- if (token.op === expression_1.MathOperation.DIV) {
390
- this.division();
391
- }
392
- if (token.op === expression_1.MathOperation.MOD) {
393
- this.modulo();
394
- }
395
- }
396
- // ------------------------------------------------------------------------
397
- // Where
398
- // ------------------------------------------------------------------------
399
- where(where) {
400
- this.sql.append('WHERE ');
401
- this.expression(where);
402
- return this;
403
- }
404
- limit(nRecords) {
405
- this.sql.append('LIMIT ' + nRecords + ' ');
406
- return this;
407
- }
408
- offset(nRecords) {
409
- this.sql.append('OFFSET ' + nRecords + ' ');
410
- return this;
411
- }
412
- groupBy(by) {
413
- this.sql.append('GROUP BY ');
414
- for (const key of by) {
415
- this.sql.columnName(key);
416
- this.sql.append(', ');
417
- }
418
- this.sql.trimEnd(', ');
419
- this.sql.space();
420
- return this;
421
- }
422
- having(query) {
423
- this.sql.append('HAVING ');
424
- this.expression(query);
425
- return this;
426
- }
427
- orderBy(by) {
428
- this.sql.append('ORDER BY ');
429
- for (const key in by) {
430
- this.sql.columnName(key);
431
- this.sql.append(' ' + by[key] + ', ');
432
- }
433
- this.sql.trimEnd(', ');
434
- this.sql.space();
435
- }
436
- select(query) {
437
- var _a, _b;
438
- this.selectStatement();
439
- if (query.distinct) {
440
- this.distinctStatement();
441
- }
442
- if ('top' in query) {
443
- this.selectTop(query.top);
444
- }
445
- this.selectColumnList(query.columns);
446
- if (query.table) {
447
- this.selectFrom(query.table);
448
- }
449
- if (query.tableAlias) {
450
- this.tableAlias(query.tableAlias);
451
- }
452
- for (const join of (_a = query.join) !== null && _a !== void 0 ? _a : []) {
453
- this.join(join);
454
- }
455
- if (query.where) {
456
- this.where(query.where);
457
- }
458
- if ((_b = query.groupBy) === null || _b === void 0 ? void 0 : _b.length) {
459
- this.groupBy(query.groupBy);
460
- }
461
- if (query.having) {
462
- this.having(query.having);
463
- }
464
- if (query.orderBy) {
465
- this.orderBy(query.orderBy);
466
- }
467
- this.pagination(query);
468
- return this;
469
- }
470
- pagination(query) {
471
- if (query.limit) {
472
- this.limit(query.limit);
473
- }
474
- if (query.offset !== undefined) {
475
- this.offset(query.offset);
476
- }
477
- return this;
478
- }
479
- // ------------------------------------------------------------------------
480
- // Join
481
- // ------------------------------------------------------------------------
482
- join(join) {
483
- var _a;
484
- this.sql.append(((_a = join.type) !== null && _a !== void 0 ? _a : '') + ' JOIN ');
485
- this.sql.tableName(join.table);
486
- this.sql.space();
487
- if (join.alias) {
488
- this.tableAlias(join.alias);
489
- }
490
- if (join.on) {
491
- this.sql.append('ON ');
492
- this.expression(join.on);
493
- }
494
- }
495
- // ------------------------------------------------------------------------
496
- // Insert
497
- // ------------------------------------------------------------------------
498
- insertIntoStatement(table) {
499
- this.sql.append('INSERT INTO ');
500
- this.sql.tableName(table);
501
- this.sql.space();
502
- return this;
503
- }
504
- insertColumnNames(record) {
505
- this.sql.openParens();
506
- this.sql.commaSeparate(Object.keys(record).map((name) => this.sql.getEnclosedName(name)));
507
- this.sql.closeParens();
508
- return this;
509
- }
510
- insertOnDuplicateKeyUpdate(assignment) {
511
- this.sql.append('ON DUPLICATE KEY UPDATE ');
512
- this.updateKeyValues(assignment);
513
- return this;
514
- }
515
- insertIfNotExists() {
516
- this.insertOnDuplicateKeyUpdate({ id: (0, tokens_1.columnName)('id') });
517
- return this;
518
- }
519
- insertOutput(primaryKey) {
520
- // This will be overridden in mssql to return the insert id(s)
521
- return this;
522
- }
523
- insertReturning(primaryKey) {
524
- // This will be overridden in postgres to return the insert id(s)
525
- return this;
526
- }
527
- insert(options) {
528
- var _a;
529
- this.insertIntoStatement(options.table);
530
- if (!Array.isArray(options.records)) {
531
- options.records = [options.records];
532
- }
533
- const columns = {};
534
- const insertions = [];
535
- if (options.records.length) {
536
- for (const rec of options.records) {
537
- for (const key in rec) {
538
- if (!(key in columns)) {
539
- columns[key] = true;
540
- }
541
- }
542
- }
543
- for (const rec of options.records) {
544
- const insertion = {};
545
- for (const key in columns) {
546
- insertion[key] = (_a = rec[key]) !== null && _a !== void 0 ? _a : null;
547
- }
548
- insertions.push(insertion);
549
- }
550
- this.insertColumnNames(columns);
551
- }
552
- if (options.primaryKey) {
553
- this.insertOutput(options.primaryKey);
554
- }
555
- this.sql.append('VALUES ');
556
- for (let i = 0; i < insertions.length; i++) {
557
- const record = insertions[i];
558
- this.sql.openParens();
559
- for (const key in record) {
560
- this.expression(record[key]);
561
- this.sql = this.sql.trimEnd();
562
- this.sql.append(', ');
563
- }
564
- this.sql.trimEnd(', ');
565
- this.sql.closeParens();
566
- this.sql = this.sql.trimEnd();
567
- this.sql.append(', ');
568
- }
569
- this.sql.trimEnd(', ');
570
- this.sql.space();
571
- if (options.ifNotExists) {
572
- this.insertIfNotExists();
573
- }
574
- else if (options.onDuplicateKeyUpdate) {
575
- this.insertOnDuplicateKeyUpdate(options.onDuplicateKeyUpdate);
576
- }
577
- this.sql.trimEnd(' ');
578
- if (options.primaryKey) {
579
- this.insertReturning(options.primaryKey);
580
- }
581
- return this;
582
- }
583
- // ------------------------------------------------------------------------
584
- // Update
585
- // ------------------------------------------------------------------------
586
- updateStatement(table) {
587
- this.sql.append('UPDATE ');
588
- this.sql.tableName(table);
589
- this.sql.space();
590
- return this;
591
- }
592
- updateKeyValues(values) {
593
- const keys = Object.keys(values);
594
- for (const key of keys) {
595
- this.sql.columnName(key);
596
- this.sql.append(' = ');
597
- this.expression(values[key]);
598
- this.sql = this.sql.trimEnd();
599
- this.sql.append(', ');
600
- }
601
- this.sql.trimEnd(', ');
602
- this.sql.space();
603
- return this;
604
- }
605
- updateSetStatement(values) {
606
- this.sql.append('SET ');
607
- this.updateKeyValues(values);
608
- return this;
609
- }
610
- update(options) {
611
- var _a;
612
- this.updateStatement(options.table);
613
- for (const join of (_a = options.join) !== null && _a !== void 0 ? _a : []) {
614
- this.join(join);
615
- }
616
- this.updateSetStatement(options.set);
617
- if (options.from) {
618
- this.selectFrom(options.from);
619
- }
620
- if (options.where) {
621
- this.where(options.where);
622
- }
623
- return this;
624
- }
625
- // ------------------------------------------------------------------------
626
- // Delete
627
- // ------------------------------------------------------------------------
628
- deleteStatement(table) {
629
- this.sql.append('DELETE FROM ');
630
- this.sql.tableName(table);
631
- this.sql.space();
632
- return this;
633
- }
634
- delete(options) {
635
- var _a;
636
- this.deleteStatement(options.table);
637
- for (const join of (_a = options.join) !== null && _a !== void 0 ? _a : []) {
638
- this.join(join);
639
- }
640
- if (options.where) {
641
- this.where(options.where);
642
- }
643
- return this;
644
- }
645
- // ------------------------------------------------------------------------
646
- // Database Functions
647
- // ------------------------------------------------------------------------
648
- /**
649
- * Append a database function the query
650
- *
651
- * @param fn Database function token
652
- */
653
- databaseFunction(fn) {
654
- switch (fn.fn) {
655
- case function_token_1.DatabaseFunctionKeys.AVERAGE:
656
- this.average(fn);
657
- break;
658
- case function_token_1.DatabaseFunctionKeys.COUNT:
659
- this.count(fn);
660
- break;
661
- case function_token_1.DatabaseFunctionKeys.MIN:
662
- this.min(fn);
663
- break;
664
- case function_token_1.DatabaseFunctionKeys.MAX:
665
- this.max(fn);
666
- break;
667
- case function_token_1.DatabaseFunctionKeys.SUM:
668
- this.sum(fn);
669
- break;
670
- case function_token_1.DatabaseFunctionKeys.CURRENT_TIMESTAMP:
671
- this.currentTimestamp(fn);
672
- break;
673
- case function_token_1.DatabaseFunctionKeys.DATE:
674
- this.date(fn);
675
- break;
676
- case function_token_1.DatabaseFunctionKeys.YEAR:
677
- this.year(fn);
678
- break;
679
- case function_token_1.DatabaseFunctionKeys.UUID:
680
- this.uuid();
681
- break;
682
- }
683
- return this;
684
- }
685
- average(fn) {
686
- this.sql.append('AVG');
687
- this.sql.openParens();
688
- if (fn.params.options.distinct) {
689
- this.distinctStatement();
690
- }
691
- this.expression(fn.params.expr);
692
- this.sql.closeParens();
693
- return this;
694
- }
695
- count(fn) {
696
- var _a, _b, _c;
697
- this.sql.append('COUNT(');
698
- if ((_a = fn.params) === null || _a === void 0 ? void 0 : _a.distinct) {
699
- this.distinctStatement();
700
- }
701
- if ((_b = fn.params) === null || _b === void 0 ? void 0 : _b.expr) {
702
- this.expression(fn.params.expr);
703
- }
704
- else if ((_c = fn.params) === null || _c === void 0 ? void 0 : _c.column) {
705
- this.sql.columnName(fn.params.column);
706
- }
707
- else {
708
- this.sql.append('*');
709
- }
710
- this.sql.append(')');
711
- return this;
712
- }
713
- min(fn) {
714
- this.sql.append('MIN');
715
- this.sql.openParens();
716
- this.expression(fn.params);
717
- this.sql.closeParens();
718
- return this;
719
- }
720
- max(fn) {
721
- this.sql.append('MAX');
722
- this.sql.openParens();
723
- this.expression(fn.params);
724
- this.sql.closeParens();
725
- return this;
726
- }
727
- sum(fn) {
728
- this.sql.append('SUM');
729
- this.sql.openParens();
730
- if (fn.params.options.distinct) {
731
- this.distinctStatement();
732
- }
733
- this.expression(fn.params.expr);
734
- this.sql.closeParens();
735
- return this;
736
- }
737
- currentTimestamp(fn) {
738
- this.sql.append('CURRENT_TIMESTAMP');
739
- return this;
740
- }
741
- date(fn) {
742
- var _a;
743
- this.sql.append('date');
744
- this.sql.openParens();
745
- if ((_a = fn.params) === null || _a === void 0 ? void 0 : _a.expr) {
746
- this.expression(fn.params.expr);
747
- }
748
- else {
749
- this.expression(functions_1.DatabaseFunctions.currentTimestamp());
750
- }
751
- this.sql.closeParens();
752
- return this;
753
- }
754
- year(fn) {
755
- var _a;
756
- this.sql.append('year');
757
- this.sql.openParens();
758
- if ((_a = fn.params) === null || _a === void 0 ? void 0 : _a.expr) {
759
- this.expression(fn.params.expr);
760
- }
761
- else {
762
- this.expression(functions_1.DatabaseFunctions.currentTimestamp());
763
- }
764
- this.sql.closeParens();
765
- return this;
766
- }
767
- uuid() {
768
- this.sql.append('uuid()');
769
- return this;
770
- }
771
- // ------------------------------------------------------------------------
772
- // Triggers
773
- // ------------------------------------------------------------------------
774
- getTriggerOld() {
775
- return 'OLD';
776
- }
777
- getTriggerOldColumn(column) {
778
- return `${this.getTriggerOld()}.${column}`;
779
- }
780
- getTriggerNew() {
781
- return 'NEW';
782
- }
783
- getTriggerNewColumn(column) {
784
- return `${this.getTriggerNew()}.${column}`;
785
- }
786
- triggerSetValue(options) {
787
- return this.set({
788
- column: `NEW.${options.column}`,
789
- value: options.value,
790
- });
791
- }
792
- }
793
- exports.DatabaseQueryBuilder = DatabaseQueryBuilder;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DatabaseQueryBuilder = void 0;
4
+ const statement_builder_1 = require("../builder/statement-builder");
5
+ const comparison_1 = require("../comparison");
6
+ const tokens_1 = require("../tokens");
7
+ const functions_1 = require("../functions");
8
+ const expression_1 = require("../expression");
9
+ const function_token_1 = require("../functions/function-token");
10
+ const subquery_1 = require("./subquery");
11
+ const case_expression_1 = require("./case-expression");
12
+ class DatabaseQueryBuilder extends statement_builder_1.StatementBuilder {
13
+ constructor() {
14
+ super(...arguments);
15
+ this.selectDepth = 0;
16
+ }
17
+ // ------------------------------------------------------------------------
18
+ // Expression
19
+ // ------------------------------------------------------------------------
20
+ expression(expr) {
21
+ if (Array.isArray(expr)) {
22
+ this.sql.openParens();
23
+ for (const e of expr) {
24
+ this.expression(e);
25
+ }
26
+ this.sql.closeParens();
27
+ }
28
+ else if ((0, expression_1.isExpressionToken)(expr)) {
29
+ const token = expr;
30
+ if ((0, comparison_1.isComparisonToken)(token)) {
31
+ this.buildComparisonToken(token);
32
+ }
33
+ else if ((0, expression_1.isLogicalToken)(token)) {
34
+ this.logical(token);
35
+ }
36
+ else if ((0, expression_1.isIdentifierToken)(token)) {
37
+ this.sql.columnName(token.name);
38
+ }
39
+ else if ((0, functions_1.isDatabaseFunction)(token)) {
40
+ this.databaseFunction(token);
41
+ }
42
+ else if ((0, expression_1.isMathToken)(token)) {
43
+ this.math(token);
44
+ }
45
+ else if ((0, expression_1.isRawExprToken)(token)) {
46
+ this.rawExpression(token);
47
+ }
48
+ }
49
+ else if (expr && typeof expr === 'object') {
50
+ if (expr instanceof Buffer || expr instanceof Date) {
51
+ this.sql.placeholder(expr);
52
+ }
53
+ else if (expr instanceof subquery_1.Subquery) {
54
+ this.subquery(expr);
55
+ }
56
+ else if (expr instanceof case_expression_1.CaseExpression) {
57
+ this.caseExpression(expr);
58
+ }
59
+ else {
60
+ this.keyValueExpression(expr);
61
+ }
62
+ }
63
+ else {
64
+ this.sql.placeholder(expr);
65
+ }
66
+ }
67
+ subquery(subquery) {
68
+ this.sql.openParens();
69
+ this.select(subquery.query);
70
+ this.sql.closeParens();
71
+ this.sql.trimEnd(' ');
72
+ }
73
+ caseExpression(expr) {
74
+ this.sql.openParens();
75
+ this.sql.append('CASE ');
76
+ if (expr.value) {
77
+ this.expression(expr.value);
78
+ this.sql.space();
79
+ }
80
+ for (const condition of expr.case) {
81
+ this.sql.append('WHEN ');
82
+ this.expression(condition.when);
83
+ this.sql.append('THEN ');
84
+ this.expression(condition.then);
85
+ }
86
+ if (expr.else) {
87
+ this.sql.append('ELSE ');
88
+ this.expression(expr.else);
89
+ }
90
+ this.sql.append('END');
91
+ this.sql.closeParens();
92
+ this.sql.trimEnd(' ');
93
+ }
94
+ rawExpression(expr) {
95
+ this.sql.append(expr.sql);
96
+ if (expr.params) {
97
+ this.sql.appendParams(expr.params);
98
+ }
99
+ return this;
100
+ }
101
+ keyValueExpression(kv) {
102
+ if (!Object.keys(kv).length) {
103
+ return this;
104
+ }
105
+ this.sql.openParens();
106
+ for (const key in kv) {
107
+ const value = kv[key];
108
+ this.sql.columnName(key);
109
+ this.sql.space();
110
+ if (value === null) {
111
+ this.isNull();
112
+ }
113
+ else if ((0, expression_1.isExpressionToken)(value)) {
114
+ const token = value;
115
+ if ((0, comparison_1.isComparisonToken)(token)) {
116
+ this.expression(value);
117
+ }
118
+ else if ((0, expression_1.isLogicalToken)(token)) {
119
+ this.expression(value);
120
+ }
121
+ else if ((0, expression_1.isIdentifierToken)(token)) {
122
+ this.equal(value);
123
+ }
124
+ else if ((0, functions_1.isDatabaseFunction)(token)) {
125
+ this.equal(value);
126
+ }
127
+ else if ((0, expression_1.isRawExprToken)(token)) {
128
+ this.equal(value);
129
+ }
130
+ }
131
+ else {
132
+ this.equal(value);
133
+ }
134
+ this.and();
135
+ }
136
+ this.sql.trimEnd(this.sql.operators.and);
137
+ this.sql.closeParens();
138
+ return this;
139
+ }
140
+ // ------------------------------------------------------------------------
141
+ // Set
142
+ // ------------------------------------------------------------------------
143
+ set(options) {
144
+ this.setStatement();
145
+ this.setColumn(options);
146
+ return this;
147
+ }
148
+ setStatement() {
149
+ this.sql.append('SET ');
150
+ return this;
151
+ }
152
+ setColumn(options) {
153
+ this.sql.columnName(options.column);
154
+ this.sql.append(' = ');
155
+ this.expression(options.value);
156
+ return this;
157
+ }
158
+ // ------------------------------------------------------------------------
159
+ // Select
160
+ // ------------------------------------------------------------------------
161
+ selectColumn(column) {
162
+ if (typeof column === 'string') {
163
+ this.sql.columnName(column);
164
+ }
165
+ else if (typeof column === 'object') {
166
+ if ('column' in column) {
167
+ this.sql.columnName(column.column);
168
+ }
169
+ else if ('query' in column) {
170
+ this.expression(column.query);
171
+ }
172
+ if (column.as) {
173
+ this.sql.append(' AS ');
174
+ this.sql.columnName(column.as);
175
+ }
176
+ }
177
+ return this;
178
+ }
179
+ selectColumnList(columns) {
180
+ if (columns) {
181
+ for (const column of columns) {
182
+ this.selectColumn(column);
183
+ this.sql.append(', ');
184
+ }
185
+ this.sql.trimEnd(', ');
186
+ this.sql.space();
187
+ }
188
+ else {
189
+ this.sql.append('* ');
190
+ }
191
+ return this;
192
+ }
193
+ selectFrom(from) {
194
+ this.sql.append('FROM ');
195
+ if (typeof from === 'string') {
196
+ this.sql.tableName(from);
197
+ }
198
+ else if (typeof from === 'object') {
199
+ for (const alias in from) {
200
+ const expr = from[alias];
201
+ if (typeof expr === 'string') {
202
+ this.sql.tableName(expr);
203
+ }
204
+ else {
205
+ this.expression(expr);
206
+ }
207
+ this.sql.append(' ');
208
+ this.sql.columnName(alias);
209
+ this.sql.append(', ');
210
+ }
211
+ this.sql.trimEnd(', ');
212
+ }
213
+ this.sql.space();
214
+ return this;
215
+ }
216
+ tableAlias(alias) {
217
+ this.sql.append('AS ');
218
+ this.sql.tableName(alias);
219
+ this.sql.space();
220
+ return this;
221
+ }
222
+ selectStatement() {
223
+ this.sql.append('SELECT ');
224
+ return this;
225
+ }
226
+ distinctStatement() {
227
+ this.sql.append('DISTINCT ');
228
+ return this;
229
+ }
230
+ selectTop(limit) {
231
+ // This will be overridden in mssql for LIMIT func
232
+ return this;
233
+ }
234
+ // ------------------------------------------------------------------------
235
+ // Comparisons
236
+ // ------------------------------------------------------------------------
237
+ equal(value) {
238
+ this.sql.append(this.sql.operators.equals + ' ');
239
+ this.expression(value);
240
+ }
241
+ like(value) {
242
+ this.sql.append(this.sql.operators.like + ' ');
243
+ this.expression(value);
244
+ }
245
+ lt(value) {
246
+ this.sql.append(this.sql.operators.lt + ' ');
247
+ this.expression(value);
248
+ }
249
+ lte(value) {
250
+ this.sql.append(this.sql.operators.lte + ' ');
251
+ this.expression(value);
252
+ }
253
+ gt(value) {
254
+ this.sql.append(this.sql.operators.gt + ' ');
255
+ this.expression(value);
256
+ }
257
+ gte(value) {
258
+ this.sql.append(this.sql.operators.gte + ' ');
259
+ this.expression(value);
260
+ }
261
+ notEqual(value) {
262
+ this.sql.append(this.sql.operators.notEqual + ' ');
263
+ this.expression(value);
264
+ }
265
+ isNull() {
266
+ this.sql.append(this.sql.operators.is + ' ' + this.sql.operators.null + ' ');
267
+ }
268
+ inArray(values) {
269
+ this.sql.append(this.sql.operators.in + ' ');
270
+ this.sql.openParens();
271
+ for (const value of values) {
272
+ this.expression(value);
273
+ this.sql.append(', ');
274
+ }
275
+ this.sql.trimEnd(', ');
276
+ this.sql.closeParens();
277
+ }
278
+ between(a, b) {
279
+ this.sql.append(this.sql.operators.between + ' ');
280
+ this.expression(a);
281
+ this.sql.append('AND ');
282
+ this.expression(b);
283
+ }
284
+ notNull() {
285
+ this.sql.append('NOT NULL ');
286
+ }
287
+ buildComparisonToken(condition) {
288
+ if (condition.op === comparison_1.ComparisonOperator.EQUALS) {
289
+ this.equal(condition.value);
290
+ }
291
+ else if (condition.op === comparison_1.ComparisonOperator.NOT_EQUAL) {
292
+ this.notEqual(condition.value);
293
+ }
294
+ else if (condition.op === comparison_1.ComparisonOperator.LIKE) {
295
+ this.like(condition.value);
296
+ }
297
+ else if (condition.op === comparison_1.ComparisonOperator.LT) {
298
+ this.lt(condition.value);
299
+ }
300
+ else if (condition.op === comparison_1.ComparisonOperator.LTE) {
301
+ this.lte(condition.value);
302
+ }
303
+ else if (condition.op === comparison_1.ComparisonOperator.GT) {
304
+ this.gt(condition.value);
305
+ }
306
+ else if (condition.op === comparison_1.ComparisonOperator.GTE) {
307
+ this.gte(condition.value);
308
+ }
309
+ else if (condition.op === comparison_1.ComparisonOperator.IN_ARRAY) {
310
+ this.inArray(condition.value);
311
+ }
312
+ else if (condition.op === comparison_1.ComparisonOperator.BETWEEN) {
313
+ this.between(condition.value.a, condition.value.b);
314
+ }
315
+ return this;
316
+ }
317
+ // ------------------------------------------------------------------------
318
+ // Logical
319
+ // ------------------------------------------------------------------------
320
+ and() {
321
+ this.sql.append(this.sql.operators.and + ' ');
322
+ }
323
+ or() {
324
+ this.sql.append(this.sql.operators.or + ' ');
325
+ }
326
+ not(value) {
327
+ if (value === null) {
328
+ this.sql.append(this.sql.operators.is + ' ');
329
+ this.notNull();
330
+ return;
331
+ }
332
+ const isComparison = (0, expression_1.isExpressionToken)(value) &&
333
+ (0, comparison_1.isComparisonToken)(value);
334
+ const conditionType = isComparison
335
+ ? value === null || value === void 0 ? void 0 : value.op
336
+ : null;
337
+ if (isComparison &&
338
+ (conditionType === comparison_1.ComparisonOperator.LIKE ||
339
+ conditionType === comparison_1.ComparisonOperator.IN_ARRAY)) {
340
+ this.sql.append('NOT ');
341
+ this.buildComparisonToken(value);
342
+ }
343
+ else if (isComparison) {
344
+ throw new Error('Cannot use not() with ' + conditionType);
345
+ }
346
+ else if (typeof value === 'object' || Array.isArray(value)) {
347
+ this.sql.append('!');
348
+ this.expression(value);
349
+ }
350
+ else {
351
+ this.notEqual(value);
352
+ }
353
+ }
354
+ logical(token) {
355
+ if (token.op === expression_1.LogicalOperator.AND) {
356
+ this.and();
357
+ }
358
+ else if (token.op === expression_1.LogicalOperator.OR) {
359
+ this.or();
360
+ }
361
+ else if (token.op === expression_1.LogicalOperator.NOT) {
362
+ this.not(token.expr);
363
+ }
364
+ else if (token.op === expression_1.LogicalOperator.EXISTS) {
365
+ this.existsSubquery(token.query);
366
+ }
367
+ else if (token.op === expression_1.LogicalOperator.NOT_EXISTS) {
368
+ this.existsSubquery(token.query, true);
369
+ }
370
+ }
371
+ existsSubquery(subquery, negated = false) {
372
+ this.sql.append(negated ? 'NOT EXISTS ' : 'EXISTS ');
373
+ this.subquery(subquery);
374
+ this.sql.space();
375
+ return this;
376
+ }
377
+ // ------------------------------------------------------------------------
378
+ // Math
379
+ // ------------------------------------------------------------------------
380
+ addition() {
381
+ this.sql.append(this.sql.operators.addition + ' ');
382
+ }
383
+ subtraction() {
384
+ this.sql.append(this.sql.operators.subtraction + ' ');
385
+ }
386
+ multiplication() {
387
+ this.sql.append(this.sql.operators.multiplication + ' ');
388
+ }
389
+ division() {
390
+ this.sql.append(this.sql.operators.division + ' ');
391
+ }
392
+ modulo() {
393
+ this.sql.append(this.sql.operators.modulo + ' ');
394
+ }
395
+ math(token) {
396
+ if (token.op === expression_1.MathOperation.ADD) {
397
+ this.addition();
398
+ }
399
+ if (token.op === expression_1.MathOperation.SUB) {
400
+ this.subtraction();
401
+ }
402
+ if (token.op === expression_1.MathOperation.MUL) {
403
+ this.multiplication();
404
+ }
405
+ if (token.op === expression_1.MathOperation.DIV) {
406
+ this.division();
407
+ }
408
+ if (token.op === expression_1.MathOperation.MOD) {
409
+ this.modulo();
410
+ }
411
+ }
412
+ // ------------------------------------------------------------------------
413
+ // Where
414
+ // ------------------------------------------------------------------------
415
+ where(where) {
416
+ this.sql.append('WHERE ');
417
+ this.expression(where);
418
+ return this;
419
+ }
420
+ limit(nRecords) {
421
+ this.sql.append('LIMIT ' + nRecords + ' ');
422
+ return this;
423
+ }
424
+ offset(nRecords) {
425
+ this.sql.append('OFFSET ' + nRecords + ' ');
426
+ return this;
427
+ }
428
+ groupBy(by) {
429
+ this.sql.append('GROUP BY ');
430
+ for (const key of by) {
431
+ this.sql.columnName(key);
432
+ this.sql.append(', ');
433
+ }
434
+ this.sql.trimEnd(', ');
435
+ this.sql.space();
436
+ return this;
437
+ }
438
+ having(query) {
439
+ this.sql.append('HAVING ');
440
+ this.expression(query);
441
+ return this;
442
+ }
443
+ orderBy(by) {
444
+ this.sql.append('ORDER BY ');
445
+ for (const key in by) {
446
+ this.sql.columnName(key);
447
+ this.sql.append(' ' + by[key] + ', ');
448
+ }
449
+ this.sql.trimEnd(', ');
450
+ this.sql.space();
451
+ }
452
+ shouldWrapIntersectExceptQuery() {
453
+ return true;
454
+ }
455
+ select(query) {
456
+ var _a, _b;
457
+ const isTopLevel = this.selectDepth === 0;
458
+ const wrapInParens = isTopLevel &&
459
+ (!!query.intersect || !!query.except) &&
460
+ this.shouldWrapIntersectExceptQuery();
461
+ this.selectDepth++;
462
+ if (wrapInParens) {
463
+ this.sql.openParens();
464
+ }
465
+ this.selectStatement();
466
+ if (query.distinct) {
467
+ this.distinctStatement();
468
+ }
469
+ if ('top' in query) {
470
+ this.selectTop(query.top);
471
+ }
472
+ this.selectColumnList(query.columns);
473
+ if (query.table) {
474
+ this.selectFrom(query.table);
475
+ }
476
+ if (query.tableAlias) {
477
+ this.tableAlias(query.tableAlias);
478
+ }
479
+ for (const join of (_a = query.join) !== null && _a !== void 0 ? _a : []) {
480
+ this.join(join);
481
+ }
482
+ if (query.where) {
483
+ this.where(query.where);
484
+ }
485
+ if ((_b = query.groupBy) === null || _b === void 0 ? void 0 : _b.length) {
486
+ this.groupBy(query.groupBy);
487
+ }
488
+ if (query.having) {
489
+ this.having(query.having);
490
+ }
491
+ if (query.orderBy) {
492
+ this.orderBy(query.orderBy);
493
+ }
494
+ this.pagination(query);
495
+ if (wrapInParens) {
496
+ this.sql.closeParens();
497
+ }
498
+ if (query.union) {
499
+ const unions = Array.isArray(query.union)
500
+ ? query.union
501
+ : [query.union];
502
+ for (const u of unions) {
503
+ this.unionStatement(u.query, u.all);
504
+ }
505
+ }
506
+ if (query.intersect) {
507
+ const intersects = Array.isArray(query.intersect)
508
+ ? query.intersect
509
+ : [query.intersect];
510
+ for (const i of intersects) {
511
+ this.intersectWithSubquery(i.query, i.all);
512
+ }
513
+ }
514
+ if (query.except) {
515
+ const excepts = Array.isArray(query.except)
516
+ ? query.except
517
+ : [query.except];
518
+ for (const e of excepts) {
519
+ this.exceptWithSubquery(e.query, e.all);
520
+ }
521
+ }
522
+ this.selectDepth--;
523
+ return this;
524
+ }
525
+ unionStatement(query, all = false) {
526
+ this.sql.trimEnd(' ');
527
+ this.sql.append(all ? ' UNION ALL ' : ' UNION ');
528
+ this.select(query);
529
+ return this;
530
+ }
531
+ pagination(query) {
532
+ if (query.limit) {
533
+ this.limit(query.limit);
534
+ }
535
+ if (query.offset !== undefined) {
536
+ this.offset(query.offset);
537
+ }
538
+ return this;
539
+ }
540
+ wrapCurrentSelectForIntersectIfNeeded() {
541
+ if (!this.shouldWrapIntersectExceptQuery()) {
542
+ return this;
543
+ }
544
+ const currentSql = this.toDatabaseQuery().sql;
545
+ const hasWhere = currentSql.toUpperCase().includes('WHERE');
546
+ if (hasWhere) {
547
+ this.sql.prepend('(');
548
+ this.sql.trimEnd(' ');
549
+ this.sql.append(')');
550
+ }
551
+ return this;
552
+ }
553
+ intersectStatement() {
554
+ this.sql.trimEnd(' ');
555
+ this.sql.append(' INTERSECT ');
556
+ return this;
557
+ }
558
+ intersect(query) {
559
+ this.wrapCurrentSelectForIntersectIfNeeded();
560
+ this.intersectStatement();
561
+ this.select(query);
562
+ return this;
563
+ }
564
+ intersectAllStatement() {
565
+ this.sql.trimEnd(' ');
566
+ this.sql.append(' INTERSECT ALL ');
567
+ return this;
568
+ }
569
+ intersectAll(query) {
570
+ this.wrapCurrentSelectForIntersectIfNeeded();
571
+ this.intersectAllStatement();
572
+ this.select(query);
573
+ return this;
574
+ }
575
+ intersectWithSubquery(query, all = false) {
576
+ this.sql.trimEnd(' ');
577
+ this.sql.append(all ? ' INTERSECT ALL ' : ' INTERSECT ');
578
+ // Use Subquery to automatically wrap in parentheses
579
+ this.subquery(new subquery_1.Subquery(query));
580
+ this.sql.space();
581
+ return this;
582
+ }
583
+ exceptStatement() {
584
+ this.sql.trimEnd(' ');
585
+ this.sql.append(' EXCEPT ');
586
+ return this;
587
+ }
588
+ except(query) {
589
+ this.exceptWithSubquery(query);
590
+ return this;
591
+ }
592
+ exceptAllStatement() {
593
+ this.sql.trimEnd(' ');
594
+ this.sql.append(' EXCEPT ALL ');
595
+ return this;
596
+ }
597
+ exceptAll(query) {
598
+ this.exceptWithSubquery(query, true);
599
+ return this;
600
+ }
601
+ exceptWithSubquery(query, all = false) {
602
+ this.sql.trimEnd(' ');
603
+ this.sql.append(all ? ' EXCEPT ALL ' : ' EXCEPT ');
604
+ // Use Subquery to automatically wrap in parentheses
605
+ this.subquery(new subquery_1.Subquery(query));
606
+ this.sql.space();
607
+ return this;
608
+ }
609
+ // ------------------------------------------------------------------------
610
+ // Join
611
+ // ------------------------------------------------------------------------
612
+ join(join) {
613
+ var _a;
614
+ this.sql.append(((_a = join.type) !== null && _a !== void 0 ? _a : '') + ' JOIN ');
615
+ this.sql.tableName(join.table);
616
+ this.sql.space();
617
+ if (join.alias) {
618
+ this.tableAlias(join.alias);
619
+ }
620
+ if (join.on) {
621
+ this.sql.append('ON ');
622
+ this.expression(join.on);
623
+ }
624
+ }
625
+ // ------------------------------------------------------------------------
626
+ // Insert
627
+ // ------------------------------------------------------------------------
628
+ insertIntoStatement(table) {
629
+ this.sql.append('INSERT INTO ');
630
+ this.sql.tableName(table);
631
+ this.sql.space();
632
+ return this;
633
+ }
634
+ insertColumnNames(record) {
635
+ this.sql.openParens();
636
+ this.sql.commaSeparate(Object.keys(record).map((name) => this.sql.getEnclosedName(name)));
637
+ this.sql.closeParens();
638
+ return this;
639
+ }
640
+ insertOnDuplicateKeyUpdate(assignment) {
641
+ this.sql.append('ON DUPLICATE KEY UPDATE ');
642
+ this.updateKeyValues(assignment);
643
+ return this;
644
+ }
645
+ insertIfNotExists() {
646
+ this.insertOnDuplicateKeyUpdate({ id: (0, tokens_1.columnName)('id') });
647
+ return this;
648
+ }
649
+ insertOutput(primaryKey) {
650
+ // This will be overridden in mssql to return the insert id(s)
651
+ return this;
652
+ }
653
+ insertReturning(primaryKey) {
654
+ // This will be overridden in postgres to return the insert id(s)
655
+ return this;
656
+ }
657
+ insert(options) {
658
+ var _a;
659
+ this.insertIntoStatement(options.table);
660
+ if (!Array.isArray(options.records)) {
661
+ options.records = [options.records];
662
+ }
663
+ const columns = {};
664
+ const insertions = [];
665
+ if (options.records.length) {
666
+ for (const rec of options.records) {
667
+ for (const key in rec) {
668
+ if (!(key in columns)) {
669
+ columns[key] = true;
670
+ }
671
+ }
672
+ }
673
+ for (const rec of options.records) {
674
+ const insertion = {};
675
+ for (const key in columns) {
676
+ insertion[key] = (_a = rec[key]) !== null && _a !== void 0 ? _a : null;
677
+ }
678
+ insertions.push(insertion);
679
+ }
680
+ this.insertColumnNames(columns);
681
+ }
682
+ if (options.primaryKey) {
683
+ this.insertOutput(options.primaryKey);
684
+ }
685
+ this.sql.append('VALUES ');
686
+ for (let i = 0; i < insertions.length; i++) {
687
+ const record = insertions[i];
688
+ this.sql.openParens();
689
+ for (const key in record) {
690
+ this.expression(record[key]);
691
+ this.sql = this.sql.trimEnd();
692
+ this.sql.append(', ');
693
+ }
694
+ this.sql.trimEnd(', ');
695
+ this.sql.closeParens();
696
+ this.sql = this.sql.trimEnd();
697
+ this.sql.append(', ');
698
+ }
699
+ this.sql.trimEnd(', ');
700
+ this.sql.space();
701
+ if (options.ifNotExists) {
702
+ this.insertIfNotExists();
703
+ }
704
+ else if (options.onDuplicateKeyUpdate) {
705
+ this.insertOnDuplicateKeyUpdate(options.onDuplicateKeyUpdate);
706
+ }
707
+ this.sql.trimEnd(' ');
708
+ if (options.primaryKey) {
709
+ this.insertReturning(options.primaryKey);
710
+ }
711
+ return this;
712
+ }
713
+ // ------------------------------------------------------------------------
714
+ // Update
715
+ // ------------------------------------------------------------------------
716
+ updateStatement(table) {
717
+ this.sql.append('UPDATE ');
718
+ this.sql.tableName(table);
719
+ this.sql.space();
720
+ return this;
721
+ }
722
+ updateKeyValues(values) {
723
+ const keys = Object.keys(values);
724
+ for (const key of keys) {
725
+ this.sql.columnName(key);
726
+ this.sql.append(' = ');
727
+ this.expression(values[key]);
728
+ this.sql = this.sql.trimEnd();
729
+ this.sql.append(', ');
730
+ }
731
+ this.sql.trimEnd(', ');
732
+ this.sql.space();
733
+ return this;
734
+ }
735
+ updateSetStatement(values) {
736
+ this.sql.append('SET ');
737
+ this.updateKeyValues(values);
738
+ return this;
739
+ }
740
+ update(options) {
741
+ var _a;
742
+ this.updateStatement(options.table);
743
+ for (const join of (_a = options.join) !== null && _a !== void 0 ? _a : []) {
744
+ this.join(join);
745
+ }
746
+ this.updateSetStatement(options.set);
747
+ if (options.from) {
748
+ this.selectFrom(options.from);
749
+ }
750
+ if (options.where) {
751
+ this.where(options.where);
752
+ }
753
+ return this;
754
+ }
755
+ // ------------------------------------------------------------------------
756
+ // Delete
757
+ // ------------------------------------------------------------------------
758
+ deleteStatement(table) {
759
+ this.sql.append('DELETE FROM ');
760
+ this.sql.tableName(table);
761
+ this.sql.space();
762
+ return this;
763
+ }
764
+ delete(options) {
765
+ var _a;
766
+ this.deleteStatement(options.table);
767
+ for (const join of (_a = options.join) !== null && _a !== void 0 ? _a : []) {
768
+ this.join(join);
769
+ }
770
+ if (options.where) {
771
+ this.where(options.where);
772
+ }
773
+ return this;
774
+ }
775
+ // ------------------------------------------------------------------------
776
+ // Database Functions
777
+ // ------------------------------------------------------------------------
778
+ /**
779
+ * Append a database function the query
780
+ *
781
+ * @param fn Database function token
782
+ */
783
+ databaseFunction(fn) {
784
+ switch (fn.fn) {
785
+ case function_token_1.DatabaseFunctionKeys.AVERAGE:
786
+ this.average(fn);
787
+ break;
788
+ case function_token_1.DatabaseFunctionKeys.COUNT:
789
+ this.count(fn);
790
+ break;
791
+ case function_token_1.DatabaseFunctionKeys.MIN:
792
+ this.min(fn);
793
+ break;
794
+ case function_token_1.DatabaseFunctionKeys.MAX:
795
+ this.max(fn);
796
+ break;
797
+ case function_token_1.DatabaseFunctionKeys.ROUND:
798
+ this.round(fn);
799
+ break;
800
+ case function_token_1.DatabaseFunctionKeys.SUM:
801
+ this.sum(fn);
802
+ break;
803
+ case function_token_1.DatabaseFunctionKeys.CONCAT:
804
+ this.concat(fn);
805
+ break;
806
+ case function_token_1.DatabaseFunctionKeys.CURRENT_TIMESTAMP:
807
+ this.currentTimestamp(fn);
808
+ break;
809
+ case function_token_1.DatabaseFunctionKeys.DATE:
810
+ this.date(fn);
811
+ break;
812
+ case function_token_1.DatabaseFunctionKeys.DAY:
813
+ this.day(fn);
814
+ break;
815
+ case function_token_1.DatabaseFunctionKeys.YEAR:
816
+ this.year(fn);
817
+ break;
818
+ case function_token_1.DatabaseFunctionKeys.MONTH:
819
+ this.month(fn);
820
+ break;
821
+ case function_token_1.DatabaseFunctionKeys.UUID:
822
+ this.uuid();
823
+ break;
824
+ }
825
+ return this;
826
+ }
827
+ average(fn) {
828
+ this.sql.append('AVG');
829
+ this.sql.openParens();
830
+ if (fn.params.options.distinct) {
831
+ this.distinctStatement();
832
+ }
833
+ this.expression(fn.params.expr);
834
+ this.sql.closeParens();
835
+ return this;
836
+ }
837
+ count(fn) {
838
+ var _a, _b, _c, _d;
839
+ this.sql.append('COUNT(');
840
+ if ((_a = fn.params) === null || _a === void 0 ? void 0 : _a.distinct) {
841
+ this.distinctStatement();
842
+ }
843
+ if ((_b = fn.params) === null || _b === void 0 ? void 0 : _b.expr) {
844
+ this.expression(fn.params.expr);
845
+ }
846
+ else if ((_c = fn.params) === null || _c === void 0 ? void 0 : _c.column) {
847
+ this.sql.columnName(fn.params.column);
848
+ }
849
+ else if (((_d = fn.params) === null || _d === void 0 ? void 0 : _d.columns) && fn.params.columns.length > 0) {
850
+ // For multiple columns, separate with commas
851
+ this.sql.commaSeparate(fn.params.columns.map((col) => this.sql.getEnclosedName(col)));
852
+ }
853
+ else {
854
+ this.sql.append('*');
855
+ }
856
+ this.sql.append(')');
857
+ return this;
858
+ }
859
+ min(fn) {
860
+ this.sql.append('MIN');
861
+ this.sql.openParens();
862
+ this.expression(fn.params);
863
+ this.sql.closeParens();
864
+ return this;
865
+ }
866
+ max(fn) {
867
+ this.sql.append('MAX');
868
+ this.sql.openParens();
869
+ this.expression(fn.params);
870
+ this.sql.closeParens();
871
+ return this;
872
+ }
873
+ round(fn) {
874
+ this.sql.append('ROUND');
875
+ this.sql.openParens();
876
+ this.expression(fn.params.expr);
877
+ if (fn.params.decimals !== undefined) {
878
+ this.sql.trimEnd();
879
+ this.sql.append(', ');
880
+ this.sql.append(fn.params.decimals);
881
+ }
882
+ this.sql.closeParens();
883
+ return this;
884
+ }
885
+ sum(fn) {
886
+ this.sql.append('SUM');
887
+ this.sql.openParens();
888
+ if (fn.params.options.distinct) {
889
+ this.distinctStatement();
890
+ }
891
+ this.expression(fn.params.expr);
892
+ this.sql.closeParens();
893
+ return this;
894
+ }
895
+ concat(fn) {
896
+ var _a, _b;
897
+ this.sql.append('CONCAT');
898
+ this.sql.openParens();
899
+ const expr = (_b = (_a = fn.params) === null || _a === void 0 ? void 0 : _a.expr) !== null && _b !== void 0 ? _b : [];
900
+ for (let i = 0; i < expr.length; i++) {
901
+ this.expression(expr[i]);
902
+ if (i < expr.length - 1) {
903
+ this.sql.append(', ');
904
+ }
905
+ }
906
+ this.sql.closeParens();
907
+ return this;
908
+ }
909
+ currentTimestamp(fn) {
910
+ this.sql.append('CURRENT_TIMESTAMP');
911
+ return this;
912
+ }
913
+ date(fn) {
914
+ var _a;
915
+ this.sql.append('date');
916
+ this.sql.openParens();
917
+ if ((_a = fn.params) === null || _a === void 0 ? void 0 : _a.expr) {
918
+ this.expression(fn.params.expr);
919
+ }
920
+ else {
921
+ this.expression(functions_1.DatabaseFunctions.currentTimestamp());
922
+ }
923
+ this.sql.closeParens();
924
+ return this;
925
+ }
926
+ day(fn) {
927
+ var _a;
928
+ this.sql.append('day');
929
+ this.sql.openParens();
930
+ if ((_a = fn.params) === null || _a === void 0 ? void 0 : _a.expr) {
931
+ this.expression(fn.params.expr);
932
+ }
933
+ else {
934
+ this.expression(functions_1.DatabaseFunctions.currentTimestamp());
935
+ }
936
+ this.sql.closeParens();
937
+ return this;
938
+ }
939
+ year(fn) {
940
+ var _a;
941
+ this.sql.append('year');
942
+ this.sql.openParens();
943
+ if ((_a = fn.params) === null || _a === void 0 ? void 0 : _a.expr) {
944
+ this.expression(fn.params.expr);
945
+ }
946
+ else {
947
+ this.expression(functions_1.DatabaseFunctions.currentTimestamp());
948
+ }
949
+ this.sql.closeParens();
950
+ return this;
951
+ }
952
+ month(fn) {
953
+ var _a;
954
+ this.sql.append('month');
955
+ this.sql.openParens();
956
+ if ((_a = fn.params) === null || _a === void 0 ? void 0 : _a.expr) {
957
+ this.expression(fn.params.expr);
958
+ }
959
+ else {
960
+ this.expression(functions_1.DatabaseFunctions.currentTimestamp());
961
+ }
962
+ this.sql.closeParens();
963
+ return this;
964
+ }
965
+ uuid() {
966
+ this.sql.append('uuid()');
967
+ return this;
968
+ }
969
+ // ------------------------------------------------------------------------
970
+ // Triggers
971
+ // ------------------------------------------------------------------------
972
+ getTriggerOld() {
973
+ return 'OLD';
974
+ }
975
+ getTriggerOldColumn(column) {
976
+ return `${this.getTriggerOld()}.${column}`;
977
+ }
978
+ getTriggerNew() {
979
+ return 'NEW';
980
+ }
981
+ getTriggerNewColumn(column) {
982
+ return `${this.getTriggerNew()}.${column}`;
983
+ }
984
+ triggerSetValue(options) {
985
+ return this.set({
986
+ column: `NEW.${options.column}`,
987
+ value: options.value,
988
+ });
989
+ }
990
+ }
991
+ exports.DatabaseQueryBuilder = DatabaseQueryBuilder;
794
992
  //# sourceMappingURL=query-builder.js.map