@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.
Files changed (53) hide show
  1. package/package.json +5 -2
  2. package/.github/workflows/flowzone.yml +0 -21
  3. package/.husky/pre-commit +0 -2
  4. package/.versionbot/CHANGELOG.yml +0 -10729
  5. package/CHANGELOG.md +0 -3515
  6. package/repo.yml +0 -12
  7. package/src/abstract-sql-compiler.ts +0 -1138
  8. package/src/abstract-sql-optimizer.ts +0 -1632
  9. package/src/abstract-sql-rules-to-sql.ts +0 -1730
  10. package/src/abstract-sql-schema-optimizer.ts +0 -172
  11. package/src/referenced-fields.ts +0 -600
  12. package/test/abstract-sql/aggregate-json.ts +0 -49
  13. package/test/abstract-sql/aggregate.ts +0 -161
  14. package/test/abstract-sql/and-or-boolean-optimisations.ts +0 -115
  15. package/test/abstract-sql/case-when-else.ts +0 -48
  16. package/test/abstract-sql/cast.ts +0 -25
  17. package/test/abstract-sql/coalesce.ts +0 -24
  18. package/test/abstract-sql/comparisons.ts +0 -360
  19. package/test/abstract-sql/dates.ts +0 -512
  20. package/test/abstract-sql/duration.ts +0 -56
  21. package/test/abstract-sql/empty-query-optimisations.ts +0 -54
  22. package/test/abstract-sql/functions-wrapper.ts +0 -70
  23. package/test/abstract-sql/get-referenced-fields.ts +0 -674
  24. package/test/abstract-sql/get-rule-referenced-fields.ts +0 -345
  25. package/test/abstract-sql/insert-query.ts +0 -22
  26. package/test/abstract-sql/is-distinct.ts +0 -102
  27. package/test/abstract-sql/joins.ts +0 -84
  28. package/test/abstract-sql/json.ts +0 -58
  29. package/test/abstract-sql/math.ts +0 -467
  30. package/test/abstract-sql/nested-in-optimisations.ts +0 -200
  31. package/test/abstract-sql/not-not-optimisations.ts +0 -15
  32. package/test/abstract-sql/schema-checks.ts +0 -168
  33. package/test/abstract-sql/schema-informative-reference.ts +0 -420
  34. package/test/abstract-sql/schema-rule-optimization.ts +0 -120
  35. package/test/abstract-sql/schema-rule-to-check.ts +0 -393
  36. package/test/abstract-sql/schema-views.ts +0 -73
  37. package/test/abstract-sql/test.ts +0 -192
  38. package/test/abstract-sql/text.ts +0 -168
  39. package/test/model.sbvr +0 -60
  40. package/test/odata/expand.ts +0 -674
  41. package/test/odata/fields.ts +0 -59
  42. package/test/odata/filterby.ts +0 -1517
  43. package/test/odata/orderby.ts +0 -96
  44. package/test/odata/paging.ts +0 -48
  45. package/test/odata/resource-parsing.ts +0 -568
  46. package/test/odata/select.ts +0 -119
  47. package/test/odata/stress.ts +0 -93
  48. package/test/odata/test.ts +0 -297
  49. package/test/sbvr/pilots.ts +0 -1097
  50. package/test/sbvr/reference-type.ts +0 -211
  51. package/test/sbvr/test.ts +0 -101
  52. package/tsconfig.build.json +0 -6
  53. package/tsconfig.json +0 -25
