pqb 0.7.13 → 0.8.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 (91) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/index.d.ts +618 -563
  3. package/dist/index.esm.js +1011 -402
  4. package/dist/index.esm.js.map +1 -1
  5. package/dist/index.js +1014 -401
  6. package/dist/index.js.map +1 -1
  7. package/package.json +1 -1
  8. package/src/columnSchema/array.test.ts +67 -0
  9. package/src/columnSchema/array.ts +39 -13
  10. package/src/columnSchema/boolean.test.ts +17 -0
  11. package/src/columnSchema/boolean.ts +5 -1
  12. package/src/columnSchema/columnType.test.ts +230 -107
  13. package/src/columnSchema/columnType.ts +198 -28
  14. package/src/columnSchema/columnTypes.ts +28 -15
  15. package/src/columnSchema/columnsSchema.ts +6 -4
  16. package/src/columnSchema/commonMethods.ts +11 -4
  17. package/src/columnSchema/dateTime.test.ts +298 -0
  18. package/src/columnSchema/dateTime.ts +59 -2
  19. package/src/columnSchema/enum.test.ts +33 -0
  20. package/src/columnSchema/enum.ts +11 -1
  21. package/src/columnSchema/json/array.test.ts +21 -0
  22. package/src/columnSchema/json/array.ts +27 -13
  23. package/src/columnSchema/json/discriminatedUnion.test.ts +32 -0
  24. package/src/columnSchema/json/discriminatedUnion.ts +17 -2
  25. package/src/columnSchema/json/enum.test.ts +9 -0
  26. package/src/columnSchema/json/enum.ts +9 -1
  27. package/src/columnSchema/json/index.ts +19 -19
  28. package/src/columnSchema/json/instanceOf.test.ts +8 -0
  29. package/src/columnSchema/json/instanceOf.ts +4 -1
  30. package/src/columnSchema/json/intersection.test.ts +19 -0
  31. package/src/columnSchema/json/intersection.ts +9 -1
  32. package/src/columnSchema/json/lazy.test.ts +22 -0
  33. package/src/columnSchema/json/lazy.ts +22 -1
  34. package/src/columnSchema/json/literal.test.ts +7 -0
  35. package/src/columnSchema/json/literal.ts +12 -1
  36. package/src/columnSchema/json/map.test.ts +10 -0
  37. package/src/columnSchema/json/map.ts +21 -1
  38. package/src/columnSchema/json/nativeEnum.test.ts +10 -0
  39. package/src/columnSchema/json/nativeEnum.ts +4 -1
  40. package/src/columnSchema/json/nullable.test.ts +18 -0
  41. package/src/columnSchema/json/nullish.test.ts +18 -0
  42. package/src/columnSchema/json/object.test.ts +77 -0
  43. package/src/columnSchema/json/object.ts +31 -3
  44. package/src/columnSchema/json/optional.test.ts +18 -0
  45. package/src/columnSchema/json/record.test.ts +14 -0
  46. package/src/columnSchema/json/record.ts +12 -1
  47. package/src/columnSchema/json/scalarTypes.test.ts +133 -0
  48. package/src/columnSchema/json/scalarTypes.ts +90 -1
  49. package/src/columnSchema/json/set.test.ts +29 -0
  50. package/src/columnSchema/json/set.ts +26 -7
  51. package/src/columnSchema/json/tuple.test.ts +17 -0
  52. package/src/columnSchema/json/tuple.ts +16 -1
  53. package/src/columnSchema/json/typeBase.test.ts +123 -0
  54. package/src/columnSchema/json/typeBase.ts +52 -13
  55. package/src/columnSchema/json/union.test.ts +10 -0
  56. package/src/columnSchema/json/union.ts +18 -1
  57. package/src/columnSchema/json.test.ts +17 -0
  58. package/src/columnSchema/json.ts +10 -2
  59. package/src/columnSchema/number.test.ts +176 -0
  60. package/src/columnSchema/number.ts +48 -1
  61. package/src/columnSchema/string.test.ts +412 -0
  62. package/src/columnSchema/string.ts +126 -15
  63. package/src/columnSchema/timestamps.test.ts +6 -6
  64. package/src/columnSchema/virtual.ts +4 -0
  65. package/src/db.ts +1 -1
  66. package/src/query.ts +1 -1
  67. package/src/queryMethods/create.ts +6 -6
  68. package/src/queryMethods/for.ts +3 -3
  69. package/src/queryMethods/having.ts +1 -1
  70. package/src/queryMethods/join.ts +4 -4
  71. package/src/queryMethods/json.ts +1 -1
  72. package/src/queryMethods/queryMethods.ts +2 -2
  73. package/src/queryMethods/select.ts +3 -3
  74. package/src/queryMethods/update.ts +17 -17
  75. package/src/queryMethods/where.test.ts +1 -1
  76. package/src/queryMethods/where.ts +4 -4
  77. package/src/relations.ts +1 -1
  78. package/src/sql/aggregate.ts +2 -2
  79. package/src/sql/copy.ts +3 -3
  80. package/src/sql/delete.ts +5 -5
  81. package/src/sql/fromAndAs.ts +4 -4
  82. package/src/sql/having.ts +7 -7
  83. package/src/sql/insert.ts +5 -5
  84. package/src/sql/join.ts +16 -16
  85. package/src/sql/select.ts +6 -6
  86. package/src/sql/toSql.ts +24 -24
  87. package/src/sql/update.ts +4 -4
  88. package/src/sql/where.ts +18 -18
  89. package/src/utils.test.ts +9 -0
  90. package/src/utils.ts +3 -0
  91. package/src/columnSchema/columnTypes.test.ts +0 -527
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pqb",
3
- "version": "0.7.13",
3
+ "version": "0.8.1",
4
4
  "description": "Postgres query builder",
