@simplysm/orm-common 13.0.74 → 13.0.76

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 (36) hide show
  1. package/package.json +2 -2
  2. package/tests/db-context/create-db-context.spec.ts +0 -31
  3. package/tests/db-context/define-db-context.spec.ts +0 -51
  4. package/tests/ddl/basic.spec.ts +0 -157
  5. package/tests/ddl/column-builder.spec.ts +0 -112
  6. package/tests/ddl/index-builder.spec.ts +0 -54
  7. package/tests/ddl/procedure-builder.spec.ts +0 -106
  8. package/tests/ddl/relation-builder.spec.ts +0 -201
  9. package/tests/ddl/table-builder.spec.ts +0 -34
  10. package/tests/ddl/view-builder.spec.ts +0 -60
  11. package/tests/dml/delete.spec.ts +0 -33
  12. package/tests/dml/insert.spec.ts +0 -78
  13. package/tests/dml/update.spec.ts +0 -96
  14. package/tests/dml/upsert.spec.ts +0 -52
  15. package/tests/errors/queryable-errors.spec.ts +0 -51
  16. package/tests/escape.spec.ts +0 -41
  17. package/tests/examples/pivot.spec.ts +0 -333
  18. package/tests/examples/sampling.spec.ts +0 -63
  19. package/tests/examples/unpivot.spec.ts +0 -65
  20. package/tests/exec/search-parser.spec.ts +0 -16
  21. package/tests/expr/comparison.spec.ts +0 -66
  22. package/tests/expr/conditional.spec.ts +0 -27
  23. package/tests/expr/date.spec.ts +0 -67
  24. package/tests/expr/math.spec.ts +0 -47
  25. package/tests/expr/string.spec.ts +0 -56
  26. package/tests/expr/utility.spec.ts +0 -27
  27. package/tests/select/basic.spec.ts +0 -69
  28. package/tests/select/filter.spec.ts +0 -114
  29. package/tests/select/group.spec.ts +0 -85
  30. package/tests/select/join.spec.ts +0 -113
  31. package/tests/select/order.spec.ts +0 -49
  32. package/tests/select/subquery.spec.ts +0 -96
  33. package/tests/select/window.spec.ts +0 -185
  34. package/tests/types/nullable-queryable-record.spec.ts +0 -48
  35. package/tests/utils/result-parser-perf.spec.ts +0 -67
  36. package/tests/utils/result-parser.spec.ts +0 -34
@@ -61,46 +61,6 @@ describe("DDL - Relation Builder", () => {
61
61
  });
62
62
  });
63
63
 
64
- describe("ForeignKeyBuilder - description specified", () => {
65
- const Post = Table("Post")
66
- .database("TestDb")
67
- .schema("TestSchema")
68
- .columns((c) => ({
69
- id: c.bigint(),
70
- userId: c.bigint(),
71
- }))
72
- .primaryKey("id")
73
- .relations(() => ({}));
74
-
75
- const RelationFactory = createRelationFactory(() => Post);
76
- const fkBuilder = RelationFactory.foreignKey(["userId"], () => User).description("User relationship");
77
-
78
- const db = createTestDb();
79
- const def = db.getAddFkQueryDef(
80
- { database: "TestDb", schema: "TestSchema", name: "Post" },
81
- "user",
82
- fkBuilder,
83
- );
84
-
85
- it("should validate QueryDef", () => {
86
- expect(def).toEqual({
87
- type: "addFk",
88
- table: { database: "TestDb", schema: "TestSchema", name: "Post" },
89
- foreignKey: {
90
- name: "FK_Post_user",
91
- fkColumns: ["userId"],
92
- targetTable: { database: "TestDb", schema: "TestSchema", name: "User" },
93
- targetPkColumns: ["id"],
94
- },
95
- });
96
- });
97
-
98
- it.each(dialects)("[%s] should validate SQL", (dialect) => {
99
- const builder = createQueryBuilder(dialect);
100
- expect(builder.build(def)).toMatchSql(expected.basicForeignKey[dialect]);
101
- });
102
- });
103
-
104
64
  describe("ForeignKeyBuilder - composite FK", () => {
105
65
  const Company = Table("Company")
106
66
  .database("TestDb")
@@ -207,166 +167,5 @@ describe("DDL - Relation Builder", () => {
207
167
  });
208
168
  });
209
169
 
