pqb 0.3.6 → 0.3.7

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.
@@ -2,9 +2,9 @@ import {
2
2
  User,
3
3
  expectQueryNotMutated,
4
4
  expectSql,
5
- AssertEqual,
6
5
  useTestDatabase,
7
6
  userData,
7
+ assertType,
8
8
  } from '../test-utils';
9
9
  import { raw } from '../common';
10
10
 
@@ -126,8 +126,7 @@ describe('aggregate', () => {
126
126
  it('should return a number', async () => {
127
127
  const count = await User.count();
128
128
 
129
- const eq: AssertEqual<typeof count, number> = true;
130
- expect(eq).toBe(true);
129
+ assertType<typeof count, number>();
131
130
 
132
131
  expect(typeof count).toBe('number');
133
132
  });
@@ -139,8 +138,7 @@ describe('aggregate', () => {
139
138
  const user = await User.selectCount().take();
140
139
  expect(user.count).toBe(1);
141
140
 
142
- const eq: AssertEqual<typeof user.count, number> = true;
143
- expect(eq).toBe(true);
141
+ assertType<typeof user.count, number>();
144
142
  });
145
143
  });
146
144
  });
@@ -157,8 +155,7 @@ describe('aggregate', () => {
157
155
  it('should return null when no records', async () => {
158
156
  const value = await User[method as 'avg']('id');
159
157
 
160
- const eq: AssertEqual<typeof value, number | null> = true;
161
- expect(eq).toBe(true);
158
+ assertType<typeof value, number | null>();
162
159
 
163
160
  expect(value).toBe(null);
164
161
  });
@@ -168,8 +165,7 @@ describe('aggregate', () => {
168
165
 
169
166
  const value = await User[method as 'avg']('id');
170
167
 
171
- const eq: AssertEqual<typeof value, number | null> = true;
172
- expect(eq).toBe(true);
168
+ assertType<typeof value, number | null>();
173
169
 
174
170
  expect(typeof value).toBe('number');
175
171
  });
@@ -181,8 +177,7 @@ describe('aggregate', () => {
181
177
  it('should select null when no record', async () => {
182
178
  const value = await User[selectMethod]('id').take();
183
179
 
184
- const eq: AssertEqual<typeof value, { avg: number | null }> = true;
185
- expect(eq).toBe(true);
180
+ assertType<typeof value, { avg: number | null }>();
186
181
 
187
182
  expect(value).toEqual({ [functionName]: null });
188
183
  });
@@ -192,8 +187,7 @@ describe('aggregate', () => {
192
187
 
193
188
  const value = await User[selectMethod]('id').take();
194
189
 
195
- const eq: AssertEqual<typeof value, { avg: number | null }> = true;
196
- expect(eq).toBe(true);
190
+ assertType<typeof value, { avg: number | null }>();
197
191
 
198
192
  expect(value).toEqual({ [functionName]: id });
199
193
  });
@@ -209,8 +203,7 @@ describe('aggregate', () => {
209
203
  it('should return null when no records', async () => {
210
204
  const value = await User[method as 'boolAnd']('active');
211
205
 
212
- const eq: AssertEqual<typeof value, boolean | null> = true;
213
- expect(eq).toBe(true);
206
+ assertType<typeof value, boolean | null>();
214
207
 
215
208
  expect(value).toBe(null);
216
209
  });
@@ -220,8 +213,7 @@ describe('aggregate', () => {
220
213
 
221
214
  const value = await User[method as 'boolAnd']('active');
222
215
 
223
- const eq: AssertEqual<typeof value, boolean | null> = true;
224
- expect(eq).toBe(true);
216
+ assertType<typeof value, boolean | null>();
225
217
 
226
218
  expect(typeof value).toBe('boolean');
227
219
  });
@@ -233,9 +225,7 @@ describe('aggregate', () => {
233
225
  it('should select null when no record', async () => {
234
226
  const value = await User[selectMethod]('active').take();
235
227
 
236
- const eq: AssertEqual<typeof value, { bool_and: boolean | null }> =
237
- true;
238
- expect(eq).toBe(true);
228
+ assertType<typeof value, { bool_and: boolean | null }>();
239
229
 
240
230
  expect(value).toEqual({ [functionName]: null });
241
231
  });
@@ -245,9 +235,7 @@ describe('aggregate', () => {
245
235
 
246
236
  const value = await User[selectMethod]('active').take();
247
237
 
248
- const eq: AssertEqual<typeof value, { bool_and: boolean | null }> =
249
- true;
250
- expect(eq).toBe(true);
238
+ assertType<typeof value, { bool_and: boolean | null }>();
251
239
 
252
240
  expect(value).toEqual({ [functionName]: true });
253
241
  });
@@ -264,11 +252,10 @@ describe('aggregate', () => {
264
252
  it('should return null when no records', async () => {
265
253
  const value = await User[method as 'jsonAgg']('data');
266
254
 
267
- const eq: AssertEqual<
255
+ assertType<
268
256
  typeof value,
269
257
  ({ name: string; tags: string[] } | null)[] | null
270
- > = true;
271
- expect(eq).toBe(true);
258
+ >();
272
259
 
273
260
  expect(value).toBe(null);
274
261
  });
@@ -278,11 +265,10 @@ describe('aggregate', () => {
278
265
 
279
266
  const value = await User[method as 'jsonAgg']('data');
280
267
 
281
- const eq: AssertEqual<
268
+ assertType<
282
269
  typeof value,
283
270
  ({ name: string; tags: string[] } | null)[] | null
284
- > = true;
285
- expect(eq).toBe(true);
271
+ >();
286
272
 
287
273
  expect(value).toEqual([data]);
288
274
  });
@@ -294,11 +280,10 @@ describe('aggregate', () => {
294
280
  it('should select null when no record', async () => {
295
281
  const value = await User[selectMethod]('data').take();
296
282
 
297
- const eq: AssertEqual<
283
+ assertType<
298
284
  typeof value,
299
285
  { json_agg: ({ name: string; tags: string[] } | null)[] | null }
300
- > = true;
301
- expect(eq).toBe(true);
286
+ >();
302
287
 
303
288
  expect(value).toEqual({ [functionName]: null });
304
289
  });
@@ -308,11 +293,10 @@ describe('aggregate', () => {
308
293
 
309
294
  const value = await User[selectMethod]('data').take();
310
295
 
311
- const eq: AssertEqual<
296
+ assertType<
312
297
  typeof value,
313
298
  { json_agg: ({ name: string; tags: string[] } | null)[] | null }
314
- > = true;
315
- expect(eq).toBe(true);
299
+ >();
316
300
 
317
301
  expect(value).toEqual({ [functionName]: [data] });
318
302
  });
@@ -390,8 +374,7 @@ describe('aggregate', () => {
390
374
  it('should return null when no records', async () => {
391
375
  const value = await User[method as 'jsonObjectAgg']({ alias: 'name' });
392
376
 
393
- const eq: AssertEqual<typeof value, { alias: string } | null> = true;
394
- expect(eq).toBe(true);
377
+ assertType<typeof value, { alias: string } | null>();
395
378
 
396
379
  expect(value).toBe(null);
397
380
  });
@@ -401,8 +384,7 @@ describe('aggregate', () => {
401
384
 
402
385
  const value = await User[method as 'jsonObjectAgg']({ alias: 'name' });
403
386
 
404
- const eq: AssertEqual<typeof value, { alias: string } | null> = true;
405
- expect(eq).toBe(true);
387
+ assertType<typeof value, { alias: string } | null>();
406
388
 
407
389
  expect(value).toEqual({ alias: 'name' });
408
390
  });
@@ -414,11 +396,10 @@ describe('aggregate', () => {
414
396
  it('should select null when no record', async () => {
415
397
  const value = await User[selectMethod]({ alias: 'name' }).take();
416
398
 
417
- const eq: AssertEqual<
399
+ assertType<
418
400
  typeof value,
419
401
  { json_object_agg: { alias: string } | null }
420
- > = true;
421
- expect(eq).toBe(true);
402
+ >();
422
403
 
423
404
  expect(value).toEqual({ [functionName]: null });
424
405
  });
@@ -428,11 +409,10 @@ describe('aggregate', () => {
428
409
 
429
410
  const value = await User[selectMethod]({ alias: 'name' }).take();
430
411
 
431
- const eq: AssertEqual<
412
+ assertType<
432
413
  typeof value,
433
414
  { json_object_agg: { alias: string } | null }
434
- > = true;
435
- expect(eq).toBe(true);
415
+ >();
436
416
 
437
417
  expect(value).toEqual({ [functionName]: { alias: 'name' } });
438
418
  });
@@ -497,8 +477,7 @@ describe('aggregate', () => {
497
477
  it('should return null when no records', async () => {
498
478
  const value = await User.stringAgg('name', ', ');
499
479
 
500
- const eq: AssertEqual<typeof value, string | null> = true;
501
- expect(eq).toBe(true);
480
+ assertType<typeof value, string | null>();
502
481
 
503
482
  expect(value).toBe(null);
504
483
  });
@@ -508,8 +487,7 @@ describe('aggregate', () => {
508
487
 
509
488
  const value = await User.stringAgg('name', ', ');
510
489
 
511
- const eq: AssertEqual<typeof value, string | null> = true;
512
- expect(eq).toBe(true);
490
+ assertType<typeof value, string | null>();
513
491
 
514
492
  expect(value).toEqual('name, name');
515
493
  });
@@ -518,9 +496,7 @@ describe('aggregate', () => {
518
496
  it('should select null when no record', async () => {
519
497
  const value = await User.selectStringAgg('name', ', ').take();
520
498
 
521
- const eq: AssertEqual<typeof value, { string_agg: string | null }> =
522
- true;
523
- expect(eq).toBe(true);
499
+ assertType<typeof value, { string_agg: string | null }>();
524
500
 
525
501
  expect(value).toEqual({ string_agg: null });
526
502
  });
@@ -530,9 +506,7 @@ describe('aggregate', () => {
530
506
 
531
507
  const value = await User.selectStringAgg('name', ', ').take();
532
508
 
533
- const eq: AssertEqual<typeof value, { string_agg: string | null }> =
534
- true;
535
- expect(eq).toBe(true);
509
+ assertType<typeof value, { string_agg: string | null }>();
536
510
 
537
511
  expect(value).toEqual({ string_agg: 'name, name' });
538
512
  });
@@ -1,5 +1,5 @@
1
1
  import {
2
- AssertEqual,
2
+ assertType,
3
3
  expectQueryNotMutated,
4
4
  expectSql,
5
5
  Profile,
@@ -45,8 +45,7 @@ describe('delete', () => {
45
45
  const result = await query;
46
46
  expect(result).toBe(id);
47
47
 
48
- const eq: AssertEqual<typeof result, number> = true;
49
- expect(eq).toBe(true);
48
+ assertType<typeof result, number>();
50
49
 
51
50
  expectQueryNotMutated(q);
52
51
  });
@@ -66,8 +65,7 @@ describe('delete', () => {
66
65
  const result = await query;
67
66
  expect(result).toBe(rowsCount);
68
67
 
69
- const eq: AssertEqual<typeof result, number> = true;
70
- expect(eq).toBe(true);
68
+ assertType<typeof result, number>();
71
69
 
72
70
  expectQueryNotMutated(q);
73
71
  });
@@ -82,8 +80,7 @@ describe('delete', () => {
82
80
  [1],
83
81
  );
84
82
 
85
- const eq: AssertEqual<Awaited<typeof query>, typeof User['type'][]> = true;
86
- expect(eq).toBe(true);
83
+ assertType<Awaited<typeof query>, typeof User['type'][]>();
87
84
 
88
85
  expectQueryNotMutated(q);
89
86
  });
@@ -98,11 +95,7 @@ describe('delete', () => {
98
95
  [1],
99
96
  );
100
97
 
101
- const eq: AssertEqual<
102
- Awaited<typeof query>,
103
- { id: number; name: string }[]
104
- > = true;
105
- expect(eq).toBe(true);
98
+ assertType<Awaited<typeof query>, { id: number; name: string }[]>();
106
99
 
107
100
  expectQueryNotMutated(q);
108
101
  });
@@ -127,8 +120,7 @@ describe('delete', () => {
127
120
  [1],
128
121
  );
129
122
 
130
- const eq: AssertEqual<Awaited<typeof query>, typeof User['type'][]> = true;
131
- expect(eq).toBe(true);
123
+ assertType<Awaited<typeof query>, typeof User['type'][]>();
132
124
 
133
125
  expectQueryNotMutated(q);
134
126
  });
@@ -1,4 +1,4 @@
1
- import { AssertEqual, User, userData, useTestDatabase } from '../test-utils';
1
+ import { assertType, User, userData, useTestDatabase } from '../test-utils';
2
2
  import { NumberColumn } from '../columnSchema';
3
3
  import { NotFoundError } from '../errors';
4
4
  import { raw } from '../common';
@@ -12,8 +12,7 @@ describe('get', () => {
12
12
 
13
13
  const received = await User.get('id');
14
14
 
15
- const eq: AssertEqual<typeof received, number> = true;
16
- expect(eq).toBe(true);
15
+ assertType<typeof received, number>();
17
16
 
18
17
  expect(received).toBe(id);
19
18
  });
@@ -21,8 +20,7 @@ describe('get', () => {
21
20
  it('should select raw and return a single value', async () => {
22
21
  const received = await User.get(raw<NumberColumn>('count(*)::int'));
23
22
 
24
- const eq: AssertEqual<typeof received, number> = true;
25
- expect(eq).toBe(true);
23
+ assertType<typeof received, number>();
26
24
 
27
25
  expect(received).toBe(0);
28
26
  });
@@ -38,8 +36,7 @@ describe('get', () => {
38
36
 
39
37
  const received = await User.getOptional('id');
40
38
 
41
- const eq: AssertEqual<typeof received, number | undefined> = true;
42
- expect(eq).toBe(true);
39
+ assertType<typeof received, number | undefined>();
43
40
 
44
41
  expect(received).toBe(id);
45
42
  });
@@ -49,16 +46,14 @@ describe('get', () => {
49
46
  raw<NumberColumn>('count(*)::int'),
50
47
  );
51
48
 
52
- const eq: AssertEqual<typeof received, number | undefined> = true;
53
- expect(eq).toBe(true);
49
+ assertType<typeof received, number | undefined>();
54
50
 
55
51
  expect(received).toBe(0);
56
52
  });
57
53
 
58
54
  it('should return undefined if not found', async () => {
59
55
  const value = await User.getOptional('id');
60
- const eq: AssertEqual<typeof value, number | undefined> = true;
61
- expect(eq).toBe(true);
56
+ assertType<typeof value, number | undefined>();
62
57
 
63
58
  expect(value).toBe(undefined);
64
59
  });
@@ -1,5 +1,5 @@
1
1
  import {
2
- AssertEqual,
2
+ assertType,
3
3
  expectQueryNotMutated,
4
4
  expectSql,
5
5
  User,
@@ -28,8 +28,7 @@ describe('insert functions', () => {
28
28
  `,
29
29
  );
30
30
 
31
- const eq: AssertEqual<Awaited<typeof query>, number> = true;
32
- expect(eq).toBe(true);
31
+ assertType<Awaited<typeof query>, number>();
33
32
 
34
33
  expectQueryNotMutated(q);
35
34
  });
@@ -52,8 +51,7 @@ describe('insert functions', () => {
52
51
  const result = await query;
53
52
  expect(result).toBe(1);
54
53
 
55
- const eq: AssertEqual<typeof result, number> = true;
56
- expect(eq).toBe(true);
54
+ assertType<typeof result, number>();
57
55
 
58
56
  const inserted = await User.take();
59
57
  expect(inserted).toMatchObject(userData);
@@ -76,8 +74,7 @@ describe('insert functions', () => {
76
74
  );
77
75
 
78
76
  const result = await query;
79
- const eq: AssertEqual<typeof result, number> = true;
80
- expect(eq).toBe(true);
77
+ assertType<typeof result, number>();
81
78
 
82
79
  expect(typeof result).toBe('number');
83
80
 
@@ -99,8 +96,7 @@ describe('insert functions', () => {
99
96
  );
100
97
 
101
98
  const result = await query;
102
- const eq: AssertEqual<typeof result, { id: number; name: string }> = true;
103
- expect(eq).toBe(true);
99
+ assertType<typeof result, { id: number; name: string }>();
104
100
 
105
101
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
106
102
  const { password, ...other } = userData;
@@ -124,8 +120,7 @@ describe('insert functions', () => {
124
120
  );
125
121
 
126
122
  const result = await query;
127
- const eq: AssertEqual<typeof result, typeof User['type']> = true;
128
- expect(eq).toBe(true);
123
+ assertType<typeof result, typeof User['type']>();
129
124
 
130
125
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
131
126
  const { password, ...other } = userData;
@@ -181,8 +176,7 @@ describe('insert functions', () => {
181
176
  const result = await query;
182
177
  expect(result).toBe(2);
183
178
 
184
- const eq: AssertEqual<typeof result, number> = true;
185
- expect(eq).toBe(true);
179
+ assertType<typeof result, number>();
186
180
 
187
181
  const inserted = await User.all();
188
182
  inserted.forEach((item, i) => {
@@ -218,9 +212,7 @@ describe('insert functions', () => {
218
212
  );
219
213
 
220
214
  const result = await query;
221
- const eq: AssertEqual<typeof result, { id: number; name: string }[]> =
222
- true;
223
- expect(eq).toBe(true);
215
+ assertType<typeof result, { id: number; name: string }[]>();
224
216
 
225
217
  const inserted = await User.all();
226
218
  inserted.forEach((item, i) => {
@@ -260,8 +252,7 @@ describe('insert functions', () => {
260
252
  expect(item).toMatchObject(arr[i]);
261
253
  });
262
254
 
263
- const eq: AssertEqual<typeof result, typeof User['type'][]> = true;
264
- expect(eq).toBe(true);
255
+ assertType<typeof result, typeof User['type'][]>();
265
256
 
266
257
  const inserted = await User.all();
267
258
  inserted.forEach((item, i) => {
@@ -503,8 +494,7 @@ describe('insert functions', () => {
503
494
  const result = await User.create(userData);
504
495
  expect(result).toMatchObject(userData);
505
496
 
506
- const eq: AssertEqual<typeof result, typeof User.type> = true;
507
- expect(eq).toBe(true);
497
+ assertType<typeof result, typeof User.type>();
508
498
  });
509
499
 
510
500
  it('should return columns from select', async () => {
@@ -514,9 +504,7 @@ describe('insert functions', () => {
514
504
  name: userData.name,
515
505
  });
516
506
 
517
- const eq: AssertEqual<typeof result, { id: number; name: string }> =
518
- true;
519
- expect(eq).toBe(true);
507
+ assertType<typeof result, { id: number; name: string }>();
520
508
  });
521
509
  });
522
510
 
@@ -526,8 +514,7 @@ describe('insert functions', () => {
526
514
  expect(result[0]).toMatchObject(userData);
527
515
  expect(result[1]).toMatchObject(userData);
528
516
 
529
- const eq: AssertEqual<typeof result, typeof User.type[]> = true;
530
- expect(eq).toBe(true);
517
+ assertType<typeof result, typeof User.type[]>();
531
518
  });
532
519
 
533
520
  it('should return columns from select', async () => {
@@ -544,9 +531,7 @@ describe('insert functions', () => {
544
531
  name: userData.name,
545
532
  });
546
533
 
547
- const eq: AssertEqual<typeof result, { id: number; name: string }[]> =
548
- true;
549
- expect(eq).toBe(true);
534
+ assertType<typeof result, { id: number; name: string }[]>();
550
535
  });
551
536
  });
552
537
  });
@@ -1,5 +1,5 @@
1
1
  import {
2
- AssertEqual,
2
+ assertType,
3
3
  expectQueryNotMutated,
4
4
  expectSql,
5
5
  User,
@@ -71,11 +71,10 @@ describe('json methods', () => {
71
71
  const result = await query.take();
72
72
  expect(result.data).toEqual({ name: 'new value', tags: ['one'] });
73
73
 
74
- const eq: AssertEqual<
74
+ assertType<
75
75
  typeof result.data,
76
76
  { name: string; tags: string[] } | null
77
- > = true;
78
- expect(eq).toBe(true);
77
+ >();
79
78
 
80
79
  expectQueryNotMutated(q);
81
80
  });
@@ -99,11 +98,10 @@ describe('json methods', () => {
99
98
  const result = await query.take();
100
99
  expect(result.alias).toEqual({ name: 'new value', tags: ['one'] });
101
100
 
102
- const eq: AssertEqual<
101
+ assertType<
103
102
  typeof result.alias,
104
103
  { name: string; tags: string[] } | null
105
- > = true;
106
- expect(eq).toBe(true);
104
+ >();
107
105
 
108
106
  expectQueryNotMutated(q);
109
107
  });
@@ -134,11 +132,10 @@ describe('json methods', () => {
134
132
  tags: ['two', 'one'],
135
133
  });
136
134
 
137
- const eq: AssertEqual<
135
+ assertType<
138
136
  typeof result.data,
139
137
  { name: string; tags: string[] } | null
140
- > = true;
141
- expect(eq).toBe(true);
138
+ >();
142
139
 
143
140
  expectQueryNotMutated(q);
144
141
  });
@@ -161,11 +158,10 @@ describe('json methods', () => {
161
158
  const result = await query.take();
162
159
  expect(result.data).toEqual({ name: 'value', tags: ['two', 'one'] });
163
160
 
164
- const eq: AssertEqual<
161
+ assertType<
165
162
  typeof result.data,
166
163
  { name: string; tags: string[] } | null
167
- > = true;
168
- expect(eq).toBe(true);
164
+ >();
169
165
 
170
166
  expectQueryNotMutated(q);
171
167
  });
@@ -189,11 +185,10 @@ describe('json methods', () => {
189
185
  const result = await query.take();
190
186
  expect(result.alias).toEqual({ name: 'value', tags: ['one', 'two'] });
191
187
 
192
- const eq: AssertEqual<
188
+ assertType<
193
189
  typeof result.alias,
194
190
  { name: string; tags: string[] } | null
195
- > = true;
196
- expect(eq).toBe(true);
191
+ >();
197
192
 
198
193
  expectQueryNotMutated(q);
199
194
  });
@@ -221,11 +216,10 @@ describe('json methods', () => {
221
216
  const result = await query.take();
222
217
  expect(result.data).toEqual({ name: 'value', tags: ['tag'] });
223
218
 
224
- const eq: AssertEqual<
219
+ assertType<
225
220
  typeof result.data,
226
221
  { name: string; tags: string[] } | null
227
- > = true;
228
- expect(eq).toBe(true);
222
+ >();
229
223
 
230
224
  expectQueryNotMutated(q);
231
225
  });
@@ -247,11 +241,10 @@ describe('json methods', () => {
247
241
  const result = await query.take();
248
242
  expect(result.data).toEqual({ name: 'value', tags: [] });
249
243
 
250
- const eq: AssertEqual<
244
+ assertType<
251
245
  typeof result.data,
252
246
  { name: string; tags: string[] } | null
253
- > = true;
254
- expect(eq).toBe(true);
247
+ >();
255
248
 
256
249
  expectQueryNotMutated(q);
257
250
  });
@@ -271,11 +264,10 @@ describe('json methods', () => {
271
264
  const result = await query.take();
272
265
  expect(result.alias).toEqual({ name: 'value', tags: [] });
273
266
 
274
- const eq: AssertEqual<
267
+ assertType<
275
268
  typeof result.alias,
276
269
  { name: string; tags: string[] } | null
277
- > = true;
278
- expect(eq).toBe(true);
270
+ >();
279
271
 
280
272
  expectQueryNotMutated(q);
281
273
  });
@@ -300,11 +292,10 @@ describe('json methods', () => {
300
292
  const result = await query.take();
301
293
  expect(result.data).toEqual({ name: 'value', tags: [] });
302
294
 
303
- const eq: AssertEqual<
295
+ assertType<
304
296
  typeof result.data,
305
297
  { name: string; tags: string[] } | null
306
- > = true;
307
- expect(eq).toBe(true);
298
+ >();
308
299
 
309
300
  expectQueryNotMutated(q);
310
301
  });
@@ -332,8 +323,7 @@ describe('json methods', () => {
332
323
  const result = await query.take();
333
324
  expect(result.name).toBe('value');
334
325
 
335
- const eq: AssertEqual<typeof result.name, string> = true;
336
- expect(eq).toBe(true);
326
+ assertType<typeof result.name, string>();
337
327
 
338
328
  expectQueryNotMutated(q);
339
329
  });
@@ -388,8 +378,7 @@ describe('json methods', () => {
388
378
  const result = await query.take();
389
379
  expect(result.tags).toEqual(['tag']);
390
380
 
391
- const eq: AssertEqual<typeof result.tags, string[]> = true;
392
- expect(eq).toBe(true);
381
+ assertType<typeof result.tags, string[]>();
393
382
 
394
383
  expectQueryNotMutated(q);
395
384
  });
@@ -0,0 +1,12 @@
1
+ import { db } from '../test-utils';
2
+
3
+ describe('then', () => {
4
+ describe('catch', () => {
5
+ it.only('should catch error', (done) => {
6
+ db('kokoko').catch((err) => {
7
+ expect(err.message).toBe(`relation "kokoko" does not exist`);
8
+ done();
9
+ });
10
+ });
11
+ });
12
+ });
@@ -43,6 +43,14 @@ export class Then {
43
43
  return then(this, resolve, reject);
44
44
  }
45
45
  }
46
+
47
+ async catch<Result>(
48
+ this: Query,
49
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
50
+ fn: (reason: any) => Result | PromiseLike<Result>,
51
+ ): Promise<Result> {
52
+ return this.then(undefined, fn);
53
+ }
46
54
  }
47
55
 
48
56
  export const handleResult: CommonQueryData['handleResult'] = async (