5
5
  "homepage": "https://orchid-orm.netlify.app/guide/query-builder-setup.html",
6
6
  "repository": {
@@ -0,0 +1,67 @@
1
+ import { assertType, db } from '../test-utils/test-utils';
2
+ import { ArrayColumn } from './array';
3
+ import { IntegerColumn } from './number';
4
+
5
+ describe('array column', () => {
6
+ describe('array', () => {
7
+ it('should output nested array of numbers', async () => {
8
+ const result = await db.get(
9
+ db.raw(
10
+ (t) => new ArrayColumn(new ArrayColumn(t.integer())),
11
+ `'{{1, 2, 3}, {4, 5, 6}}'::integer[][]`,
12
+ ),
13
+ );
14
+ expect(result).toEqual([
15
+ [1, 2, 3],
16
+ [4, 5, 6],
17
+ ]);
18
+
19
+ assertType<typeof result, number[][]>();
20
+ });
21
+
22
+ it('should output nested array of strings', async () => {
23
+ const result = await db.get(
24
+ db.raw(
25
+ (t) => new ArrayColumn(new ArrayColumn(t.text())),
26
+ `'{{"a", "b"}, {"c", "d"}}'::text[][]`,
27
+ ),
28
+ );
29
+ expect(result).toEqual([
30
+ ['a', 'b'],
31
+ ['c', 'd'],
32
+ ]);
33
+
34
+ assertType<typeof result, string[][]>();
35
+ });
36
+
37
+ it('should output nested array of booleans', async () => {
38
+ const result = await db.get(
39
+ db.raw(
40
+ (t) => new ArrayColumn(new ArrayColumn(t.boolean())),
41
+ `'{{true}, {false}}'::text[][]`,
42
+ ),
43
+ );
44
+ expect(result).toEqual([[true], [false]]);
45
+
46
+ assertType<typeof result, boolean[][]>();
47
+ });
48
+
49
+ it('should have toCode', async () => {
50
+ const column = new ArrayColumn(new IntegerColumn());
51
+ expect(column.toCode('t')).toEqual(['t.array(', 't.integer()', ')']);
52
+
53
+ expect(column.nonEmpty().toCode('t')).toEqual([
54
+ 't.array(',
55
+ 't.integer()',
56
+ ')',
57
+ '.nonEmpty()',
58
+ ]);
59
+
60
+ expect(column.min(1).max(10).length(15).toCode('t')).toEqual([
61
+ 't.array(',
62
+ 't.integer()',
63
+ ').min(1).max(10).length(15)',
64
+ ]);
65
+ });
66
+ });
67
+ });
@@ -1,13 +1,15 @@
1
- import { ColumnData, ColumnType } from './columnType';
1
+ import { Code, columnCode, ColumnData, ColumnType } from './columnType';
2
2
  import { Operators } from '../columnsOperators';
3
3
  import { assignMethodsToClass } from './utils';
4
4
  import { arrayMethods } from './commonMethods';
5
+ import { toArray } from '../utils';
5
6
 
6
7
  export type ArrayData<Item extends ColumnType> = ColumnData & {
7
8
  item: Item;
8
9
  min?: number;
9
10
  max?: number;
10
11
  length?: number;
12
+ isNonEmpty?: true;
11
13
  };
12
14
 
13
15
  type ArrayMethods = typeof arrayMethods;
@@ -34,18 +36,42 @@ export class ArrayColumn<Item extends ColumnType> extends ColumnType<
34
36
  return `${this.data.item.toSQL()}[]`;
35
37
  }