210
- describe("ForeignKeyTargetBuilder - description specified", () => {
211
- const Post = Table("Post")
212
- .database("TestDb")
213
- .schema("TestSchema")
214
- .columns((c) => ({
215
- id: c.bigint(),
216
- userId: c.bigint(),
217
- }))
218
- .primaryKey("id")
219
- .relations(() => ({}));
220
-
221
- const RelationFactory = createRelationFactory(() => User);
222
- const targetBuilder = RelationFactory.foreignKeyTarget(() => Post, "posts").description(
223
- "List of posts by user",
224
- );
225
-
226
- it("should validate metadata", () => {
227
- expect(targetBuilder.meta).toEqual({
228
- targetTableFn: expect.any(Function),
229
- relationName: "posts",
230
- description: "List of posts by user",
231
- isSingle: undefined,
232
- });
233
- });
234
- });
235
-
236
- //#endregion
237
-
238
- //#region ========== RelationKeyBuilder ==========
239
-
240
- describe("RelationKeyBuilder - basic", () => {
241
- const Post = Table("Post")
242
- .database("TestDb")
243
- .schema("TestSchema")
244
- .columns((c) => ({
245
- id: c.bigint(),
246
- authorId: c.bigint(),
247
- }))
248
- .primaryKey("id")
249
- .relations(() => ({}));
250
-
251
- const RelationFactory = createRelationFactory(() => Post);
252
- const rkBuilder = RelationFactory.relationKey(["authorId"], () => User);
253
-
254
- // RelationKey does not register FK in DB so getAddFkQueryDef test is not possible
255
- // Only metadata validation
256
- it("should validate metadata", () => {
257
- expect(rkBuilder.meta).toEqual({
258
- ownerFn: expect.any(Function),
259
- columns: ["authorId"],
260
- targetFn: expect.any(Function),
261
- description: undefined,
262
- });
263
- });
264
- });
265
-
266
- describe("RelationKeyBuilder - description specified", () => {
267
- const Post = Table("Post")
268
- .database("TestDb")
269
- .schema("TestSchema")
270
- .columns((c) => ({
271
- id: c.bigint(),
272
- authorId: c.bigint(),
273
- }))
274
- .primaryKey("id")
275
- .relations(() => ({}));
276
-
277
- const RelationFactory = createRelationFactory(() => Post);
278
- const rkBuilder = RelationFactory.relationKey(["authorId"], () => User).description(
279
- "Author relationship (logical)",
280
- );
281
-
282
- it("should validate metadata", () => {
283
- expect(rkBuilder.meta).toEqual({
284
- ownerFn: expect.any(Function),
285
- columns: ["authorId"],
286
- targetFn: expect.any(Function),
287
- description: "Author relationship (logical)",
288
- });
289
- });
290
- });
291
-
292
- //#endregion
293
-
294
- //#region ========== RelationKeyTargetBuilder ==========
295
-
296
- describe("RelationKeyTargetBuilder - basic (array)", () => {
297
- const Post = Table("Post")
298
- .database("TestDb")
299
- .schema("TestSchema")
300
- .columns((c) => ({
301
- id: c.bigint(),
302
- authorId: c.bigint(),
303
- }))
304
- .primaryKey("id")
305
- .relations(() => ({}));
306
-
307
- const RelationFactory = createRelationFactory(() => User);
308
- const targetBuilder = RelationFactory.relationKeyTarget(() => Post, "authoredPosts");
309
-
310
- it("should validate metadata", () => {
311
- expect(targetBuilder.meta).toEqual({
312
- targetTableFn: expect.any(Function),
313
- relationName: "authoredPosts",
314
- description: undefined,
315
- isSingle: undefined,
316
- });
317
- });
318
- });
319
-
320
- describe("RelationKeyTargetBuilder - single() method", () => {
321
- const Post = Table("Post")
322
- .database("TestDb")
323
- .schema("TestSchema")
324
- .columns((c) => ({
325
- id: c.bigint(),
326
- authorId: c.bigint(),
327
- }))
328
- .primaryKey("id")
329
- .relations(() => ({}));
330
-
331
- const RelationFactory = createRelationFactory(() => User);
332
- const targetBuilder = RelationFactory.relationKeyTarget(() => Post, "featuredPost").single();
333
-
334
- it("should validate metadata", () => {
335
- expect(targetBuilder.meta).toEqual({
336
- targetTableFn: expect.any(Function),
337
- relationName: "featuredPost",
338
- description: undefined,
339
- isSingle: true,
340
- });
341
- });
342
- });
343
-
344
- describe("RelationKeyTargetBuilder - description specified", () => {
345
- const Post = Table("Post")
346
- .database("TestDb")
347
- .schema("TestSchema")
348
- .columns((c) => ({
349
- id: c.bigint(),
350
- authorId: c.bigint(),
351
- }))
352
- .primaryKey("id")
353
- .relations(() => ({}));
354
-
355
- const RelationFactory = createRelationFactory(() => User);
356
- const targetBuilder = RelationFactory.relationKeyTarget(
357
- () => Post,
358
- "authoredPosts",
359
- ).description("List of authored posts (logical)");
360
-
361
- it("should validate metadata", () => {
362
- expect(targetBuilder.meta).toEqual({
363
- targetTableFn: expect.any(Function),
364
- relationName: "authoredPosts",
365
- description: "List of authored posts (logical)",
366
- isSingle: undefined,
367
- });
368
- });
369
- });
370
-
371
170
  //#endregion