@@ -1,96 +0,0 @@
1
- import test from './test.js';
2
- import { pilotFields } from './fields.js';
3
- const pilotFieldsStr = pilotFields.join(', ');
4
-
5
- test('/pilot?$orderby=name', (result, sqlEquals) => {
6
- it('should order by name desc', () => {
7
- sqlEquals(
8
- result,
9
- `\
10
- SELECT ${pilotFieldsStr}
11
- FROM "pilot"
12
- ORDER BY "pilot"."name" DESC`,
13
- );
14
- });
15
- });
16
-
17
- test('/pilot?$orderby=name,age', (result, sqlEquals) => {
18
- it('should order by name desc, age desc', () => {
19
- sqlEquals(
20
- result,
21
- `\
22
- SELECT ${pilotFieldsStr}
23
- FROM "pilot"
24
- ORDER BY "pilot"."name" DESC,
25
- "pilot"."age" DESC`,
26
- );
27
- });
28
- });
29
-
30
- test('/pilot?$orderby=name desc', (result, sqlEquals) => {
31
- it('should order by name desc', () => {
32
- sqlEquals(
33
- result,
34
- `\
35
- SELECT ${pilotFieldsStr}
36
- FROM "pilot"
37
- ORDER BY "pilot"."name" DESC`,
38
- );
39
- });
40
- });
41
-
42
- test('/pilot?$orderby=name asc', (result, sqlEquals) => {
43
- it('should order by name asc', () => {
44
- sqlEquals(
45
- result,
46
- `\
47
- SELECT ${pilotFieldsStr}
48
- FROM "pilot"
49
- ORDER BY "pilot"."name" ASC`,
50
- );
51
- });
52
- });
53
-
54
- test('/pilot?$orderby=name asc,age desc', (result, sqlEquals) => {
55
- it('should order by name desc, age desc', () => {
56
- sqlEquals(
57
- result,
58
- `\
59
- SELECT ${pilotFieldsStr}
60
- FROM "pilot"
61
- ORDER BY "pilot"."name" ASC,
62
- "pilot"."age" DESC`,
63
- );
64
- });
65
- });
66
-
67
- test('/pilot?$orderby=licence/id asc', (result, sqlEquals) => {
68
- it('should order by licence/id asc', () => {
69
- sqlEquals(
70
- result,
71
- `\
72
- SELECT ${pilotFieldsStr}
73
- FROM "pilot"
74
- LEFT JOIN "licence" AS "pilot.licence" ON "pilot"."licence" = "pilot.licence"."id"
75
- ORDER BY "pilot.licence"."id" ASC`,
76
- );
77
- });
78
- });
79
-
80
- test('/pilot?$orderby=can_fly__plane/plane/id asc', (result, sqlEquals) => {
81
- it('should order by pilot__can_fly__plane/plane/id asc', () => {
82
- sqlEquals(
83
- result,
84
- `\
85
- SELECT ${pilotFieldsStr}
86
- FROM "pilot"
87
- LEFT JOIN "pilot-can fly-plane" AS "pilot.pilot-can fly-plane" ON "pilot"."id" = "pilot.pilot-can fly-plane"."pilot"
88
- LEFT JOIN "plane" AS "pilot.pilot-can fly-plane.plane" ON "pilot.pilot-can fly-plane"."can fly-plane" = "pilot.pilot-can fly-plane.plane"."id"
89
- ORDER BY "pilot.pilot-can fly-plane.plane"."id" ASC`,
90
- );
91
- });
92
- });
93
-
94
- test.fail('/pilot?$orderby=favourite_colour/red', () => {
95
- it("should order by how red the pilot's favourite colour is");
96
- });
@@ -1,48 +0,0 @@
1
- import test from './test.js';
2
- import { pilotFields } from './fields.js';
3
- const pilotFieldsStr = pilotFields.join(', ');
4
-
5
- test('/pilot?$top=5', 'GET', [['Bind', 0]], (result, sqlEquals) => {
6
- it('should select from pilot limited by 5', () => {
7
- sqlEquals(
8
- result,
9
- `\
10
- SELECT ${pilotFieldsStr}
11
- FROM "pilot"
12
- LIMIT ?`,
13
- );
14
- });
15
- });
16
-
17
- test('/pilot?$skip=100', 'GET', [['Bind', 0]], (result, sqlEquals) => {
18
- it('should select from pilot offset by 100', () => {
19
- sqlEquals(
20
- result,
21
- `\
22
- SELECT ${pilotFieldsStr}
23
- FROM "pilot"
24
- OFFSET ?`,
25
- );
26
- });
27
- });
28
-
29
- test(
30
- '/pilot?$top=5&$skip=100',
31
- 'GET',
32
- [
33
- ['Bind', 0],
34
- ['Bind', 1],
35
- ],
36
- (result, sqlEquals) => {
37
- it('should select from pilot limited by 5 and offset by 100', () => {
38
- sqlEquals(
39
- result,
40
- `\
41
- SELECT ${pilotFieldsStr}
42
- FROM "pilot"
43
- LIMIT ?
44
- OFFSET ?`,
45
- );
46
- });
47
- },
48
- );
@@ -1,568 +0,0 @@
1
- import { expect } from 'chai';
2
- import type { ExpectationSuccessFn } from './test.js';
3
- import test from './test.js';
4
- import ODataParser from '@balena/odata-parser';
5
- import {
6
- pilotFields,
7
- teamFields,
8
- aliasFields,
9
- aliasPlaneFields,
10
- aliasPilotLicenceFields,
11
- aliasLicenceFields,
12
- } from './fields.js';
13
- import type { SqlResult } from '../../out/abstract-sql-compiler.js';
14
- const aliasPilotFields = aliasFields(
15
- 'plane.pilot-can fly-plane.pilot',
16
- pilotFields,
17
- ).join(', ');
18
- const aliasPlaneFieldsStr = aliasPlaneFields.join(', ');
19
- const aliasPilotLicenceFieldsStr = aliasPilotLicenceFields.join(', ');
20
- const aliasLicenceFieldsStr = aliasLicenceFields.join(', ');
21
- const pilotFieldsStr = pilotFields.join(', ');
22
- const teamFieldsStr = teamFields.join(', ');
23
-
24
- test('/pilot', (result, sqlEquals) => {
25
- it('should select from pilot', () => {
26
- sqlEquals(
27
- result,
28
- `\
29
- SELECT ${pilotFieldsStr}
30
- FROM "pilot"`,
31
- );
32
- });
33
- });
34
-
35
- test('/pilot(1)', 'GET', [['Bind', 0]], (result, sqlEquals) => {
36
- it('should select from pilot with id', () => {
37
- sqlEquals(
38
- result,
39
- `\
40
- SELECT ${pilotFieldsStr}
41
- FROM "pilot"
42
- WHERE "pilot"."id" IS NOT NULL AND "pilot"."id" = ?`,
43
- );
44
- });
45
- });
46
-
47
- test("/pilot('TextKey')", 'GET', [['Bind', 0]], (result, sqlEquals) => {
48
- it('should select from pilot with id', () => {
49
- sqlEquals(
50
- result,
51
- `\
52
- SELECT ${pilotFieldsStr}
53
- FROM "pilot"
54
- WHERE "pilot"."id" IS NOT NULL AND "pilot"."id" = ?`,
55
- );
56
- });
57
- });
58
-
59
- test('/pilot(1)/licence', 'GET', [['Bind', 0]], (result, sqlEquals) => {
60
- it('should select from the licence of pilot with id', () => {
61
- sqlEquals(
62
- result,
63
- `\
64
- SELECT ${aliasLicenceFieldsStr}
65
- FROM "pilot",
66
- "licence" AS "pilot.licence"
67
- WHERE "pilot"."licence" = "pilot.licence"."id"
68
- AND "pilot"."id" IS NOT NULL AND "pilot"."id" = ?`,
69
- );
70
- });
71
- });
72
-
73
- test('/licence(1)/is_of__pilot', 'GET', [['Bind', 0]], (result, sqlEquals) => {
74
- it('should select from the pilots of licence with id', () => {
75
- sqlEquals(
76
- result,
77
- `\
78
- SELECT ${aliasPilotLicenceFieldsStr}
79
- FROM "licence",
80
- "pilot" AS "licence.is of-pilot"
81
- WHERE "licence"."id" = "licence.is of-pilot"."licence"
82
- AND "licence"."id" IS NOT NULL AND "licence"."id" = ?`,
83
- );
84
- });
85
- });
86
-
87
- test(
88
- '/pilot(1)/can_fly__plane/plane',
89
- 'GET',
90
- [['Bind', 0]],
91
- (result, sqlEquals) => {
92
- it('should select from the plane of pilot with id', () => {
93
- sqlEquals(
94
- result,
95
- `\
96
- SELECT ${aliasPlaneFieldsStr}
97
- FROM "pilot",
98
- "pilot-can fly-plane" AS "pilot.pilot-can fly-plane",
99
- "plane" AS "pilot.pilot-can fly-plane.plane"
100
- WHERE "pilot.pilot-can fly-plane"."can fly-plane" = "pilot.pilot-can fly-plane.plane"."id"
101
- AND "pilot"."id" = "pilot.pilot-can fly-plane"."pilot"
102
- AND "pilot"."id" IS NOT NULL AND "pilot"."id" = ?`,
103
- );
104
- });
105
- },
106
- );
107
-
108
- test(
109
- '/plane(1)/can_be_flown_by__pilot/pilot',
110
- 'GET',
111
- [['Bind', 0]],
112
- (result, sqlEquals) => {
113
- it('should select from the pilots of plane with id', () => {
114
- sqlEquals(
115
- result,
116
- `\
117
- SELECT ${aliasPilotFields}
118
- FROM "plane",
119
- "pilot-can fly-plane" AS "plane.pilot-can fly-plane",
120
- "pilot" AS "plane.pilot-can fly-plane.pilot"
121
- WHERE "plane.pilot-can fly-plane"."pilot" = "plane.pilot-can fly-plane.pilot"."id"
122
- AND "plane"."id" = "plane.pilot-can fly-plane"."can fly-plane"
123
- AND "plane"."id" IS NOT NULL AND "plane"."id" = ?`,
124
- );
125
- });
126
- },
127
- );
128
-
129
- test('/pilot(1)', 'DELETE', [['Bind', 0]], (result, sqlEquals) => {
130
- it('should delete the pilot with id 1', () => {
131
- sqlEquals(
132
- result,
133
- `\
134
- DELETE FROM "pilot"
135
- WHERE "pilot"."id" IS NOT NULL AND "pilot"."id" = ?`,
136
- );
137
- });
138
- });
139
-
140
- test(
141
- '/pilot(1)',
142
- 'PUT',
143
- [
144
- [
145
- ['Bind', ['pilot', 'id']],
146
- ['Bind', 0],
147
- ],
148
- [
149
- ['Bind', ['pilot', 'id']],
150
- ['Bind', 0],
151
- ],
152
- ],
153
- (result, sqlEquals) => {
154
- it('should insert/update the pilot with id 1', () => {
155
- sqlEquals(
156
- (result as SqlResult[])[0],
157
- `\
158
- INSERT INTO "pilot" ("id")
159
- SELECT "$insert"."id"
160
- FROM (
161
- SELECT CAST(NULL AS TIMESTAMPTZ) AS "created at", CAST(NULL AS TIMESTAMPTZ) AS "modified at", CAST(? AS INTEGER) AS "id", CAST(NULL AS INTEGER) AS "person", CAST(NULL AS BOOLEAN) AS "is experienced", CAST(NULL AS VARCHAR(255)) AS "name", CAST(NULL AS INTEGER) AS "age", CAST(NULL AS INTEGER) AS "favourite colour", CAST(NULL AS INTEGER) AS "is on-team", CAST(NULL AS INTEGER) AS "licence", CAST(NULL AS TIMESTAMPTZ) AS "hire date", CAST(NULL AS INTEGER) AS "was trained by-pilot"
162
- ) AS "$insert"
163
- WHERE EXISTS (
164
- SELECT 1
165
- FROM (
166
- SELECT "$insert".*
167
- ) AS "pilot"
168
- WHERE "pilot"."id" IS NOT NULL AND "pilot"."id" = ?
169
- )`,
170
- );
171
- sqlEquals(
172
- (result as SqlResult[])[1],
173
- `\
174
- UPDATE "pilot"
175
- SET "created at" = DEFAULT,
176
- "modified at" = DEFAULT,
177
- "id" = ?,
178
- "person" = DEFAULT,
179
- "is experienced" = DEFAULT,
180
- "name" = DEFAULT,
181
- "age" = DEFAULT,
182
- "favourite colour" = DEFAULT,
183
- "is on-team" = DEFAULT,
184
- "licence" = DEFAULT,
185
- "hire date" = DEFAULT,
186
- "was trained by-pilot" = DEFAULT
187
- WHERE "pilot"."id" IS NOT NULL AND "pilot"."id" = ?`,
188
- );
189
- });
190
- },
191
- );
192
- test(
193
- '/pilot',
194
- 'POST',
195
- [['Bind', ['pilot', 'name']]],
196
- { name: 'Peter' },
197
- (result, sqlEquals) => {
198
- it('should insert/update the pilot with id 1', () => {
199
- sqlEquals(
200
- result,
201
- `\
202
- INSERT INTO "pilot" ("name")
203
- VALUES (?)`,
204
- );
205
- });
206
- },
207
- );
208
- test('/pilot', 'POST', (result, sqlEquals) => {
209
- it('should insert a pilot with default values', () => {
210
- sqlEquals(
211
- result,
212
- `\
213
- INSERT INTO "pilot" DEFAULT VALUES`,
214
- );
215
- });
216
- });
217
-
218
- (function () {
219
- const bindings = [
220
- ['Bind', ['pilot', 'is_experienced']],
221
- ['Bind', 0],
222
- ] as const;
223
- const testFunc: ExpectationSuccessFn = (result, sqlEquals) => {
224
- it('should update the pilot with id 1', () => {
225
- sqlEquals(
226
- result,
227
- `\
228
- UPDATE "pilot"
229
- SET "is experienced" = ?
230
- WHERE "pilot"."id" IS NOT NULL AND "pilot"."id" = ?`,
231
- );
232
- });
233
- };
234
- test('/pilot(1)', 'PATCH', bindings, { is_experienced: true }, testFunc);
235
- test('/pilot(1)', 'MERGE', bindings, { is_experienced: true }, testFunc);
236
- })();
237
-
238
- test(
239
- '/pilot__can_fly__plane(1)',
240
- 'DELETE',
241
- [['Bind', 0]],
242
- (result, sqlEquals) => {
243
- it('should delete the pilot with id 1', () => {
244
- sqlEquals(
245
- result,
246
- `\
247
- DELETE FROM "pilot-can fly-plane"
248
- WHERE "pilot-can fly-plane"."id" IS NOT NULL AND "pilot-can fly-plane"."id" = ?`,
249
- );
250
- });
251
- },
252
- );
253
-
254
- test(
255
- '/pilot__can_fly__plane(1)',
256
- 'PUT',
257
- [
258
- [
259
- ['Bind', ['pilot-can fly-plane', 'id']],
260
- ['Bind', 0],
261
- ],
262
- [
263
- ['Bind', ['pilot-can fly-plane', 'id']],
264
- ['Bind', 0],
265
- ],
266
- ],
267
- (result, sqlEquals) => {
268
- it('should insert/update the pilot-can fly-plane with id 1', () => {
269
- sqlEquals(
270
- (result as SqlResult[])[0],
271
- `\
272
- INSERT INTO "pilot-can fly-plane" ("id")
273
- SELECT "$insert"."id"
274
- FROM (
275
- SELECT CAST(NULL AS TIMESTAMPTZ) AS "created at", CAST(NULL AS TIMESTAMPTZ) AS "modified at", CAST(NULL AS INTEGER) AS "pilot", CAST(NULL AS INTEGER) AS "can fly-plane", CAST(? AS INTEGER) AS "id"
276
- ) AS "$insert"
277
- WHERE EXISTS (
278
- SELECT 1
279
- FROM (
280
- SELECT "$insert".*
281
- ) AS "pilot-can fly-plane"
282
- WHERE "pilot-can fly-plane"."id" IS NOT NULL AND "pilot-can fly-plane"."id" = ?
283
- )`,
284
- );
285
- sqlEquals(
286
- (result as SqlResult[])[1],
287
- `\
288
- UPDATE "pilot-can fly-plane"
289
- SET "created at" = DEFAULT,
290
- "modified at" = DEFAULT,
291
- "pilot" = DEFAULT,
292
- "can fly-plane" = DEFAULT,
293
- "id" = ?
294
- WHERE "pilot-can fly-plane"."id" IS NOT NULL AND "pilot-can fly-plane"."id" = ?`,
295
- );
296
- });
297
- },
298
- );
299
- test(
300
- '/pilot__can_fly__plane',
301
- 'POST',
302
- [
303
- ['Bind', ['pilot-can fly-plane', 'pilot']],
304
- ['Bind', ['pilot-can fly-plane', 'can_fly__plane']],
305
- ],
306
- { pilot: 2, can_fly__plane: 3 },
307
- (result, sqlEquals) => {
308
- it('should insert/update the pilot-can fly-plane with id 1', () => {
309
- sqlEquals(
310
- result,
311
- `\
312
- INSERT INTO "pilot-can fly-plane" ("pilot", "can fly-plane")
313
- VALUES (?, ?)`,
314
- );
315
- });
316
- },
317
- );
318
- test('/pilot__can_fly__plane', 'POST', (result, sqlEquals) => {
319
- it('should insert a "pilot-can fly-plane" with default values', () => {
320
- sqlEquals(
321
- result,
322
- `\
323
- INSERT INTO "pilot-can fly-plane" DEFAULT VALUES`,
324
- );
325
- });
326
- });
327
-
328
- (function () {
329
- const bindings = [
330
- ['Bind', ['pilot-can fly-plane', 'pilot']],
331
- ['Bind', 0],
332
- ] as const;
333
- const testFunc: ExpectationSuccessFn = (result, sqlEquals) => {
334
- it('should update the pilot with id 1', () => {
335
- sqlEquals(
336
- result,
337
- `\
338
- UPDATE "pilot-can fly-plane"
339
- SET "pilot" = ?
340
- WHERE "pilot-can fly-plane"."id" IS NOT NULL AND "pilot-can fly-plane"."id" = ?`,
341
- );
342
- });
343
- };
344
- test('/pilot__can_fly__plane(1)', 'PATCH', bindings, { pilot: 1 }, testFunc);
345
- test('/pilot__can_fly__plane(1)', 'MERGE', bindings, { pilot: 1 }, testFunc);
346
- })();
347
-
348
- test('/pilot(1)/$links/licence', 'GET', [['Bind', 0]], (result, sqlEquals) => {
349
- it('should select the list of licence ids, for generating the links', () => {
350
- sqlEquals(
351
- result,
352
- `\
353
- SELECT "pilot"."licence" AS "licence"
354
- FROM "pilot"
355
- WHERE "pilot"."id" IS NOT NULL AND "pilot"."id" = ?`,
356
- );
357
- });
358
- });
359
-
360
- test(
361
- '/pilot(1)/can_fly__plane/$links/plane',
362
- 'GET',
363
- [['Bind', 0]],
364
- (result, sqlEquals) => {
365
- it('should select the list of plane ids, for generating the links', () => {
366
- sqlEquals(
367
- result,
368
- `\
369
- SELECT "pilot.pilot-can fly-plane"."can fly-plane" AS "plane"
370
- FROM "pilot",
371
- "pilot-can fly-plane" AS "pilot.pilot-can fly-plane"
372
- WHERE "pilot"."id" = "pilot.pilot-can fly-plane"."pilot"
373
- AND "pilot"."id" IS NOT NULL AND "pilot"."id" = ?`,
374
- );
375
- });
376
- },
377
- );
378
-
379
- test.fail('/pilot(1)/favourite_colour/red', () => {
380
- it("should select the red component of the pilot's favourite colour");
381
- });
382
-
383
- test.fail('/method(1)/child?foo=bar', () => {
384
- it('should do something..');
385
- });
386
-
387
- test("/team('purple')", 'GET', [['Bind', 0]], (result, sqlEquals) => {
388
- it('should select the team with the "favourite colour" id of "purple"', () => {
389
- sqlEquals(
390
- result,
391
- `\
392
- SELECT ${teamFieldsStr}
393
- FROM "team"
394
- WHERE "team"."favourite colour" IS NOT NULL AND "team"."favourite colour" = ?`,
395
- );
396
- });
397
- });
398
-
399
- test(
400
- '/team',
401
- 'POST',
402
- [['Bind', ['team', 'favourite_colour']]],
403
- { favourite_colour: 'purple' },
404
- (result, sqlEquals) => {
405
- it('should insert a team', () => {
406
- sqlEquals(
407
- result,
408
- `\
409
- INSERT INTO "team" ("favourite colour")
410
- VALUES (?)`,
411
- );
412
- });
413
- },
414
- );
415
-
416
- test.fail('/pilot/$count/$count', (result) => {
417
- it('should fail because it is invalid', () => {
418
- expect(result).to.be.instanceOf(ODataParser.SyntaxError);
419
- });
420
- });
421
-
422
- test('/pilot/$count', (result, sqlEquals) => {
423
- it('should select count(*) from pilot', () => {
424
- sqlEquals(
425
- result,
426
- `\
427
- SELECT COUNT(*) AS "$count"
428
- FROM "pilot"`,
429
- );
430
- });
431
- });
432
-
433
- test.fail('/pilot(5)/$count', (result) => {
434
- it('should fail because it is invalid', () => {
435
- expect(result).to.be.instanceOf(ODataParser.SyntaxError);
436
- });
437
- });
438
-
439
- test.fail('/pilot?$filter=id eq 5/$count', (result) => {
440
- it('should fail because it is invalid', () => {
441
- expect(result).to.be.instanceOf(ODataParser.SyntaxError);
442
- });
443
- });
444
-
445
- test(
446
- '/pilot/$count?$filter=id gt 5',
447
- 'GET',
448
- [['Bind', 0]],
449
- (result, sqlEquals) => {
450
- it('should select count(*) from pilot where pilot/id > 5 ', () => {
451
- sqlEquals(
452
- result,
453
- `\
454
- SELECT COUNT(*) AS "$count"
455
- FROM "pilot"
456
- WHERE "pilot"."id" > ?`,
457
- );
458
- });
459
- },
460
- );
461
-
462
- test(
463
- '/pilot/$count?$filter=id eq 5 or id eq 10',
464
- 'GET',
465
- [
466
- ['Bind', 0],
467
- ['Bind', 1],
468
- ],
469
- (result, sqlEquals) => {
470
- it('should select count(*) from pilot where id in (5,10)', () => {
471
- sqlEquals(
472
- result,
473
- `\
474
- SELECT COUNT(*) AS "$count"
475
- FROM "pilot"
476
- WHERE ("pilot"."id" IS NOT NULL AND "pilot"."id" = ?
477
- OR "pilot"."id" IS NOT NULL AND "pilot"."id" = ?)`,
478
- );
479
- });
480
- },
481
- );
482
-
483
- test(
484
- '/pilot/$count?$filter=id eq 5 or id eq null',
485
- 'GET',
486
- [['Bind', 0]],
487
- (result, sqlEquals) => {
488
- it('should select count(*) from pilot where id in (5,10)', () => {
489
- sqlEquals(
490
- result,
491
- `\
492
- SELECT COUNT(*) AS "$count"
493
- FROM "pilot"
494
- WHERE ("pilot"."id" IS NOT NULL AND "pilot"."id" = ?
495
- OR "pilot"."id" IS NULL)`,
496
- );
497
- });
498
- },
499
- );
500
-
501
- test('/pilot(5)/licence/$count', 'GET', [['Bind', 0]], (result, sqlEquals) => {
502
- it('should select count(*) the licence from pilot where pilot/id', () => {
503
- sqlEquals(
504
- result,
505
- `\
506
- SELECT COUNT(*) AS "$count"
507
- FROM "pilot",
508
- "licence" AS "pilot.licence"
509
- WHERE "pilot"."licence" = "pilot.licence"."id"
510
- AND "pilot"."id" IS NOT NULL AND "pilot"."id" = ?`,
511
- );
512
- });
513
- });
514
-
515
- test('/pilot/$count?$orderby=id asc', (result, sqlEquals) => {
516
- it('should select count(*) from pilot and ignore orderby', () => {
517
- sqlEquals(
518
- result,
519
- `\
520
- SELECT COUNT(*) AS "$count"
521
- FROM "pilot"`,
522
- );
523
- });
524
- });
525
-
526
- test('/pilot/$count?$skip=5', (result, sqlEquals) => {
527
- it('should select count(*) from pilot and ignore skip', () => {
528
- sqlEquals(
529
- result,
530
- `\
531
- SELECT COUNT(*) AS "$count"
532
- FROM "pilot"`,
533
- );
534
- });
535
- });
536
-
537
- test('/pilot/$count?$top=5', (result, sqlEquals) => {
538
- it('should select count(*) from pilot and ignore top', () => {
539
- sqlEquals(
540
- result,
541
- `\
542
- SELECT COUNT(*) AS "$count"
543
- FROM "pilot"`,
544
- );
545
- });
546
- });
547
-
548
- test('/pilot/$count?$top=5&$skip=5', (result, sqlEquals) => {
549
- it('should select count(*) from pilot and ignore top and skip', () => {
550
- sqlEquals(
551
- result,
552
- `\
553
- SELECT COUNT(*) AS "$count"
554
- FROM "pilot"`,
555
- );
556
- });
557
- });
558
-
559
- test('/pilot/$count?$select=id', (result, sqlEquals) => {
560
- it('should select count(*) from pilot and ignore select', () => {
561
- sqlEquals(
562
- result,
563
- `\
564
- SELECT COUNT(*) AS "$count"
565
- FROM "pilot"`,
566
- );
567
- });
568
- });