36
38
 
37
- parseFn = (input: unknown) => {
38
- const entries: unknown[] = [];
39
- parseArray(
40
- input as string,
41
- 0,
42
- (input as string).length,
43
- entries,
44
- false,
45
- this.data.item,
46
- );
47
- return entries;
48
- };
39
+ toCode(this: ArrayColumn<Item>, t: string): Code {
40
+ let code = ')';
41
+
42
+ const { min, max, length, isNonEmpty } = this.data;
43
+
44
+ if (min !== undefined && (!isNonEmpty || (isNonEmpty && min !== 1)))
45
+ code += `.min(${min})`;
46
+
47
+ if (max !== undefined) code += `.max(${max})`;
48
+
49
+ if (length !== undefined) code += `.length(${length})`;
50
+
51
+ return columnCode(this, t, [
52
+ 't.array(',
53
+ ...toArray(this.data.item.toCode(t)),
54
+ code,
55
+ ]);
56
+ }
57
+
58
+ parseFn = Object.assign(
59
+ (input: unknown) => {
60
+ const entries: unknown[] = [];
61
+ parseArray(
62
+ input as string,
63
+ 0,
64
+ (input as string).length,
65
+ entries,
66
+ false,
67
+ this.data.item,
68
+ );
69
+ return entries;
70
+ },
71
+ {
72
+ hideFromCode: true,
73
+ },
74
+ );
49
75
  }
50
76
 
51
77
  const parseArray = (
@@ -0,0 +1,17 @@
1
+ import { assertType, db } from '../test-utils/test-utils';
2
+ import { BooleanColumn } from './boolean';
3
+
4
+ describe('boolean column', () => {
5
+ it('should output boolean', async () => {
6
+ const result = await db.get(db.raw(() => new BooleanColumn(), `true`));
7
+ expect(result).toBe(true);
8
+
9
+ assertType<typeof result, boolean>();
10
+ });
11
+
12
+ it('should have toCode', () => {
13
+ const column = new BooleanColumn();
14
+
15
+ expect(column.toCode('t')).toBe('t.boolean()');
16
+ });
17
+ });
@@ -1,4 +1,4 @@
1
- import { ColumnType } from './columnType';
1
+ import { Code, columnCode, ColumnType } from './columnType';
2
2
  import { Operators } from '../columnsOperators';
3
3
 
4
4
  // 1 byte, true or false
@@ -9,5 +9,9 @@ export class BooleanColumn extends ColumnType<
9
9
  dataType = 'boolean' as const;
10
10
  operators = Operators.boolean;
11
11
 
12
+ toCode(t: string): Code {
13
+ return columnCode(this, t, `${t}.boolean()`);
14
+ }
15
+
12
16
  parseItem = (input: string) => input[0] === 't';
13
17
  }