372
171
  });
@@ -24,23 +24,6 @@ describe("DDL - Table Builder", () => {
24
24
  });
25
25
  });
26
26
 
27
- describe("description specified", () => {
28
- const table = Table("User").description("User table");
29
-
30
- it("should validate metadata", () => {
31
- expect(table.meta).toEqual({
32
- name: "User",
33
- description: "User table",
34
- database: undefined,
35
- schema: undefined,
36
- columns: undefined,
37
- primaryKey: undefined,
38
- relations: undefined,
39
- indexes: undefined,
40
- });
41
- });
42
- });
43
-
44
27
  describe("database specified", () => {
45
28
  const table = Table("User").database("CustomDb");
46
29
 
@@ -58,23 +41,6 @@ describe("DDL - Table Builder", () => {
58
41
  });
59
42
  });
60
43
 
61
- describe("schema specified", () => {
62
- const table = Table("User").schema("CustomSchema");
63
-
64
- it("should validate metadata", () => {
65
- expect(table.meta).toEqual({
66
- name: "User",
67
- description: undefined,
68
- database: undefined,
69
- schema: "CustomSchema",
70
- columns: undefined,
71
- primaryKey: undefined,
72
- relations: undefined,
73
- indexes: undefined,
74
- });
75
- });
76
- });
77
-
78
44
  describe("columns specified (single column)", () => {
79
45
  const table = Table("User").columns((c) => ({ id: c.bigint() }));
80
46
 
@@ -7,66 +7,6 @@ import "../setup/test-utils"; // toMatchSql matcher
7
7
  import * as expected from "./view-builder.expected";
8
8
 
9
9
  describe("DDL - View Builder", () => {
10
- describe("basic view (name only)", () => {
11
- const view = View("TestView");
12
-
13
- it("should validate metadata", () => {
14
- expect(view.meta).toEqual({
15
- name: "TestView",
16
- description: undefined,
17
- database: undefined,
18
- schema: undefined,
19
- viewFn: undefined,
20
- relations: undefined,
21
- });
22
- });
23
- });
24
-
25
- describe("description specified", () => {
26
- const view = View("TestView").description("This is a test view");
27
-
28
- it("should validate metadata", () => {
29
- expect(view.meta).toEqual({
30
- name: "TestView",
31
- description: "This is a test view",
32
- database: undefined,
33
- schema: undefined,
34
- viewFn: undefined,
35
- relations: undefined,
36
- });
37
- });
38
- });
39
-
40
- describe("database specified", () => {
41
- const view = View("TestView").database("CustomDb");
42
-
43
- it("should validate metadata", () => {
44
- expect(view.meta).toEqual({
45
- name: "TestView",
46
- description: undefined,
47
- database: "CustomDb",
48
- schema: undefined,
49
- viewFn: undefined,
50
- relations: undefined,
51
- });
52
- });
53
- });
54
-
55
- describe("schema specified", () => {
56
- const view = View("TestView").schema("CustomSchema");
57
-
58
- it("should validate metadata", () => {
59
- expect(view.meta).toEqual({
60
- name: "TestView",
61
- description: undefined,
62
- database: undefined,
63
- schema: "CustomSchema",
64
- viewFn: undefined,
65
- relations: undefined,
66
- });
67
- });
68
- });
69
-
70
10
  describe("query specified (basic SELECT)", () => {
71
11
  const view = View("TestView").query((db: TestDbContext) =>
72
12
  db.user().select((u) => ({
@@ -60,39 +60,6 @@ describe("DELETE - Basic", () => {
60
60
  });
61
61
  });
62
62
 
63
- describe("DELETE with multiple conditions", () => {
64
- const db = createTestDb();
65
-
66
- const def = db
67
- .employee()
68
- .where((e) => [expr.eq(e.departmentId, 1), expr.null(e.managerId)])
69
- .getDeleteQueryDef();
70
-
71
- it("should validate QueryDef", () => {
72
- expect(def).toEqual({
73
- type: "delete",
74
- table: { database: "TestDb", schema: "TestSchema", name: "Employee" },
75
- as: "T1",
76
- where: [
77
- {
78
- type: "eq",
79
- source: { type: "column", path: ["T1", "departmentId"] },
80
- target: { type: "value", value: 1 },
81
- },
82
- {
83
- type: "null",
84
- arg: { type: "column", path: ["T1", "managerId"] },
85
- },
86
- ],
87
- });
88
- });
89
-
90
- it.each(dialects)("[%s] should validate SQL", (dialect) => {
91
- const builder = createQueryBuilder(dialect);
92
- expect(builder.build(def)).toMatchSql(expected.deleteMultiCond[dialect]);
93
- });
94
- });
95
-
96
63
  describe("output column specified", () => {
97
64
  const db = createTestDb();
98
65
 
@@ -161,44 +161,6 @@ describe("INSERT IF NOT EXISTS", () => {
161
161
  });
162
162
  });
163
163
 
164
- describe("Check duplicates with complex conditions", () => {
165
- const db = createTestDb();
166
- const def = db
167
- .employee()
168
- .where((e) => [expr.eq(e.name, "Gildong Hong"), expr.eq(e.departmentId, 1)])
169
- .getInsertIfNotExistsQueryDef({ name: "Gildong Hong", departmentId: 1 });
170
-
171
- it("Verify QueryDef", () => {
172
- expect(def).toEqual({
173
- type: "insertIfNotExists",
174
- table: { database: "TestDb", schema: "TestSchema", name: "Employee" },
175
- record: { name: "Gildong Hong", departmentId: 1 },
176
- existsSelectQuery: {
177
- type: "select",
178
- as: "T1",
179
- from: { database: "TestDb", schema: "TestSchema", name: "Employee" },
180
- where: [
181
- {
182
- type: "eq",
183
- source: { type: "column", path: ["T1", "name"] },
184
- target: { type: "value", value: "Gildong Hong" },
185
- },
186
- {
187
- type: "eq",
188
- source: { type: "column", path: ["T1", "departmentId"] },
189
- target: { type: "value", value: 1 },
190
- },
191
- ],
192
- },
193
- });
194
- });
195
-
196
- it.each(dialects)("[%s] Verify SQL", (dialect) => {
197
- const builder = createQueryBuilder(dialect);
198
- expect(builder.build(def)).toMatchSql(expected.insertIfNotExistsMultiple[dialect]);
199
- });
200
- });
201
-
202
164
  //#endregion
203
165
  });
204
166
 
@@ -244,45 +206,5 @@ describe("INSERT INTO ... SELECT", () => {
244
206
  });
245
207
  });
246
208
 
247
- describe("INSERT INTO SELECT with WHERE condition", () => {
248
- const db = createTestDb();
249
- const def = db
250
- .employee()
251
- .where((e) => [expr.eq(e.departmentId, 1)])
252
- .select((e) => ({
253
- id: e.id,
254
- name: e.name,
255
- }))
256
- .getInsertIntoQueryDef(EmployeeBackup);
257
-
258
- it("Verify QueryDef", () => {
259
- expect(def).toEqual({
260
- type: "insertInto",
261
- table: { database: "TestDb", schema: "TestSchema", name: "EmployeeBackup" },
262
- recordsSelectQuery: {
263
- type: "select",
264
- as: "T1",
265
- from: { database: "TestDb", schema: "TestSchema", name: "Employee" },
266
- where: [
267
- {
268
- type: "eq",
269
- source: { type: "column", path: ["T1", "departmentId"] },
270
- target: { type: "value", value: 1 },
271
- },
272
- ],
273
- select: {
274
- id: { type: "column", path: ["T1", "id"] },
275
- name: { type: "column", path: ["T1", "name"] },
276
- },
277
- },
278
- });
279
- });
280
-
281
- it.each(dialects)("[%s] Verify SQL", (dialect) => {
282
- const builder = createQueryBuilder(dialect);
283
- expect(builder.build(def)).toMatchSql(expected.insertIntoSelectWhere[dialect]);
284
- });
285
- });
286
-
287
209
  //#endregion
288
210
  });
@@ -41,42 +41,6 @@ describe("UPDATE - Basic", () => {
41
41
  });
42
42
  });
