@balena/abstract-sql-compiler 11.0.0-build-11-x-b2280608fff69d9959999c79db6245c4ad561bbc-1 → 11.0.0-build-11-x-7511b8ebe5a9461f20add0ed97d0670ed3b5a479-1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +5 -2
- package/.github/workflows/flowzone.yml +0 -21
- package/.husky/pre-commit +0 -2
- package/.versionbot/CHANGELOG.yml +0 -10729
- package/CHANGELOG.md +0 -3515
- package/repo.yml +0 -12
- package/src/abstract-sql-compiler.ts +0 -1138
- package/src/abstract-sql-optimizer.ts +0 -1632
- package/src/abstract-sql-rules-to-sql.ts +0 -1730
- package/src/abstract-sql-schema-optimizer.ts +0 -172
- package/src/referenced-fields.ts +0 -600
- package/test/abstract-sql/aggregate-json.ts +0 -49
- package/test/abstract-sql/aggregate.ts +0 -161
- package/test/abstract-sql/and-or-boolean-optimisations.ts +0 -115
- package/test/abstract-sql/case-when-else.ts +0 -48
- package/test/abstract-sql/cast.ts +0 -25
- package/test/abstract-sql/coalesce.ts +0 -24
- package/test/abstract-sql/comparisons.ts +0 -360
- package/test/abstract-sql/dates.ts +0 -512
- package/test/abstract-sql/duration.ts +0 -56
- package/test/abstract-sql/empty-query-optimisations.ts +0 -54
- package/test/abstract-sql/functions-wrapper.ts +0 -70
- package/test/abstract-sql/get-referenced-fields.ts +0 -674
- package/test/abstract-sql/get-rule-referenced-fields.ts +0 -345
- package/test/abstract-sql/insert-query.ts +0 -22
- package/test/abstract-sql/is-distinct.ts +0 -102
- package/test/abstract-sql/joins.ts +0 -84
- package/test/abstract-sql/json.ts +0 -58
- package/test/abstract-sql/math.ts +0 -467
- package/test/abstract-sql/nested-in-optimisations.ts +0 -200
- package/test/abstract-sql/not-not-optimisations.ts +0 -15
- package/test/abstract-sql/schema-checks.ts +0 -168
- package/test/abstract-sql/schema-informative-reference.ts +0 -420
- package/test/abstract-sql/schema-rule-optimization.ts +0 -120
- package/test/abstract-sql/schema-rule-to-check.ts +0 -393
- package/test/abstract-sql/schema-views.ts +0 -73
- package/test/abstract-sql/test.ts +0 -192
- package/test/abstract-sql/text.ts +0 -168
- package/test/model.sbvr +0 -60
- package/test/odata/expand.ts +0 -674
- package/test/odata/fields.ts +0 -59
- package/test/odata/filterby.ts +0 -1517
- package/test/odata/orderby.ts +0 -96
- package/test/odata/paging.ts +0 -48
- package/test/odata/resource-parsing.ts +0 -568
- package/test/odata/select.ts +0 -119
- package/test/odata/stress.ts +0 -93
- package/test/odata/test.ts +0 -297
- package/test/sbvr/pilots.ts +0 -1097
- package/test/sbvr/reference-type.ts +0 -211
- package/test/sbvr/test.ts +0 -101
- package/tsconfig.build.json +0 -6
- package/tsconfig.json +0 -25
@@ -1,512 +0,0 @@
|
|
1
|
-
import test from './test.js';
|
2
|
-
|
3
|
-
describe('Year', () => {
|
4
|
-
test(
|
5
|
-
['SelectQuery', ['Select', [['Year', ['Date', '2022-10-10']]]]],
|
6
|
-
[['Date', '2022-10-10']],
|
7
|
-
(result, sqlEquals) => {
|
8
|
-
it('should produce a valid Year statement', () => {
|
9
|
-
sqlEquals(result, `SELECT EXTRACT('YEAR' FROM $1)`);
|
10
|
-
});
|
11
|
-
},
|
12
|
-
);
|
13
|
-
});
|
14
|
-
|
15
|
-
describe('Month', () => {
|
16
|
-
test(
|
17
|
-
['SelectQuery', ['Select', [['Month', ['Date', '2022-10-10']]]]],
|
18
|
-
[['Date', '2022-10-10']],
|
19
|
-
(result, sqlEquals) => {
|
20
|
-
it('should produce a valid Month statement', () => {
|
21
|
-
sqlEquals(result, `SELECT EXTRACT('MONTH' FROM $1)`);
|
22
|
-
});
|
23
|
-
},
|
24
|
-
);
|
25
|
-
});
|
26
|
-
|
27
|
-
describe('Day', () => {
|
28
|
-
test(
|
29
|
-
['SelectQuery', ['Select', [['Day', ['Date', '2022-10-10']]]]],
|
30
|
-
[['Date', '2022-10-10']],
|
31
|
-
(result, sqlEquals) => {
|
32
|
-
it('should produce a valid Day statement', () => {
|
33
|
-
sqlEquals(result, `SELECT EXTRACT('DAY' FROM $1)`);
|
34
|
-
});
|
35
|
-
},
|
36
|
-
);
|
37
|
-
});
|
38
|
-
|
39
|
-
describe('Hour', () => {
|
40
|
-
test(
|
41
|
-
[
|
42
|
-
'SelectQuery',
|
43
|
-
['Select', [['Hour', ['Date', '2022-10-10T10:10:10.000Z']]]],
|
44
|
-
],
|
45
|
-
[['Date', '2022-10-10T10:10:10.000Z']],
|
46
|
-
(result, sqlEquals) => {
|
47
|
-
it('should produce a valid Hour statement', () => {
|
48
|
-
sqlEquals(result, `SELECT EXTRACT('HOUR' FROM $1)`);
|
49
|
-
});
|
50
|
-
},
|
51
|
-
);
|
52
|
-
});
|
53
|
-
|
54
|
-
describe('Minute', () => {
|
55
|
-
test(
|
56
|
-
[
|
57
|
-
'SelectQuery',
|
58
|
-
['Select', [['Minute', ['Date', '2022-10-10T10:10:10.000Z']]]],
|
59
|
-
],
|
60
|
-
[['Date', '2022-10-10T10:10:10.000Z']],
|
61
|
-
(result, sqlEquals) => {
|
62
|
-
it('should produce a valid Minute statement', () => {
|
63
|
-
sqlEquals(result, `SELECT EXTRACT('MINUTE' FROM $1)`);
|
64
|
-
});
|
65
|
-
},
|
66
|
-
);
|
67
|
-
});
|
68
|
-
|
69
|
-
describe('Second', () => {
|
70
|
-
test(
|
71
|
-
[
|
72
|
-
'SelectQuery',
|
73
|
-
['Select', [['Second', ['Date', '2022-10-10T10:10:10.000Z']]]],
|
74
|
-
],
|
75
|
-
[['Date', '2022-10-10T10:10:10.000Z']],
|
76
|
-
(result, sqlEquals) => {
|
77
|
-
it('should produce a valid extract second statement', () => {
|
78
|
-
sqlEquals(result, `SELECT FLOOR(EXTRACT('SECOND' FROM $1))`);
|
79
|
-
});
|
80
|
-
},
|
81
|
-
);
|
82
|
-
});
|
83
|
-
|
84
|
-
describe('Fractionalseconds', () => {
|
85
|
-
test(
|
86
|
-
[
|
87
|
-
'SelectQuery',
|
88
|
-
['Select', [['Fractionalseconds', ['Date', '2022-10-10T10:10:10.000Z']]]],
|
89
|
-
],
|
90
|
-
[['Date', '2022-10-10T10:10:10.000Z']],
|
91
|
-
(result, sqlEquals) => {
|
92
|
-
it('should produce a valid extract Fractionalseconds statement', () => {
|
93
|
-
sqlEquals(
|
94
|
-
result,
|
95
|
-
`SELECT EXTRACT('SECOND' FROM $1) - FLOOR(EXTRACT('SECOND' FROM $1))`,
|
96
|
-
);
|
97
|
-
});
|
98
|
-
},
|
99
|
-
);
|
100
|
-
});
|
101
|
-
|
102
|
-
describe('ToDate', () => {
|
103
|
-
test(
|
104
|
-
['SelectQuery', ['Select', [['ToDate', ['Date', '2022-10-10']]]]],
|
105
|
-
[['Date', '2022-10-10']],
|
106
|
-
(result, sqlEquals) => {
|
107
|
-
it('should produce a valid ToDate statement', () => {
|
108
|
-
sqlEquals(result, `SELECT DATE($1)`);
|
109
|
-
});
|
110
|
-
},
|
111
|
-
);
|
112
|
-
});
|
113
|
-
|
114
|
-
describe('DateTrunc', () => {
|
115
|
-
test(
|
116
|
-
[
|
117
|
-
'SelectQuery',
|
118
|
-
[
|
119
|
-
'Select',
|
120
|
-
[['DateTrunc', ['EmbeddedText', 'year'], ['Date', '2022-10-10']]],
|
121
|
-
],
|
122
|
-
],
|
123
|
-
[['Date', '2022-10-10']],
|
124
|
-
(result, sqlEquals) => {
|
125
|
-
it('should produce a valid DateTrunc statement', () => {
|
126
|
-
sqlEquals(result, `SELECT DATE_TRUNC('year', $1)`);
|
127
|
-
});
|
128
|
-
},
|
129
|
-
);
|
130
|
-
|
131
|
-
test(
|
132
|
-
[
|
133
|
-
'SelectQuery',
|
134
|
-
[
|
135
|
-
'Select',
|
136
|
-
[
|
137
|
-
[
|
138
|
-
'DateTrunc',
|
139
|
-
['EmbeddedText', 'year'],
|
140
|
-
['Date', '2022-10-10'],
|
141
|
-
['EmbeddedText', 'UTC'],
|
142
|
-
],
|
143
|
-
],
|
144
|
-
],
|
145
|
-
],
|
146
|
-
[['Date', '2022-10-10']],
|
147
|
-
(result, sqlEquals) => {
|
148
|
-
it('should produce a valid DateTrunc statement', () => {
|
149
|
-
sqlEquals(result, `SELECT DATE_TRUNC('year', $1, 'UTC')`);
|
150
|
-
});
|
151
|
-
},
|
152
|
-
);
|
153
|
-
});
|
154
|
-
|
155
|
-
describe('ToTime', () => {
|
156
|
-
test(
|
157
|
-
[
|
158
|
-
'SelectQuery',
|
159
|
-
['Select', [['ToTime', ['Date', '2022-10-10T10:10:10.000Z']]]],
|
160
|
-
],
|
161
|
-
[['Date', '2022-10-10T10:10:10.000Z']],
|
162
|
-
(result, sqlEquals) => {
|
163
|
-
it('should produce a valid ToTime statement', () => {
|
164
|
-
sqlEquals(result, `SELECT CAST($1 AS TIME)`);
|
165
|
-
});
|
166
|
-
},
|
167
|
-
);
|
168
|
-
});
|
169
|
-
|
170
|
-
describe('AddDateDuration', () => {
|
171
|
-
test(
|
172
|
-
[
|
173
|
-
'SelectQuery',
|
174
|
-
[
|
175
|
-
'Select',
|
176
|
-
[
|
177
|
-
[
|
178
|
-
'AddDateDuration',
|
179
|
-
['Date', '2022-10-10T10:10:10.000Z'],
|
180
|
-
[
|
181
|
-
'Duration',
|
182
|
-
{
|
183
|
-
day: 1,
|
184
|
-
},
|
185
|
-
],
|
186
|
-
],
|
187
|
-
],
|
188
|
-
],
|
189
|
-
],
|
190
|
-
[['Date', '2022-10-10T10:10:10.000Z']],
|
191
|
-
(result, sqlEquals) => {
|
192
|
-
it('should produce a valid Date addition statement', () => {
|
193
|
-
sqlEquals(result, `SELECT $1 + INTERVAL '1 0:0:0.0'`);
|
194
|
-
});
|
195
|
-
},
|
196
|
-
);
|
197
|
-
|
198
|
-
test(
|
199
|
-
[
|
200
|
-
'SelectQuery',
|
201
|
-
[
|
202
|
-
'Select',
|
203
|
-
[
|
204
|
-
[
|
205
|
-
'AddDateDuration',
|
206
|
-
[
|
207
|
-
'AddDateDuration',
|
208
|
-
['Date', '2022-10-10T10:10:10.000Z'],
|
209
|
-
[
|
210
|
-
'Duration',
|
211
|
-
{
|
212
|
-
day: 1,
|
213
|
-
},
|
214
|
-
],
|
215
|
-
],
|
216
|
-
[
|
217
|
-
'Duration',
|
218
|
-
{
|
219
|
-
day: 2,
|
220
|
-
},
|
221
|
-
],
|
222
|
-
],
|
223
|
-
],
|
224
|
-
],
|
225
|
-
],
|
226
|
-
[['Date', '2022-10-10T10:10:10.000Z']],
|
227
|
-
(result, sqlEquals) => {
|
228
|
-
it('should produce a valid Date addition statement when the first operand returns a Date node', () => {
|
229
|
-
sqlEquals(
|
230
|
-
result,
|
231
|
-
`SELECT ($1 + INTERVAL '1 0:0:0.0') + INTERVAL '2 0:0:0.0'`,
|
232
|
-
);
|
233
|
-
});
|
234
|
-
},
|
235
|
-
);
|
236
|
-
});
|
237
|
-
|
238
|
-
describe('AddDateNumber', () => {
|
239
|
-
test(
|
240
|
-
[
|
241
|
-
'SelectQuery',
|
242
|
-
[
|
243
|
-
'Select',
|
244
|
-
[
|
245
|
-
[
|
246
|
-
'AddDateNumber',
|
247
|
-
['Date', '2022-10-10T10:10:10.000Z'],
|
248
|
-
['Number', 10],
|
249
|
-
],
|
250
|
-
],
|
251
|
-
],
|
252
|
-
],
|
253
|
-
[['Date', '2022-10-10T10:10:10.000Z']],
|
254
|
-
(result, sqlEquals) => {
|
255
|
-
it('should produce a valid Date addition statement', () => {
|
256
|
-
sqlEquals(result, `SELECT $1 + 10`);
|
257
|
-
});
|
258
|
-
},
|
259
|
-
);
|
260
|
-
|
261
|
-
test(
|
262
|
-
[
|
263
|
-
'SelectQuery',
|
264
|
-
[
|
265
|
-
'Select',
|
266
|
-
[
|
267
|
-
[
|
268
|
-
'AddDateNumber',
|
269
|
-
['Date', '2022-10-10T10:10:10.000Z'],
|
270
|
-
['Subtract', ['Number', 4], ['Number', 5]],
|
271
|
-
],
|
272
|
-
],
|
273
|
-
],
|
274
|
-
],
|
275
|
-
[['Date', '2022-10-10T10:10:10.000Z']],
|
276
|
-
(result, sqlEquals) => {
|
277
|
-
it('should produce a valid Date addition statement when the second operand is a math operation', () => {
|
278
|
-
sqlEquals(result, `SELECT $1 + (4 - 5)`);
|
279
|
-
});
|
280
|
-
},
|
281
|
-
);
|
282
|
-
});
|
283
|
-
|
284
|
-
describe('SubtractDateNumber', () => {
|
285
|
-
test(
|
286
|
-
[
|
287
|
-
'SelectQuery',
|
288
|
-
[
|
289
|
-
'Select',
|
290
|
-
[
|
291
|
-
[
|
292
|
-
'SubtractDateNumber',
|
293
|
-
['Date', '2022-10-10T10:10:10.000Z'],
|
294
|
-
['Number', 10],
|
295
|
-
],
|
296
|
-
],
|
297
|
-
],
|
298
|
-
],
|
299
|
-
[['Date', '2022-10-10T10:10:10.000Z']],
|
300
|
-
(result, sqlEquals) => {
|
301
|
-
it('should produce a valid Date subtraction statement', () => {
|
302
|
-
sqlEquals(result, `SELECT $1 - 10`);
|
303
|
-
});
|
304
|
-
},
|
305
|
-
);
|
306
|
-
|
307
|
-
test(
|
308
|
-
[
|
309
|
-
'SelectQuery',
|
310
|
-
[
|
311
|
-
'Select',
|
312
|
-
[
|
313
|
-
[
|
314
|
-
'SubtractDateNumber',
|
315
|
-
['Date', '2022-10-10T10:10:10.000Z'],
|
316
|
-
['Subtract', ['Number', 4], ['Number', 5]],
|
317
|
-
],
|
318
|
-
],
|
319
|
-
],
|
320
|
-
],
|
321
|
-
[['Date', '2022-10-10T10:10:10.000Z']],
|
322
|
-
(result, sqlEquals) => {
|
323
|
-
it('should produce a valid Date subtraction statement when the second operand is a math operation', () => {
|
324
|
-
sqlEquals(result, `SELECT $1 - (4 - 5)`);
|
325
|
-
});
|
326
|
-
},
|
327
|
-
);
|
328
|
-
|
329
|
-
test(
|
330
|
-
[
|
331
|
-
'SelectQuery',
|
332
|
-
[
|
333
|
-
'Select',
|
334
|
-
[
|
335
|
-
[
|
336
|
-
'SubtractDateNumber',
|
337
|
-
[
|
338
|
-
'AddDateNumber',
|
339
|
-
['Date', '2022-10-10T10:10:10.000Z'],
|
340
|
-
['Number', 1],
|
341
|
-
],
|
342
|
-
['Subtract', ['Number', 4], ['Number', 5]],
|
343
|
-
],
|
344
|
-
],
|
345
|
-
],
|
346
|
-
],
|
347
|
-
[['Date', '2022-10-10T10:10:10.000Z']],
|
348
|
-
(result, sqlEquals) => {
|
349
|
-
it('should produce a valid Date subtraction statement when first operand returns a Date and the second operand is a math operation', () => {
|
350
|
-
sqlEquals(result, `SELECT ($1 + 1) - (4 - 5)`);
|
351
|
-
});
|
352
|
-
},
|
353
|
-
);
|
354
|
-
});
|
355
|
-
|
356
|
-
describe('SubtractDateDate', () => {
|
357
|
-
test(
|
358
|
-
[
|
359
|
-
'SelectQuery',
|
360
|
-
[
|
361
|
-
'Select',
|
362
|
-
[
|
363
|
-
[
|
364
|
-
'Multiply',
|
365
|
-
['SubtractDateDate', ['CurrentTimestamp'], ['CurrentTimestamp']],
|
366
|
-
['Number', 4],
|
367
|
-
],
|
368
|
-
],
|
369
|
-
],
|
370
|
-
],
|
371
|
-
(result, sqlEquals) => {
|
372
|
-
it('should produce a valid multiplication statement when the first operand is a SubtractDateDate operation and the second a number', () => {
|
373
|
-
sqlEquals(result, `SELECT (CURRENT_TIMESTAMP - CURRENT_TIMESTAMP) * 4`);
|
374
|
-
});
|
375
|
-
},
|
376
|
-
);
|
377
|
-
|
378
|
-
test(
|
379
|
-
[
|
380
|
-
'SelectQuery',
|
381
|
-
[
|
382
|
-
'Select',
|
383
|
-
[
|
384
|
-
[
|
385
|
-
'Multiply',
|
386
|
-
['SubtractDateDate', ['CurrentTimestamp'], ['CurrentTimestamp']],
|
387
|
-
['Subtract', ['Number', 4], ['Number', 5]],
|
388
|
-
],
|
389
|
-
],
|
390
|
-
],
|
391
|
-
],
|
392
|
-
(result, sqlEquals) => {
|
393
|
-
it('should produce a valid multiplication statement when the first operand is a SubtractDateDate operation and the second a math subtraction', () => {
|
394
|
-
sqlEquals(
|
395
|
-
result,
|
396
|
-
`SELECT (CURRENT_TIMESTAMP - CURRENT_TIMESTAMP) * (4 - 5)`,
|
397
|
-
);
|
398
|
-
});
|
399
|
-
},
|
400
|
-
);
|
401
|
-
|
402
|
-
test(
|
403
|
-
[
|
404
|
-
'SelectQuery',
|
405
|
-
[
|
406
|
-
'Select',
|
407
|
-
[
|
408
|
-
[
|
409
|
-
'SubtractDateDate',
|
410
|
-
[
|
411
|
-
'AddDateDuration',
|
412
|
-
['CurrentTimestamp'],
|
413
|
-
[
|
414
|
-
'Duration',
|
415
|
-
{
|
416
|
-
day: 1,
|
417
|
-
},
|
418
|
-
],
|
419
|
-
],
|
420
|
-
[
|
421
|
-
'AddDateDuration',
|
422
|
-
['Date', '2022-10-10T10:10:10.000Z'],
|
423
|
-
[
|
424
|
-
'Duration',
|
425
|
-
{
|
426
|
-
day: 2,
|
427
|
-
},
|
428
|
-
],
|
429
|
-
],
|
430
|
-
],
|
431
|
-
],
|
432
|
-
],
|
433
|
-
],
|
434
|
-
[['Date', '2022-10-10T10:10:10.000Z']],
|
435
|
-
(result, sqlEquals) => {
|
436
|
-
it('should produce a valid SubtractDateDate operation when the operands return a Date node', () => {
|
437
|
-
sqlEquals(
|
438
|
-
result,
|
439
|
-
`SELECT (CURRENT_TIMESTAMP + INTERVAL '1 0:0:0.0') - ($1 + INTERVAL '2 0:0:0.0')`,
|
440
|
-
);
|
441
|
-
});
|
442
|
-
},
|
443
|
-
);
|
444
|
-
});
|
445
|
-
|
446
|
-
describe('SubtractDateDuration', () => {
|
447
|
-
test(
|
448
|
-
[
|
449
|
-
'SelectQuery',
|
450
|
-
[
|
451
|
-
'Select',
|
452
|
-
[
|
453
|
-
[
|
454
|
-
'SubtractDateDuration',
|
455
|
-
['Date', '2022-10-10T10:10:10.000Z'],
|
456
|
-
[
|
457
|
-
'Duration',
|
458
|
-
{
|
459
|
-
day: 1,
|
460
|
-
},
|
461
|
-
],
|
462
|
-
],
|
463
|
-
],
|
464
|
-
],
|
465
|
-
],
|
466
|
-
[['Date', '2022-10-10T10:10:10.000Z']],
|
467
|
-
(result, sqlEquals) => {
|
468
|
-
it('should produce a valid Date subtraction statement', () => {
|
469
|
-
sqlEquals(result, `SELECT $1 - INTERVAL '1 0:0:0.0'`);
|
470
|
-
});
|
471
|
-
},
|
472
|
-
);
|
473
|
-
|
474
|
-
test(
|
475
|
-
[
|
476
|
-
'SelectQuery',
|
477
|
-
[
|
478
|
-
'Select',
|
479
|
-
[
|
480
|
-
[
|
481
|
-
'SubtractDateDuration',
|
482
|
-
[
|
483
|
-
'AddDateDuration',
|
484
|
-
['Date', '2022-10-10T10:10:10.000Z'],
|
485
|
-
[
|
486
|
-
'Duration',
|
487
|
-
{
|
488
|
-
day: 1,
|
489
|
-
},
|
490
|
-
],
|
491
|
-
],
|
492
|
-
[
|
493
|
-
'Duration',
|
494
|
-
{
|
495
|
-
day: 2,
|
496
|
-
},
|
497
|
-
],
|
498
|
-
],
|
499
|
-
],
|
500
|
-
],
|
501
|
-
],
|
502
|
-
[['Date', '2022-10-10T10:10:10.000Z']],
|
503
|
-
(result, sqlEquals) => {
|
504
|
-
it('should produce a valid Date subtraction statement when the first operand returns a Date node', () => {
|
505
|
-
sqlEquals(
|
506
|
-
result,
|
507
|
-
`SELECT ($1 + INTERVAL '1 0:0:0.0') - INTERVAL '2 0:0:0.0'`,
|
508
|
-
);
|
509
|
-
});
|
510
|
-
},
|
511
|
-
);
|
512
|
-
});
|
@@ -1,56 +0,0 @@
|
|
1
|
-
import test from './test.js';
|
2
|
-
|
3
|
-
describe('Totalseconds', () => {
|
4
|
-
test(
|
5
|
-
[
|
6
|
-
'SelectQuery',
|
7
|
-
[
|
8
|
-
'Select',
|
9
|
-
[
|
10
|
-
[
|
11
|
-
'Totalseconds',
|
12
|
-
[
|
13
|
-
'Duration',
|
14
|
-
{
|
15
|
-
day: 1,
|
16
|
-
},
|
17
|
-
],
|
18
|
-
],
|
19
|
-
],
|
20
|
-
],
|
21
|
-
],
|
22
|
-
(result, sqlEquals) => {
|
23
|
-
it('should produce a valid Totalseconds statement', () => {
|
24
|
-
sqlEquals(result, `SELECT EXTRACT(EPOCH FROM INTERVAL '1 0:0:0.0')`);
|
25
|
-
});
|
26
|
-
},
|
27
|
-
);
|
28
|
-
});
|
29
|
-
|
30
|
-
describe('Duration', () => {
|
31
|
-
test(
|
32
|
-
[
|
33
|
-
'SelectQuery',
|
34
|
-
[
|
35
|
-
'Select',
|
36
|
-
[
|
37
|
-
[
|
38
|
-
'Duration',
|
39
|
-
{
|
40
|
-
negative: false,
|
41
|
-
day: 1,
|
42
|
-
hour: 2,
|
43
|
-
minute: 3,
|
44
|
-
second: 4,
|
45
|
-
},
|
46
|
-
],
|
47
|
-
],
|
48
|
-
],
|
49
|
-
],
|
50
|
-
(result, sqlEquals) => {
|
51
|
-
it('should produce a valid Duration statement', () => {
|
52
|
-
sqlEquals(result, `SELECT INTERVAL '1 2:3:4.0'`);
|
53
|
-
});
|
54
|
-
},
|
55
|
-
);
|
56
|
-
});
|
@@ -1,54 +0,0 @@
|
|
1
|
-
import { stripIndent } from 'common-tags';
|
2
|
-
import type { SelectQueryNode } from '../../out/abstract-sql-compiler.js';
|
3
|
-
|
4
|
-
import test from './test.js';
|
5
|
-
|
6
|
-
describe('Empty queries should be optimized', () => {
|
7
|
-
const emptyQuery: SelectQueryNode = [
|
8
|
-
'SelectQuery',
|
9
|
-
['Select', []],
|
10
|
-
['From', ['Table', 'table']],
|
11
|
-
['Where', ['Boolean', false]],
|
12
|
-
];
|
13
|
-
test(
|
14
|
-
[
|
15
|
-
'SelectQuery',
|
16
|
-
['Select', []],
|
17
|
-
['From', ['Table', 'table']],
|
18
|
-
['Where', ['Exists', emptyQuery]],
|
19
|
-
],
|
20
|
-
(result, sqlEquals) => {
|
21
|
-
it('should simplify `EXISTS($emptyQuery)` to `false`', () => {
|
22
|
-
sqlEquals(
|
23
|
-
result,
|
24
|
-
stripIndent`
|
25
|
-
SELECT 1
|
26
|
-
FROM "table"
|
27
|
-
WHERE false
|
28
|
-
`,
|
29
|
-
);
|
30
|
-
});
|
31
|
-
},
|
32
|
-
);
|
33
|
-
|
34
|
-
test(
|
35
|
-
[
|
36
|
-
'SelectQuery',
|
37
|
-
['Select', []],
|
38
|
-
['From', ['Table', 'table']],
|
39
|
-
['Where', ['NotExists', emptyQuery]],
|
40
|
-
],
|
41
|
-
(result, sqlEquals) => {
|
42
|
-
it('should simplify `NOT EXISTS($emptyQuery)` to `true`', () => {
|
43
|
-
sqlEquals(
|
44
|
-
result,
|
45
|
-
stripIndent`
|
46
|
-
SELECT 1
|
47
|
-
FROM "table"
|
48
|
-
WHERE true
|
49
|
-
`,
|
50
|
-
);
|
51
|
-
});
|
52
|
-
},
|
53
|
-
);
|
54
|
-
});
|
@@ -1,70 +0,0 @@
|
|
1
|
-
import { stripIndent } from 'common-tags';
|
2
|
-
import test from './test.js';
|
3
|
-
|
4
|
-
describe('Date trunc function on ReferencedField for milliseconds', () => {
|
5
|
-
test(
|
6
|
-
[
|
7
|
-
'SelectQuery',
|
8
|
-
['Select', []],
|
9
|
-
['From', ['Table', 'table']],
|
10
|
-
[
|
11
|
-
'Where',
|
12
|
-
[
|
13
|
-
'GreaterThan',
|
14
|
-
[
|
15
|
-
'DateTrunc',
|
16
|
-
['EmbeddedText', 'milliseconds'],
|
17
|
-
['ReferencedField', 'table', 'created at'],
|
18
|
-
],
|
19
|
-
['Bind', 0],
|
20
|
-
],
|
21
|
-
],
|
22
|
-
],
|
23
|
-
[['Bind', 0]],
|
24
|
-
(result, sqlEquals) => {
|
25
|
-
it('Generate a postgresql DATE_TRUNC query for referenced field with milliseconds resoluton and binding', () => {
|
26
|
-
sqlEquals(
|
27
|
-
result,
|
28
|
-
stripIndent`
|
29
|
-
SELECT 1
|
30
|
-
FROM "table"
|
31
|
-
WHERE DATE_TRUNC('milliseconds', "table"."created at") > $1
|
32
|
-
`,
|
33
|
-
);
|
34
|
-
});
|
35
|
-
},
|
36
|
-
);
|
37
|
-
|
38
|
-
test.mysql(
|
39
|
-
[
|
40
|
-
'SelectQuery',
|
41
|
-
['Select', []],
|
42
|
-
['From', ['Table', 'table']],
|
43
|
-
[
|
44
|
-
'Where',
|
45
|
-
[
|
46
|
-
'GreaterThan',
|
47
|
-
[
|
48
|
-
'DateTrunc',
|
49
|
-
['EmbeddedText', 'milliseconds'],
|
50
|
-
['ReferencedField', 'table', 'created at'],
|
51
|
-
],
|
52
|
-
['Bind', 0],
|
53
|
-
],
|
54
|
-
],
|
55
|
-
],
|
56
|
-
[['Bind', 0]],
|
57
|
-
(result, sqlEquals) => {
|
58
|
-
it('Ignore DATE_TRUNC in mysql query for referenced field with milliseconds resoluton and binding', () => {
|
59
|
-
sqlEquals(
|
60
|
-
result,
|
61
|
-
stripIndent`
|
62
|
-
SELECT 1
|
63
|
-
FROM "table"
|
64
|
-
WHERE "table"."created at" > ?
|
65
|
-
`,
|
66
|
-
);
|
67
|
-
});
|
68
|
-
},
|
69
|
-
);
|
70
|
-
});
|