@@ -1,4 +1,4 @@
1
- import { ColumnType } from './columnType';
1
+ import { Code, columnCode, ColumnType } from './columnType';
2
2
  import { Operators } from '../columnsOperators';
3
3
  import {
4
4
  adapter,
@@ -11,6 +11,7 @@ import {
11
11
  } from '../test-utils/test-utils';
12
12
  import { createDb } from '../db';
13
13
  import { columnTypes } from './columnTypes';
14
+ import { IntegerColumn } from './number';
14
15
 
15
16
  describe('column base', () => {
16
17
  useTestDatabase();
@@ -18,6 +19,9 @@ describe('column base', () => {
18
19
  class Column extends ColumnType {
19
20
  dataType = 'test';
20
21
  operators = Operators.any;
22
+ toCode(t: string): Code {
23
+ return columnCode(this, t, `${t}.column()`);
24
+ }
21
25
  }
22
26
  const column = new Column();
23
27
 
@@ -26,6 +30,63 @@ describe('column base', () => {
26
30
  expect(column.isPrimaryKey).toBe(false);
27
31
  expect(column.primaryKey().isPrimaryKey).toBe(true);
28
32
  });
33
+
34
+ it('should have toCode', () => {
35
+ expect(column.primaryKey().toCode('t')).toEqual([
36
+ 't.column()',
37
+ '.primaryKey()',
38
+ ]);
39
+ });
40
+ });
41
+
42
+ describe('.foreignKey', () => {
43
+ it('should have toCode', () => {
44
+ class Table {
45
+ table = 'table';
46
+ columns = { shape: { column: new IntegerColumn() } };
47
+ }
48
+
49
+ expect(column.foreignKey(() => Table, 'column').toCode('t')).toEqual([
50
+ 't.column()',
51
+ '.foreignKey(',
52
+ '()=>Table',
53
+ `, 'column'`,
54
+ ')',
55
+ ]);
56
+
57
+ expect(column.foreignKey('table', 'column').toCode('t')).toEqual([
58
+ 't.column()',
59
+ '.foreignKey(',
60
+ `'table'`,
61
+ `, 'column'`,
62
+ ')',
63
+ ]);
64
+
65
+ expect(
66
+ column
67
+ .foreignKey('table', 'column', {
68
+ name: 'name',
69
+ match: 'FULL',
70
+ onUpdate: 'CASCADE',
71
+ onDelete: 'CASCADE',
72
+ })
73
+ .toCode('t'),
74
+ ).toEqual([
75
+ 't.column()',
76
+ '.foreignKey(',
77
+ `'table'`,
78
+ `, 'column'`,
79
+ ', {',
80
+ [
81
+ `name: 'name',`,
82
+ `match: 'FULL',`,
83
+ `onUpdate: 'CASCADE',`,
84
+ `onDelete: 'CASCADE',`,
85
+ ],
86
+ '}',
87
+ ')',
88
+ ]);
89
+ });
29
90
  });
30
91
 
31
92
  describe('.hidden', () => {
@@ -34,7 +95,11 @@ describe('column base', () => {
34
95
  expect(column.hidden().isHidden).toBe(true);
35
96
  });
36
97
 
37
- test('model with hidden column should omit from select it by default', () => {
98
+ it('should have toCode', () => {
99
+ expect(column.hidden().toCode('t')).toEqual(['t.column()', '.hidden()']);
100
+ });
101
+
102
+ test('table with hidden column should omit from select it by default', () => {
38
103
  const User = db('user', (t) => ({
39
104
  id: t.serial().primaryKey(),
40
105
  name: t.text(),
@@ -53,7 +118,7 @@ describe('column base', () => {
53
118
  );
54
119
  });
55
120
 
56
- test('model with hidden column still allows to select it', () => {
121
+ test('table with hidden column still allows to select it', () => {
57
122
  const User = db('user', (t) => ({
58
123
  id: t.serial().primaryKey(),
59
124
  name: t.text(),
@@ -79,9 +144,16 @@ describe('column base', () => {
79
144
  expect(column.isNullable).toBe(false);
80
145
  expect(column.nullable().isNullable).toBe(true);
81
146
  });
147
+
148
+ it('should have toCode', () => {
149
+ expect(column.nullable().toCode('t')).toEqual([
150
+ 't.column()',
151
+ '.nullable()',
152
+ ]);
153
+ });
82
154
  });
83
155
 
84
- describe('.encodeFn', () => {
156
+ describe('.encode', () => {
85
157
  it('should set a function to encode value for this column', () => {
86
158
  expect(column.encodeFn).toBe(undefined);
87
159
  const fn = (input: number) => input.toString();
@@ -89,9 +161,15 @@ describe('column base', () => {
89
161
  expect(withEncode.encodeFn).toBe(fn);
90
162
  assertType<typeof withEncode.inputType, number>();
91
163
  });
164
+
165
+ it('should have toCode', () => {
166
+ expect(
167
+ column.encode((input: number) => input.toString()).toCode('t'),
168
+ ).toEqual(['t.column()', '.encode((input)=>input.toString())']);
169
+ });
92
170
  });
93
171
 
94
- describe('.parseFn', () => {
172
+ describe('.parse', () => {
95
173
  it('should set a function to encode value for this column', () => {
96
174
  expect(column.parseFn).toBe(undefined);
97
175
  const fn = () => 123;
@@ -100,6 +178,13 @@ describe('column base', () => {
100
178
  assertType<typeof withEncode.type, number>();
101
179
  });
102
180
 
181
+ it('should have toCode', () => {
182
+ expect(column.parse((v) => parseInt(v as string)).toCode('t')).toEqual([
183
+ 't.column()',
184
+ '.parse((v)=>parseInt(v))',
185
+ ]);
186
+ });
187
+
103
188
  describe('parsing columns', () => {
104
189
  beforeEach(async () => {
105
190
  await User.create(userData);
@@ -156,6 +241,13 @@ describe('column base', () => {
156
241
  updatedAt: t.dateTimestamp(),
157
242
  }));
158
243
 
244
+ it('should have toCode', () => {
245
+ expect(column.as(columnTypes.integer()).toCode('t')).toEqual([
246
+ 't.column()',
247
+ '.as(t.integer())',
248
+ ]);
249
+ });
250
+
159
251
  it('should accept only column of same type and input type', () => {
160
252
  columnTypes
161
253
  .timestamp()
@@ -233,121 +325,152 @@ describe('column base', () => {
233
325
  });
234
326
  });
235
327
 
236
- describe('timestamp().asNumber()', () => {
237
- it('should parse and encode timestamp as a number', async () => {
238
- const UserWithNumberTimestamp = db('user', (t) => ({
239
- id: t.serial().primaryKey(),
240
- name: t.text(),
241
- password: t.text(),
242
- createdAt: t.timestamp().asNumber(),
243
- updatedAt: t.timestamp().asNumber(),
244
- }));
245
-
246
- const now = Date.now();
247
-
248
- const createQuery = UserWithNumberTimestamp.create({
249
- ...userData,
250
- createdAt: now,
251
- updatedAt: now,
252
- });
253
-
254
- expectSql(
255
- createQuery.toSql(),
256
- `
257
- INSERT INTO "user"("name", "password", "createdAt", "updatedAt")
258
- VALUES ($1, $2, $3, $4)
259
- RETURNING *
260
- `,
261
- [userData.name, userData.password, new Date(now), new Date(now)],
262
- );
263
-
264
- const { id } = await createQuery;
265
- const user = await UserWithNumberTimestamp.select(
266
- 'createdAt',
267
- 'updatedAt',
268
- ).find(id);
269
-
270
- assertType<typeof user, { createdAt: number; updatedAt: number }>();
271
-
272
- expect(typeof user.createdAt).toBe('number');
273
- expect(typeof user.updatedAt).toBe('number');
274
-
275
- const updateQuery = UserWithNumberTimestamp.find(id).update({
276
- createdAt: now,
277
- updatedAt: now,
278
- });
328
+ describe('.default', () => {
329
+ it('should have toCode', () => {
330
+ expect(column.default(123).toCode('t')).toEqual([
331
+ 't.column()',
332
+ '.default(123)',
333
+ ]);
334
+ });
335
+ });
279
336
 
280
- expectSql(
281
- updateQuery.toSql(),
282
- `
283
- UPDATE "user"
284
- SET "createdAt" = $1, "updatedAt" = $2
285
- WHERE "user"."id" = $3
286
- `,
287
- [new Date(now), new Date(now), id],
288
- );
337
+ describe('.index', () => {
338
+ it('should have toCode', () => {
339
+ expect(
340
+ column
341
+ .index({
342
+ expression: 'expression',
343
+ collate: 'collate',
344
+ operator: 'operator',
345
+ order: 'order',
346
+ name: 'name',
347
+ using: 'using',
348
+ include: 'include',
349
+ with: 'with',
350
+ tablespace: 'tablespace',
351
+ where: 'where',
352
+ })
353
+ .toCode('t'),
354
+ ).toEqual([
355
+ 't.column()',
356
+ '.index(',
357
+ '{',
358
+ [
359
+ `expression: 'expression',`,
360
+ `collate: 'collate',`,
361
+ `operator: 'operator',`,
362
+ `order: 'order',`,
363
+ `name: 'name',`,
364
+ `using: 'using',`,
365
+ `include: 'include',`,
366
+ `with: 'with',`,
367
+ `tablespace: 'tablespace',`,
368
+ `where: 'where',`,
369
+ ],
370
+ '}',
371
+ ')',
372
+ ]);
289
373
  });
290
374
  });
291
375
 
292
- describe('timestamp().asDate()', () => {
293
- it('should parse and encode timestamp as a number', async () => {
294
- columnTypes
295
- .text(0, 100)
296
- .encode((input: number) => input)
297
- .parse((text) => parseInt(text))
298
- .as(columnTypes.integer());
376
+ describe('unique', () => {
377
+ it('should have toCode', () => {
378
+ expect(column.unique().toCode('t')).toEqual([
379
+ 't.column()',
380
+ '.unique(',
381
+ ')',
382
+ ]);
383
+ });
384
+ });
299
385
 
300
- const UserWithNumberTimestamp = db('user', (t) => ({
301
- id: t.serial().primaryKey(),
302
- name: t.text(),
303
- password: t.text(),
304
- createdAt: columnTypes.timestamp().asDate(),
305
- updatedAt: columnTypes.timestamp().asDate(),
306
- }));
386
+ describe('comment', () => {
387
+ it('should have toCode', () => {
388
+ expect(column.comment('comment').toCode('t')).toEqual([
389
+ 't.column()',
390
+ `.comment('comment')`,
391
+ ]);
392
+ });
393
+ });
307
394
 
308
- const now = new Date();
395
+ describe('validationDefault', () => {
396
+ it('should have toCode', () => {
397
+ expect(column.validationDefault('value').toCode('t')).toEqual([
398
+ 't.column()',
399
+ `.validationDefault('value')`,
400
+ ]);
401
+
402
+ expect(column.validationDefault(123).toCode('t')).toEqual([
403
+ 't.column()',
404
+ `.validationDefault(123)`,
405
+ ]);
406
+
407
+ expect(column.validationDefault(() => 'value').toCode('t')).toEqual([
408
+ 't.column()',
409
+ `.validationDefault(()=>'value')`,
410
+ ]);
411
+ });
412
+ });
309
413
 
310
- const createQuery = UserWithNumberTimestamp.create({
311
- ...userData,
312
- createdAt: now,
313
- updatedAt: now,
314
- });
414
+ describe('compression', () => {
415
+ it('should have toCode', () => {
416
+ expect(column.compression('compression').toCode('t')).toEqual([
417
+ 't.column()',
418
+ `.compression('compression')`,
419
+ ]);
420
+ });
421
+ });
315
422
 
316
- expectSql(
317
- createQuery.toSql(),
318
- `
319
- INSERT INTO "user"("name", "password", "createdAt", "updatedAt")
320
- VALUES ($1, $2, $3, $4)
321
- RETURNING *
322
- `,
323
- [userData.name, userData.password, new Date(now), new Date(now)],
324
- );
423
+ describe('collate', () => {
424
+ it('should have toCode', () => {
425
+ expect(column.collate('collate').toCode('t')).toEqual([
426
+ 't.column()',
427
+ `.collate('collate')`,
428
+ ]);
429
+ });
430
+ });
325
431
 
326
- const { id } = await createQuery;
327
- const user = await UserWithNumberTimestamp.select(
328
- 'createdAt',
329
- 'updatedAt',
330
- ).find(id);
432
+ describe('modifyQuery', () => {
433
+ it('should have toCode', () => {
434
+ expect(column.modifyQuery((table) => table).toCode('t')).toEqual([
435
+ 't.column()',
436
+ `.modifyQuery((table)=>table)`,
437
+ ]);
438
+ });
439
+ });
331
440
 
332
- assertType<typeof user, { createdAt: Date; updatedAt: Date }>();
441
+ describe('transform', () => {
442
+ it('should have toCode', () => {
443
+ expect(column.transform((s) => s).toCode('t')).toEqual([
444
+ 't.column()',
445
+ '.transform((s)=>s)',
446
+ ]);
447
+ });
448
+ });
333
449
 
334
- expect(user.createdAt).toBeInstanceOf(Date);
335
- expect(user.updatedAt).toBeInstanceOf(Date);
450
+ describe('to', () => {
451
+ it('should have toCode', () => {
452
+ expect(
453
+ column
454
+ .to((s) => parseInt(s as string), new IntegerColumn())
455
+ .toCode('t'),
456
+ ).toEqual(['t.column()', '.to((s)=>parseInt(s), ', 't.integer()', ')']);
457
+ });
458
+ });
336
459
 
337
- const updateQuery = UserWithNumberTimestamp.find(id).update({
338
- createdAt: now,
339
- updatedAt: now,
340
- });
460
+ describe('refine', () => {
461
+ it('should have toCode', () => {
462
+ expect(
463
+ column.refine((s) => (s as string).length > 0).toCode('t'),
464
+ ).toEqual(['t.column()', '.refine((s)=>s.length > 0)']);
465
+ });
466
+ });
341
467
 
342
- expectSql(
343
- updateQuery.toSql(),
344
- `
345
- UPDATE "user"
346
- SET "createdAt" = $1, "updatedAt" = $2
347
- WHERE "user"."id" = $3
348
- `,
349
- [now, now, id],
350
- );
468
+ describe('superRefine', () => {
469
+ it('should have toCode', () => {
470
+ expect(column.superRefine((s) => s).toCode('t')).toEqual([
471
+ 't.column()',
472
+ '.superRefine((s)=>s)',
473
+ ]);
351
474
  });
352
475
  });
353
476
  });