43
43
 
44
- describe("UPDATE multiple columns", () => {
45
- const db = createTestDb();
46
-
47
- const def = db
48
- .employee()
49
- .where((e) => [expr.eq(e.id, 1)])
50
- .getUpdateQueryDef(() => ({
51
- name: expr.val("string", "New Name"),
52
- departmentId: expr.val("number", 2),
53
- }));
54
-
55
- it("Verify QueryDef", () => {
56
- expect(def).toEqual({
57
- type: "update",
58
- table: { database: "TestDb", schema: "TestSchema", name: "Employee" },
59
- as: "T1",
60
- record: {
61
- name: { type: "value", value: "New Name" },
62
- departmentId: { type: "value", value: 2 },
63
- },
64
- where: [
65
- {
66
- type: "eq",
67
- source: { type: "column", path: ["T1", "id"] },
68
- target: { type: "value", value: 1 },
69
- },
70
- ],
71
- });
72
- });
73
-
74
- it.each(dialects)("[%s] should validate SQL", (dialect) => {
75
- const builder = createQueryBuilder(dialect);
76
- expect(builder.build(def)).toMatchSql(expected.updateMultiCol[dialect]);
77
- });
78
- });
79
-
80
44
  describe("UPDATE with literal values (without expr.val)", () => {
81
45
  const db = createTestDb();
82
46
 
@@ -153,45 +117,6 @@ describe("UPDATE - Basic", () => {
153
117
  });
154
118
  });
