@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
package/test/odata/expand.ts
DELETED
@@ -1,674 +0,0 @@
|
|
1
|
-
import type { ExpectationFailFn, ExpectationSuccessFn } from './test.js';
|
2
|
-
import test from './test.js';
|
3
|
-
import {
|
4
|
-
pilotFields,
|
5
|
-
aliasFields,
|
6
|
-
aliasLicenceFields,
|
7
|
-
aliasPlaneFields,
|
8
|
-
aliasPilotCanFlyPlaneFields,
|
9
|
-
} from './fields.js';
|
10
|
-
import _ from 'lodash';
|
11
|
-
|
12
|
-
type TestFn = (
|
13
|
-
aggFunc: (field: string) => string,
|
14
|
-
fields?: string,
|
15
|
-
) => ExpectationSuccessFn;
|
16
|
-
|
17
|
-
const postgresAgg = (field: string) =>
|
18
|
-
'COALESCE(JSON_AGG(' + field + "), '[]')";
|
19
|
-
const mysqlAgg = (field: string) =>
|
20
|
-
"'[' || group_concat(" + field + ", ',') || ']'";
|
21
|
-
const websqlAgg = mysqlAgg;
|
22
|
-
|
23
|
-
(function () {
|
24
|
-
const remainingPilotFields = _.reject(
|
25
|
-
pilotFields,
|
26
|
-
(field) => field === '"pilot"."licence"',
|
27
|
-
).join(', ');
|
28
|
-
const testFunc: TestFn = (aggFunc, fields) => (result, sqlEquals) => {
|
29
|
-
it('should select from pilot.*, aggregated licence', () => {
|
30
|
-
sqlEquals?.(
|
31
|
-
result,
|
32
|
-
`\
|
33
|
-
SELECT (
|
34
|
-
SELECT ${aggFunc('"pilot.licence".*')} AS "licence"
|
35
|
-
FROM (
|
36
|
-
SELECT ${fields}
|
37
|
-
FROM "licence" AS "pilot.licence"
|
38
|
-
WHERE "pilot"."licence" = "pilot.licence"."id"
|
39
|
-
) AS "pilot.licence"
|
40
|
-
) AS "licence", ${remainingPilotFields}
|
41
|
-
FROM "pilot"`,
|
42
|
-
);
|
43
|
-
});
|
44
|
-
};
|
45
|
-
const url = '/pilot?$expand=licence';
|
46
|
-
const urlCount = '/pilot?$expand=licence/$count';
|
47
|
-
test.postgres(url, testFunc(postgresAgg, aliasLicenceFields.join(', ')));
|
48
|
-
test.postgres(urlCount, testFunc(postgresAgg, 'COUNT(*) AS "$count"'));
|
49
|
-
test.mysql.fail(
|
50
|
-
url,
|
51
|
-
testFunc(
|
52
|
-
mysqlAgg,
|
53
|
-
aliasLicenceFields.join(', '),
|
54
|
-
) as any as ExpectationFailFn,
|
55
|
-
);
|
56
|
-
test.mysql.fail(
|
57
|
-
urlCount,
|
58
|
-
testFunc(mysqlAgg, 'COUNT(*) AS "$count"') as any as ExpectationFailFn,
|
59
|
-
);
|
60
|
-
test.websql.fail(
|
61
|
-
url,
|
62
|
-
testFunc(
|
63
|
-
websqlAgg,
|
64
|
-
aliasLicenceFields.join(', '),
|
65
|
-
) as any as ExpectationFailFn,
|
66
|
-
);
|
67
|
-
test.websql.fail(
|
68
|
-
urlCount,
|
69
|
-
testFunc(websqlAgg, 'COUNT(*) AS "$count"') as any as ExpectationFailFn,
|
70
|
-
);
|
71
|
-
})();
|
72
|
-
|
73
|
-
(function () {
|
74
|
-
const remainingAliasPilotCanFlyFields = _.reject(
|
75
|
-
aliasPilotCanFlyPlaneFields,
|
76
|
-
(field) => field === '"pilot.pilot-can fly-plane"."can fly-plane"',
|
77
|
-
).join(', ');
|
78
|
-
const testFunc: TestFn = (aggFunc) => (result, sqlEquals) => {
|
79
|
-
it('should select from pilot.*, aggregated(pilot-can fly-plane, aggregated plane)', () => {
|
80
|
-
sqlEquals?.(
|
81
|
-
result,
|
82
|
-
`\
|
83
|
-
SELECT (
|
84
|
-
SELECT ${aggFunc('"pilot.pilot-can fly-plane".*')} AS "can_fly__plane"
|
85
|
-
FROM (
|
86
|
-
SELECT (
|
87
|
-
SELECT ${aggFunc('"pilot.pilot-can fly-plane.plane".*')} AS "plane"
|
88
|
-
FROM (
|
89
|
-
SELECT ${aliasPlaneFields.join(', ')}
|
90
|
-
FROM "plane" AS "pilot.pilot-can fly-plane.plane"
|
91
|
-
WHERE "pilot.pilot-can fly-plane"."can fly-plane" = "pilot.pilot-can fly-plane.plane"."id"
|
92
|
-
) AS "pilot.pilot-can fly-plane.plane"
|
93
|
-
) AS "plane", ${remainingAliasPilotCanFlyFields}
|
94
|
-
FROM "pilot-can fly-plane" AS "pilot.pilot-can fly-plane"
|
95
|
-
WHERE "pilot"."id" = "pilot.pilot-can fly-plane"."pilot"
|
96
|
-
) AS "pilot.pilot-can fly-plane"
|
97
|
-
) AS "can_fly__plane", ${pilotFields.join(', ')}
|
98
|
-
FROM "pilot"`,
|
99
|
-
);
|
100
|
-
});
|
101
|
-
};
|
102
|
-
|
103
|
-
for (const url of [
|
104
|
-
'/pilot?$expand=can_fly__plane/plane',
|
105
|
-
'/pilot?$expand=can_fly__plane($expand=plane)',
|
106
|
-
]) {
|
107
|
-
test.postgres(url, testFunc(postgresAgg));
|
108
|
-
test.mysql.fail(url, testFunc(mysqlAgg) as any as ExpectationFailFn);
|
109
|
-
test.websql.fail(url, testFunc(websqlAgg) as any as ExpectationFailFn);
|
110
|
-
}
|
111
|
-
})();
|
112
|
-
|
113
|
-
(function () {
|
114
|
-
const remainingAliasPilotCanFlyFields = _.reject(
|
115
|
-
aliasPilotCanFlyPlaneFields,
|
116
|
-
(field) => field === '"pilot.pilot-can fly-plane"."can fly-plane"',
|
117
|
-
).join(', ');
|
118
|
-
const remainingPilotFields = _.reject(
|
119
|
-
pilotFields,
|
120
|
-
(field) => field === '"pilot"."licence"',
|
121
|
-
).join(', ');
|
122
|
-
const testFunc: TestFn = (aggFunc) => (result, sqlEquals) => {
|
123
|
-
it('should select from pilot.*, aggregated(pilot-can fly-plane, aggregated plane), aggregated licence', () => {
|
124
|
-
sqlEquals?.(
|
125
|
-
result,
|
126
|
-
`\
|
127
|
-
SELECT (
|
128
|
-
SELECT ${aggFunc('"pilot.pilot-can fly-plane".*')} AS "can_fly__plane"
|
129
|
-
FROM (
|
130
|
-
SELECT (
|
131
|
-
SELECT ${aggFunc('"pilot.pilot-can fly-plane.plane".*')} AS "plane"
|
132
|
-
FROM (
|
133
|
-
SELECT ${aliasPlaneFields.join(', ')}
|
134
|
-
FROM "plane" AS "pilot.pilot-can fly-plane.plane"
|
135
|
-
WHERE "pilot.pilot-can fly-plane"."can fly-plane" = "pilot.pilot-can fly-plane.plane"."id"
|
136
|
-
) AS "pilot.pilot-can fly-plane.plane"
|
137
|
-
) AS "plane", ${remainingAliasPilotCanFlyFields}
|
138
|
-
FROM "pilot-can fly-plane" AS "pilot.pilot-can fly-plane"
|
139
|
-
WHERE "pilot"."id" = "pilot.pilot-can fly-plane"."pilot"
|
140
|
-
) AS "pilot.pilot-can fly-plane"
|
141
|
-
) AS "can_fly__plane", (
|
142
|
-
SELECT ${aggFunc('"pilot.licence".*')} AS "licence"
|
143
|
-
FROM (
|
144
|
-
SELECT ${aliasLicenceFields.join(', ')}
|
145
|
-
FROM "licence" AS "pilot.licence"
|
146
|
-
WHERE "pilot"."licence" = "pilot.licence"."id"
|
147
|
-
) AS "pilot.licence"
|
148
|
-
) AS "licence", ${remainingPilotFields}
|
149
|
-
FROM "pilot"`,
|
150
|
-
);
|
151
|
-
});
|
152
|
-
};
|
153
|
-
|
154
|
-
for (const url of [
|
155
|
-
'/pilot?$expand=can_fly__plane/plane,licence',
|
156
|
-
'/pilot?$expand=can_fly__plane($expand=plane),licence',
|
157
|
-
]) {
|
158
|
-
test.postgres(url, testFunc(postgresAgg));
|
159
|
-
test.mysql.fail(url, testFunc(mysqlAgg) as any as ExpectationFailFn);
|
160
|
-
test.websql.fail(url, testFunc(websqlAgg) as any as ExpectationFailFn);
|
161
|
-
}
|
162
|
-
})();
|
163
|
-
|
164
|
-
(function () {
|
165
|
-
const testFunc: TestFn = (aggFunc) => (result, sqlEquals) => {
|
166
|
-
it('should select from pilot.*, aggregated(pilot-can fly-plane, aggregated plane), aggregated licence', () => {
|
167
|
-
sqlEquals?.(
|
168
|
-
result,
|
169
|
-
`\
|
170
|
-
SELECT (
|
171
|
-
SELECT ${aggFunc('"pilot.licence".*')} AS "licence"
|
172
|
-
FROM (
|
173
|
-
SELECT ${aliasLicenceFields.join(', ')}
|
174
|
-
FROM "licence" AS "pilot.licence"
|
175
|
-
WHERE "pilot"."licence" = "pilot.licence"."id"
|
176
|
-
) AS "pilot.licence"
|
177
|
-
) AS "licence"
|
178
|
-
FROM "pilot"`,
|
179
|
-
);
|
180
|
-
});
|
181
|
-
};
|
182
|
-
const url = '/pilot?$select=licence&$expand=licence';
|
183
|
-
test.postgres(url, testFunc(postgresAgg));
|
184
|
-
test.mysql.fail(url, testFunc(mysqlAgg) as any as ExpectationFailFn);
|
185
|
-
test.websql.fail(url, testFunc(websqlAgg) as any as ExpectationFailFn);
|
186
|
-
})();
|
187
|
-
|
188
|
-
(function () {
|
189
|
-
const remainingAliasPilotCanFlyFields = _.reject(
|
190
|
-
aliasPilotCanFlyPlaneFields,
|
191
|
-
(field) => field === '"pilot.pilot-can fly-plane"."can fly-plane"',
|
192
|
-
).join(', ');
|
193
|
-
const testFunc: TestFn = (aggFunc) => (result, sqlEquals) => {
|
194
|
-
it('should select from pilot.*, aggregated(pilot-can fly-plane, aggregated plane)', () => {
|
195
|
-
sqlEquals?.(
|
196
|
-
result,
|
197
|
-
`\
|
198
|
-
SELECT (
|
199
|
-
SELECT ${aggFunc('"pilot.pilot-can fly-plane".*')} AS "can_fly__plane"
|
200
|
-
FROM (
|
201
|
-
SELECT (
|
202
|
-
SELECT ${aggFunc('"pilot.pilot-can fly-plane.plane".*')} AS "plane"
|
203
|
-
FROM (
|
204
|
-
SELECT ${aliasPlaneFields.join(', ')}
|
205
|
-
FROM "plane" AS "pilot.pilot-can fly-plane.plane"
|
206
|
-
WHERE "pilot.pilot-can fly-plane"."can fly-plane" = "pilot.pilot-can fly-plane.plane"."id"
|
207
|
-
) AS "pilot.pilot-can fly-plane.plane"
|
208
|
-
) AS "plane", ${remainingAliasPilotCanFlyFields}
|
209
|
-
FROM "pilot-can fly-plane" AS "pilot.pilot-can fly-plane"
|
210
|
-
WHERE "pilot"."id" = "pilot.pilot-can fly-plane"."pilot"
|
211
|
-
) AS "pilot.pilot-can fly-plane"
|
212
|
-
) AS "can_fly__plane", "pilot"."id"
|
213
|
-
FROM "pilot"`,
|
214
|
-
);
|
215
|
-
});
|
216
|
-
};
|
217
|
-
|
218
|
-
for (const url of [
|
219
|
-
'/pilot?$select=id&$expand=can_fly__plane/plane',
|
220
|
-
'/pilot?$select=id&$expand=can_fly__plane($expand=plane)',
|
221
|
-
]) {
|
222
|
-
test.postgres(url, testFunc(postgresAgg));
|
223
|
-
test.mysql.fail(url, testFunc(mysqlAgg) as any as ExpectationFailFn);
|
224
|
-
test.websql.fail(url, testFunc(websqlAgg) as any as ExpectationFailFn);
|
225
|
-
}
|
226
|
-
})();
|
227
|
-
|
228
|
-
(function () {
|
229
|
-
const remainingAliasPilotCanFlyFields = _.reject(
|
230
|
-
aliasPilotCanFlyPlaneFields,
|
231
|
-
(field) => field === '"pilot.pilot-can fly-plane"."can fly-plane"',
|
232
|
-
).join(', ');
|
233
|
-
const testFunc: TestFn = (aggFunc) => (result, sqlEquals) => {
|
234
|
-
it('should select from pilot.*, aggregated(pilot-can fly-plane, aggregated plane), aggregated licence', () => {
|
235
|
-
sqlEquals?.(
|
236
|
-
result,
|
237
|
-
`\
|
238
|
-
SELECT (
|
239
|
-
SELECT ${aggFunc('"pilot.pilot-can fly-plane".*')} AS "can_fly__plane"
|
240
|
-
FROM (
|
241
|
-
SELECT (
|
242
|
-
SELECT ${aggFunc('"pilot.pilot-can fly-plane.plane".*')} AS "plane"
|
243
|
-
FROM (
|
244
|
-
SELECT ${aliasPlaneFields.join(', ')}
|
245
|
-
FROM "plane" AS "pilot.pilot-can fly-plane.plane"
|
246
|
-
WHERE "pilot.pilot-can fly-plane"."can fly-plane" = "pilot.pilot-can fly-plane.plane"."id"
|
247
|
-
) AS "pilot.pilot-can fly-plane.plane"
|
248
|
-
) AS "plane", ${remainingAliasPilotCanFlyFields}
|
249
|
-
FROM "pilot-can fly-plane" AS "pilot.pilot-can fly-plane"
|
250
|
-
WHERE "pilot"."id" = "pilot.pilot-can fly-plane"."pilot"
|
251
|
-
) AS "pilot.pilot-can fly-plane"
|
252
|
-
) AS "can_fly__plane", (
|
253
|
-
SELECT ${aggFunc('"pilot.licence".*')} AS "licence"
|
254
|
-
FROM (
|
255
|
-
SELECT ${aliasLicenceFields.join(', ')}
|
256
|
-
FROM "licence" AS "pilot.licence"
|
257
|
-
WHERE "pilot"."licence" = "pilot.licence"."id"
|
258
|
-
) AS "pilot.licence"
|
259
|
-
) AS "licence", "pilot"."id"
|
260
|
-
FROM "pilot"`,
|
261
|
-
);
|
262
|
-
});
|
263
|
-
};
|
264
|
-
|
265
|
-
for (const url of [
|
266
|
-
'/pilot?$select=id,licence&$expand=can_fly__plane/plane,licence',
|
267
|
-
'/pilot?$select=id,licence&$expand=can_fly__plane($expand=plane),licence',
|
268
|
-
]) {
|
269
|
-
test.postgres(url, testFunc(postgresAgg));
|
270
|
-
test.mysql.fail(url, testFunc(mysqlAgg) as any as ExpectationFailFn);
|
271
|
-
test.websql.fail(url, testFunc(websqlAgg) as any as ExpectationFailFn);
|
272
|
-
}
|
273
|
-
})();
|
274
|
-
|
275
|
-
(function () {
|
276
|
-
const testFunc: TestFn = (aggFunc) => (result, sqlEquals) => {
|
277
|
-
it('should select from pilot.*, aggregated(pilot-can fly-plane, aggregated plane)', () => {
|
278
|
-
sqlEquals?.(
|
279
|
-
result,
|
280
|
-
`\
|
281
|
-
SELECT (
|
282
|
-
SELECT ${aggFunc('"pilot.pilot-can fly-plane".*')} AS "can_fly__plane"
|
283
|
-
FROM (
|
284
|
-
SELECT "pilot.pilot-can fly-plane"."id"
|
285
|
-
FROM "pilot-can fly-plane" AS "pilot.pilot-can fly-plane"
|
286
|
-
WHERE "pilot"."id" = "pilot.pilot-can fly-plane"."pilot"
|
287
|
-
) AS "pilot.pilot-can fly-plane"
|
288
|
-
) AS "can_fly__plane", ${pilotFields.join(', ')}
|
289
|
-
FROM "pilot"`,
|
290
|
-
);
|
291
|
-
});
|
292
|
-
};
|
293
|
-
const url = '/pilot?$expand=can_fly__plane($select=id)';
|
294
|
-
test.postgres(url, testFunc(postgresAgg));
|
295
|
-
test.mysql.fail(url, testFunc(mysqlAgg) as any as ExpectationFailFn);
|
296
|
-
test.websql.fail(url, testFunc(websqlAgg) as any as ExpectationFailFn);
|
297
|
-
})();
|
298
|
-
|
299
|
-
(function () {
|
300
|
-
const remainingPilotFields = _.reject(
|
301
|
-
pilotFields,
|
302
|
-
(field) => field === '"pilot"."licence"',
|
303
|
-
).join(', ');
|
304
|
-
const testFunc: TestFn = (aggFunc, fields) => (result, sqlEquals) => {
|
305
|
-
it('should select from pilot.*, aggregated licence', () => {
|
306
|
-
sqlEquals?.(
|
307
|
-
result,
|
308
|
-
`\
|
309
|
-
SELECT (
|
310
|
-
SELECT ${aggFunc('"pilot.licence".*')} AS "licence"
|
311
|
-
FROM (
|
312
|
-
SELECT ${fields}
|
313
|
-
FROM "licence" AS "pilot.licence"
|
314
|
-
WHERE "pilot.licence"."id" IS NOT NULL AND "pilot.licence"."id" = ?
|
315
|
-
AND "pilot"."licence" = "pilot.licence"."id"
|
316
|
-
) AS "pilot.licence"
|
317
|
-
) AS "licence", ${remainingPilotFields}
|
318
|
-
FROM "pilot"`,
|
319
|
-
);
|
320
|
-
});
|
321
|
-
};
|
322
|
-
const url = '/pilot?$expand=licence($filter=id eq 1)';
|
323
|
-
const urlCount = '/pilot?$expand=licence/$count($filter=id eq 1)';
|
324
|
-
test.postgres(
|
325
|
-
url,
|
326
|
-
'GET',
|
327
|
-
[['Bind', 0]],
|
328
|
-
testFunc(postgresAgg, aliasLicenceFields.join(', ')),
|
329
|
-
);
|
330
|
-
test.postgres(
|
331
|
-
urlCount,
|
332
|
-
'GET',
|
333
|
-
[['Bind', 0]],
|
334
|
-
testFunc(postgresAgg, 'COUNT(*) AS "$count"'),
|
335
|
-
);
|
336
|
-
test.mysql.fail(
|
337
|
-
url,
|
338
|
-
'GET',
|
339
|
-
[['Bind', 0]],
|
340
|
-
testFunc(
|
341
|
-
mysqlAgg,
|
342
|
-
aliasLicenceFields.join(', '),
|
343
|
-
) as any as ExpectationFailFn,
|
344
|
-
);
|
345
|
-
test.mysql.fail(
|
346
|
-
urlCount,
|
347
|
-
'GET',
|
348
|
-
[['Bind', 0]],
|
349
|
-
testFunc(mysqlAgg, 'COUNT(*) AS "$count"') as any as ExpectationFailFn,
|
350
|
-
);
|
351
|
-
test.websql.fail(
|
352
|
-
url,
|
353
|
-
'GET',
|
354
|
-
[['Bind', 0]],
|
355
|
-
testFunc(
|
356
|
-
websqlAgg,
|
357
|
-
aliasLicenceFields.join(', '),
|
358
|
-
) as any as ExpectationFailFn,
|
359
|
-
);
|
360
|
-
test.websql.fail(
|
361
|
-
urlCount,
|
362
|
-
'GET',
|
363
|
-
[['Bind', 0]],
|
364
|
-
testFunc(websqlAgg, 'COUNT(*) AS "$count') as any as ExpectationFailFn,
|
365
|
-
);
|
366
|
-
})();
|
367
|
-
|
368
|
-
(function () {
|
369
|
-
const remainingPilotFields = _.reject(
|
370
|
-
pilotFields,
|
371
|
-
(field) => field === '"pilot"."licence"',
|
372
|
-
).join(', ');
|
373
|
-
const testFunc: TestFn = (aggFunc) => (result, sqlEquals) => {
|
374
|
-
it('should select from pilot.*, aggregated licence', () => {
|
375
|
-
sqlEquals?.(
|
376
|
-
result,
|
377
|
-
`\
|
378
|
-
SELECT (
|
379
|
-
SELECT ${aggFunc('"pilot.licence".*')} AS "licence"
|
380
|
-
FROM (
|
381
|
-
SELECT ${aliasLicenceFields.join(', ')}
|
382
|
-
FROM "licence" AS "pilot.licence"
|
383
|
-
LEFT JOIN "pilot" AS "pilot.licence.is of-pilot" ON "pilot.licence"."id" = "pilot.licence.is of-pilot"."licence"
|
384
|
-
WHERE "pilot.licence.is of-pilot"."id" IS NOT NULL AND "pilot.licence.is of-pilot"."id" = ?
|
385
|
-
AND "pilot"."licence" = "pilot.licence"."id"
|
386
|
-
) AS "pilot.licence"
|
387
|
-
) AS "licence", ${remainingPilotFields}
|
388
|
-
FROM "pilot"`,
|
389
|
-
);
|
390
|
-
});
|
391
|
-
};
|
392
|
-
const url = '/pilot?$expand=licence($filter=is_of__pilot/id eq 1)';
|
393
|
-
test.postgres(url, 'GET', [['Bind', 0]], testFunc(postgresAgg));
|
394
|
-
test.mysql.fail(
|
395
|
-
url,
|
396
|
-
'GET',
|
397
|
-
[['Bind', 0]],
|
398
|
-
testFunc(mysqlAgg) as any as ExpectationFailFn,
|
399
|
-
);
|
400
|
-
test.websql.fail(
|
401
|
-
url,
|
402
|
-
'GET',
|
403
|
-
[['Bind', 0]],
|
404
|
-
testFunc(websqlAgg) as any as ExpectationFailFn,
|
405
|
-
);
|
406
|
-
})();
|
407
|
-
|
408
|
-
(function () {
|
409
|
-
const remainingPilotFields = _.reject(
|
410
|
-
pilotFields,
|
411
|
-
(field) => field === '"pilot"."licence"',
|
412
|
-
).join(', ');
|
413
|
-
const testFunc: TestFn = (aggFunc) => (result, sqlEquals) => {
|
414
|
-
it('should select from pilot.*, aggregated licence', () => {
|
415
|
-
sqlEquals?.(
|
416
|
-
result,
|
417
|
-
`\
|
418
|
-
SELECT (
|
419
|
-
SELECT ${aggFunc('"pilot.licence".*')} AS "licence"
|
420
|
-
FROM (
|
421
|
-
SELECT ${aliasLicenceFields.join(', ')}
|
422
|
-
FROM "licence" AS "pilot.licence"
|
423
|
-
WHERE "pilot"."licence" = "pilot.licence"."id"
|
424
|
-
ORDER BY "pilot.licence"."id" DESC
|
425
|
-
) AS "pilot.licence"
|
426
|
-
) AS "licence", ${remainingPilotFields}
|
427
|
-
FROM "pilot"`,
|
428
|
-
);
|
429
|
-
});
|
430
|
-
};
|
431
|
-
const url = '/pilot?$expand=licence($orderby=id)';
|
432
|
-
test.postgres(url, testFunc(postgresAgg));
|
433
|
-
test.mysql.fail(url, testFunc(mysqlAgg) as any as ExpectationFailFn);
|
434
|
-
test.websql.fail(url, testFunc(websqlAgg) as any as ExpectationFailFn);
|
435
|
-
})();
|
436
|
-
|
437
|
-
(function () {
|
438
|
-
const remainingPilotFields = _.reject(
|
439
|
-
pilotFields,
|
440
|
-
(field) => field === '"pilot"."licence"',
|
441
|
-
).join(', ');
|
442
|
-
const testFunc: TestFn = (aggFunc) => (result, sqlEquals) => {
|
443
|
-
it('should select from pilot.*, aggregated count(*) licence and ignore orderby', () => {
|
444
|
-
sqlEquals?.(
|
445
|
-
result,
|
446
|
-
`\
|
447
|
-
SELECT (
|
448
|
-
SELECT ${aggFunc('"pilot.licence".*')} AS "licence"
|
449
|
-
FROM (
|
450
|
-
SELECT COUNT(*) AS "$count"
|
451
|
-
FROM "licence" AS "pilot.licence"
|
452
|
-
WHERE "pilot"."licence" = "pilot.licence"."id"
|
453
|
-
) AS "pilot.licence"
|
454
|
-
) AS "licence", ${remainingPilotFields}
|
455
|
-
FROM "pilot"`,
|
456
|
-
);
|
457
|
-
});
|
458
|
-
};
|
459
|
-
const urlCount = '/pilot?$expand=licence/$count($orderby=id)';
|
460
|
-
test.postgres(urlCount, testFunc(postgresAgg));
|
461
|
-
test.mysql.fail(urlCount, testFunc(mysqlAgg) as any as ExpectationFailFn);
|
462
|
-
test.websql.fail(urlCount, testFunc(websqlAgg) as any as ExpectationFailFn);
|
463
|
-
})();
|
464
|
-
|
465
|
-
(function () {
|
466
|
-
const remainingPilotFields = _.reject(
|
467
|
-
pilotFields,
|
468
|
-
(field) => field === '"pilot"."licence"',
|
469
|
-
).join(', ');
|
470
|
-
const testFunc: TestFn = (aggFunc) => (result, sqlEquals) => {
|
471
|
-
it('should select from pilot.*, aggregated licence', () => {
|
472
|
-
sqlEquals?.(
|
473
|
-
result,
|
474
|
-
`\
|
475
|
-
SELECT (
|
476
|
-
SELECT ${aggFunc('"pilot.licence".*')} AS "licence"
|
477
|
-
FROM (
|
478
|
-
SELECT ${aliasLicenceFields.join(', ')}
|
479
|
-
FROM "licence" AS "pilot.licence"
|
480
|
-
WHERE "pilot"."licence" = "pilot.licence"."id"
|
481
|
-
LIMIT ?
|
482
|
-
) AS "pilot.licence"
|
483
|
-
) AS "licence", ${remainingPilotFields}
|
484
|
-
FROM "pilot"`,
|
485
|
-
);
|
486
|
-
});
|
487
|
-
};
|
488
|
-
const url = '/pilot?$expand=licence($top=10)';
|
489
|
-
test.postgres(url, 'GET', [['Bind', 0]], testFunc(postgresAgg));
|
490
|
-
test.mysql.fail(
|
491
|
-
url,
|
492
|
-
'GET',
|
493
|
-
[['Bind', 0]],
|
494
|
-
testFunc(mysqlAgg) as any as ExpectationFailFn,
|
495
|
-
);
|
496
|
-
test.websql.fail(
|
497
|
-
url,
|
498
|
-
'GET',
|
499
|
-
[['Bind', 0]],
|
500
|
-
testFunc(websqlAgg) as any as ExpectationFailFn,
|
501
|
-
);
|
502
|
-
})();
|
503
|
-
|
504
|
-
(function () {
|
505
|
-
const remainingPilotFields = _.reject(
|
506
|
-
pilotFields,
|
507
|
-
(field) => field === '"pilot"."licence"',
|
508
|
-
).join(', ');
|
509
|
-
const testFunc: TestFn = (aggFunc) => (result, sqlEquals) => {
|
510
|
-
it('should select from pilot.*, aggregated count(*) licence and ignore top', () => {
|
511
|
-
sqlEquals?.(
|
512
|
-
result,
|
513
|
-
`\
|
514
|
-
SELECT (
|
515
|
-
SELECT ${aggFunc('"pilot.licence".*')} AS "licence"
|
516
|
-
FROM (
|
517
|
-
SELECT COUNT(*) AS "$count"
|
518
|
-
FROM "licence" AS "pilot.licence"
|
519
|
-
WHERE "pilot"."licence" = "pilot.licence"."id"
|
520
|
-
) AS "pilot.licence"
|
521
|
-
) AS "licence", ${remainingPilotFields}
|
522
|
-
FROM "pilot"`,
|
523
|
-
);
|
524
|
-
});
|
525
|
-
};
|
526
|
-
const urlCount = '/pilot?$expand=licence/$count($top=10)';
|
527
|
-
test.postgres(urlCount, testFunc(postgresAgg));
|
528
|
-
test.mysql.fail(urlCount, testFunc(mysqlAgg) as any as ExpectationFailFn);
|
529
|
-
test.websql.fail(urlCount, testFunc(websqlAgg) as any as ExpectationFailFn);
|
530
|
-
})();
|
531
|
-
|
532
|
-
(function () {
|
533
|
-
const remainingPilotFields = _.reject(
|
534
|
-
pilotFields,
|
535
|
-
(field) => field === '"pilot"."licence"',
|
536
|
-
).join(', ');
|
537
|
-
const testFunc: TestFn = (aggFunc) => (result, sqlEquals) => {
|
538
|
-
it('should select from pilot.*, aggregated licence', () => {
|
539
|
-
sqlEquals?.(
|
540
|
-
result,
|
541
|
-
`\
|
542
|
-
SELECT (
|
543
|
-
SELECT ${aggFunc('"pilot.licence".*')} AS "licence"
|
544
|
-
FROM (
|
545
|
-
SELECT ${aliasLicenceFields.join(', ')}
|
546
|
-
FROM "licence" AS "pilot.licence"
|
547
|
-
WHERE "pilot"."licence" = "pilot.licence"."id"
|
548
|
-
OFFSET ?
|
549
|
-
) AS "pilot.licence"
|
550
|
-
) AS "licence", ${remainingPilotFields}
|
551
|
-
FROM "pilot"`,
|
552
|
-
);
|
553
|
-
});
|
554
|
-
};
|
555
|
-
const url = '/pilot?$expand=licence($skip=10)';
|
556
|
-
test.postgres(url, 'GET', [['Bind', 0]], testFunc(postgresAgg));
|
557
|
-
test.mysql.fail(
|
558
|
-
url,
|
559
|
-
'GET',
|
560
|
-
[['Bind', 0]],
|
561
|
-
testFunc(mysqlAgg) as any as ExpectationFailFn,
|
562
|
-
);
|
563
|
-
test.websql.fail(
|
564
|
-
url,
|
565
|
-
'GET',
|
566
|
-
[['Bind', 0]],
|
567
|
-
testFunc(websqlAgg) as any as ExpectationFailFn,
|
568
|
-
);
|
569
|
-
})();
|
570
|
-
|
571
|
-
(function () {
|
572
|
-
const remainingPilotFields = _.reject(
|
573
|
-
pilotFields,
|
574
|
-
(field) => field === '"pilot"."licence"',
|
575
|
-
).join(', ');
|
576
|
-
const testFunc: TestFn = (aggFunc) => (result, sqlEquals) => {
|
577
|
-
it('should select from pilot.*, aggregated count(*) licence and ignore skip', () => {
|
578
|
-
sqlEquals?.(
|
579
|
-
result,
|
580
|
-
`\
|
581
|
-
SELECT (
|
582
|
-
SELECT ${aggFunc('"pilot.licence".*')} AS "licence"
|
583
|
-
FROM (
|
584
|
-
SELECT COUNT(*) AS "$count"
|
585
|
-
FROM "licence" AS "pilot.licence"
|
586
|
-
WHERE "pilot"."licence" = "pilot.licence"."id"
|
587
|
-
) AS "pilot.licence"
|
588
|
-
) AS "licence", ${remainingPilotFields}
|
589
|
-
FROM "pilot"`,
|
590
|
-
);
|
591
|
-
});
|
592
|
-
};
|
593
|
-
const urlCount = '/pilot?$expand=licence/$count($skip=10)';
|
594
|
-
test.postgres(urlCount, testFunc(postgresAgg));
|
595
|
-
test.mysql.fail(urlCount, testFunc(mysqlAgg) as any as ExpectationFailFn);
|
596
|
-
test.websql.fail(urlCount, testFunc(websqlAgg) as any as ExpectationFailFn);
|
597
|
-
})();
|
598
|
-
|
599
|
-
(function () {
|
600
|
-
const testFunc: TestFn = (aggFunc) => (result, sqlEquals) => {
|
601
|
-
it('should select from pilot.*, aggregated(pilot-can fly-plane, aggregated plane)', () => {
|
602
|
-
sqlEquals?.(
|
603
|
-
result,
|
604
|
-
`\
|
605
|
-
SELECT (
|
606
|
-
SELECT ${aggFunc('"pilot.pilot-can fly-plane".*')} AS "can_fly__plane"
|
607
|
-
FROM (
|
608
|
-
SELECT "pilot.pilot-can fly-plane"."can fly-plane" AS "plane"
|
609
|
-
FROM "pilot-can fly-plane" AS "pilot.pilot-can fly-plane"
|
610
|
-
WHERE "pilot"."id" = "pilot.pilot-can fly-plane"."pilot"
|
611
|
-
) AS "pilot.pilot-can fly-plane"
|
612
|
-
) AS "can_fly__plane", ${pilotFields.join(', ')}
|
613
|
-
FROM "pilot"`,
|
614
|
-
);
|
615
|
-
});
|
616
|
-
};
|
617
|
-
const url = '/pilot?$expand=can_fly__plane($select=plane)';
|
618
|
-
test.postgres(url, testFunc(postgresAgg));
|
619
|
-
test.mysql.fail(url, testFunc(mysqlAgg) as any as ExpectationFailFn);
|
620
|
-
test.websql.fail(url, testFunc(websqlAgg) as any as ExpectationFailFn);
|
621
|
-
})();
|
622
|
-
|
623
|
-
(function () {
|
624
|
-
const testFunc: TestFn = (aggFunc) => (result, sqlEquals) => {
|
625
|
-
it('should select from pilot.*, aggregated count(*) pilot-can fly-plane and ignore select', () => {
|
626
|
-
sqlEquals?.(
|
627
|
-
result,
|
628
|
-
`\
|
629
|
-
SELECT (
|
630
|
-
SELECT ${aggFunc('"pilot.pilot-can fly-plane".*')} AS "can_fly__plane"
|
631
|
-
FROM (
|
632
|
-
SELECT COUNT(*) AS "$count"
|
633
|
-
FROM "pilot-can fly-plane" AS "pilot.pilot-can fly-plane"
|
634
|
-
WHERE "pilot"."id" = "pilot.pilot-can fly-plane"."pilot"
|
635
|
-
) AS "pilot.pilot-can fly-plane"
|
636
|
-
) AS "can_fly__plane", ${pilotFields.join(', ')}
|
637
|
-
FROM "pilot"`,
|
638
|
-
);
|
639
|
-
});
|
640
|
-
};
|
641
|
-
const urlCount = '/pilot?$expand=can_fly__plane/$count($select=plane)';
|
642
|
-
test.postgres(urlCount, testFunc(postgresAgg));
|
643
|
-
test.mysql.fail(urlCount, testFunc(mysqlAgg) as any as ExpectationFailFn);
|
644
|
-
test.websql.fail(urlCount, testFunc(websqlAgg) as any as ExpectationFailFn);
|
645
|
-
})();
|
646
|
-
|
647
|
-
(function () {
|
648
|
-
const aliasedFields = aliasFields('pilot.trained-pilot', pilotFields);
|
649
|
-
const remainingPilotFields = _.reject(
|
650
|
-
pilotFields,
|
651
|
-
(field) => field === '"pilot"."trained-pilot"',
|
652
|
-
).join(', ');
|
653
|
-
const testFunc: TestFn = (aggFunc) => (result, sqlEquals) => {
|
654
|
-
it('should select from pilot.*, aggregated pilot', () => {
|
655
|
-
sqlEquals?.(
|
656
|
-
result,
|
657
|
-
`\
|
658
|
-
SELECT (
|
659
|
-
SELECT ${aggFunc('"pilot.trained-pilot".*')} AS "trained__pilot"
|
660
|
-
FROM (
|
661
|
-
SELECT ${aliasedFields.join(', ')}
|
662
|
-
FROM "pilot" AS "pilot.trained-pilot"
|
663
|
-
WHERE "pilot"."id" = "pilot.trained-pilot"."was trained by-pilot"
|
664
|
-
) AS "pilot.trained-pilot"
|
665
|
-
) AS "trained__pilot", ${remainingPilotFields}
|
666
|
-
FROM "pilot"`,
|
667
|
-
);
|
668
|
-
});
|
669
|
-
};
|
670
|
-
const url = '/pilot?$expand=trained__pilot';
|
671
|
-
test.postgres(url, testFunc(postgresAgg));
|
672
|
-
test.mysql.fail(url, testFunc(mysqlAgg) as any as ExpectationFailFn);
|
673
|
-
test.websql.fail(url, testFunc(websqlAgg) as any as ExpectationFailFn);
|
674
|
-
})();
|