155
119
 
156
- describe("UPDATE referencing current values (e.g., count = count + 1)", () => {
157
- const db = createTestDb();
158
-
159
- const def = db
160
- .employee()
161
- .where((e) => [expr.eq(e.id, 1)])
162
- .getUpdateQueryDef((e) => ({
163
- // managerId = managerId + 1 (example)
164
- managerId: expr.raw("number")`${e.managerId} + 1`,
165
- }));
166
-
167
- it("Verify QueryDef", () => {
168
- expect(def).toEqual({
169
- type: "update",
170
- table: { database: "TestDb", schema: "TestSchema", name: "Employee" },
171
- as: "T1",
172
- record: {
173
- managerId: {
174
- type: "raw",
175
- sql: "$1 + 1",
176
- params: [{ type: "column", path: ["T1", "managerId"] }],
177
- },
178
- },
179
- where: [
180
- {
181
- type: "eq",
182
- source: { type: "column", path: ["T1", "id"] },
183
- target: { type: "value", value: 1 },
184
- },
185
- ],
186
- });
187
- });
188
-
189
- it.each(dialects)("[%s] should validate SQL", (dialect) => {
190
- const builder = createQueryBuilder(dialect);
191
- expect(builder.build(def)).toMatchSql(expected.updateWithRef[dialect]);
192
- });
193
- });
194
-
195
120
  describe("Specify output column", () => {
196
121
  const db = createTestDb();
197
122
 
@@ -294,25 +219,4 @@ describe("FK switch", () => {
294
219
  });
295
220
  });
296
221
 
297
- describe("FK on", () => {
298
- const db = createTestDb();
299
-
300
- const def = db.getSwitchFkQueryDef(
301
- { database: "TestDb", schema: "TestSchema", name: "Employee" },
302
- "on",
303
- );
304
-
305
- it("Verify QueryDef", () => {
306
- expect(def).toEqual({
307
- type: "switchFk",
308
- table: { database: "TestDb", schema: "TestSchema", name: "Employee" },
309
- switch: "on",
310
- });
311
- });
312
-
313
- it.each(dialects)("[%s] should validate SQL", (dialect) => {
314
- const builder = createQueryBuilder(dialect);
315
- expect(builder.build(def)).toMatchSql(expected.fkOn[dialect]);
316
- });
317
- });
318
222
  });
@@ -146,58 +146,6 @@ describe("UPSERT - Basic", () => {
146
146
  });
147
147
  });
148
148
 
149
- describe("Complex WHERE condition", () => {
150
- const db = createTestDb();
151
- const def = db
152
- .employee()
153
- .where((e) => [expr.eq(e.name, "Gildong Hong"), expr.eq(e.departmentId, 1)])
154
- .getUpsertQueryDef(
155
- () => ({ managerId: expr.val("number", 10) }),
156
- (upd) => ({
157
- name: expr.val("string", "Gildong Hong"),
158
- departmentId: expr.val("number", 1),
159
- managerId: upd.managerId,
160
- }),
161
- );
162
-
163
- it("Verify QueryDef", () => {
164
- expect(def).toEqual({
165
- type: "upsert",
166
- table: { database: "TestDb", schema: "TestSchema", name: "Employee" },
167
- existsSelectQuery: {
168
- type: "select",
169
- as: "T1",
170
- from: { database: "TestDb", schema: "TestSchema", name: "Employee" },
171
- where: [
172
- {
173
- type: "eq",
174
- source: { type: "column", path: ["T1", "name"] },
175
- target: { type: "value", value: "Gildong Hong" },
176
- },
177
- {
178
- type: "eq",
179
- source: { type: "column", path: ["T1", "departmentId"] },
180
- target: { type: "value", value: 1 },
181
- },
182
- ],
183
- },
184
- updateRecord: {
185
- managerId: { type: "value", value: 10 },
186
- },
187
- insertRecord: {
188
- name: { type: "value", value: "Gildong Hong" },
189
- departmentId: { type: "value", value: 1 },
190
- managerId: { type: "value", value: 10 },
191
- },
192
- });
193
- });
194
-
195
- it.each(dialects)("[%s] should validate SQL", (dialect) => {
196
- const builder = createQueryBuilder(dialect);
197
- expect(builder.build(def)).toMatchSql(expected.upsertMultiWhere[dialect]);
198
- });
199
- });
200
-
201
149
  describe("UPSERT with literal values (without expr.val)", () => {
202
150
  const db = createTestDb();
203
151
  const def = db
@@ -10,9 +10,6 @@ describe("Queryable error cases", () => {
10
10
  expect(() => expr.and([])).toThrow("empty arrays are not allowed");
11
11
  });
12
12
 
13
- it("ArgumentError when calling or() with empty array", () => {
14
- expect(() => expr.or([])).toThrow("empty arrays are not allowed");
15
- });
16
13
  });
17
14
 
18
15
  describe("executable errors", () => {
@@ -97,21 +94,6 @@ describe("Queryable error cases", () => {
97
94
  }).toThrow("inQuery subquery must SELECT only a single column.");
98
95
  });
99
96
 
100
- it("Error when using subquery without column specification", () => {
101
- const db = createTestDb();
102
-
103
- expect(() => {
104
- db.user()
105
- .where((u) => [
106
- expr.inQuery(
107
- u.id,
108
- // @ts-expect-error - subquery without SELECT
109
- db.post(),
110
- ),
111
- ])
112
- .getSelectQueryDef();
113
- }).toThrow("inQuery subquery must SELECT only a single column.");
114
- });
115
97
  });
116
98
 
117
99
  describe("countAsync() errors", () => {
@@ -141,37 +123,4 @@ describe("Queryable error cases", () => {
141
123
  });
142
124
  });
143
125
 
144
- describe("RecursiveQueryable.union() errors", () => {
145
- it("Error when calling union with a single queryable", () => {
146
- const db = createTestDb();
147
-
148
- expect(() => {
149
- db.employee()
150
- .where((e) => [expr.null(e.managerId)])
151
- .recursive((cte) => cte.union(db.employee()));
152
- }).toThrow("union requires at least 2 queryables.");
153
- });
154
-
155
- it("Error when calling union with zero queryables", () => {
156
- const db = createTestDb();
157
-
158
- expect(() => {
159
- db.employee()
160
- .where((e) => [expr.null(e.managerId)])
161
- .recursive((cte) => cte.union());
162
- }).toThrow("union requires at least 2 queryables.");
163
- });
164
- });
165
-
166
- describe("JoinQueryable.union() errors", () => {
167
- it("Error when calling union with a single queryable inside join", () => {
168
- const db = createTestDb();
169
-
170
- expect(() => {
171
- db.user().join("posts", (j, u) =>
172
- j.union(db.post().where((p) => [expr.eq(p.userId, u.id)])),
173
- );
174
- }).toThrow("union requires at least 2 queryables.");
175
- });
176
- });
177
126
  });