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
@@ -0,0 +1,176 @@
1
+ import { assertType, db } from '../test-utils/test-utils';
2
+ import {
3
+ BigIntColumn,
4
+ BigSerialColumn,
5
+ DecimalColumn,
6
+ DoublePrecisionColumn,
7
+ IntegerColumn,
8
+ NumberBaseColumn,
9
+ RealColumn,
10
+ SerialColumn,
11
+ SmallIntColumn,
12
+ SmallSerialColumn,
13
+ } from './number';
14
+
15
+ const testNumberColumnMethods = (type: NumberBaseColumn, name: string) => {
16
+ expect(type.lt(1).lte(2).gt(3).gte(4).multipleOf(5).toCode('t')).toBe(
17
+ `t.${name}().min(4).gt(3).max(2).lt(1).step(5)`,
18
+ );
19
+
20
+ expect(
21
+ type.positive().nonNegative().negative().nonPositive().toCode('t'),
22
+ ).toBe(`t.${name}().min(0).gt(0).max(0).lt(0)`);
23
+
24
+ expect(type.min(1).max(2).step(3).toCode('t')).toBe(
25
+ `t.${name}().min(1).max(2).step(3)`,
26
+ );
27
+ };
28
+
29
+ describe('number columns', () => {
30
+ describe('smallint', () => {
31
+ it('should output number', async () => {
32
+ const result = await db.get(
33
+ db.raw(() => new SmallIntColumn(), '1::smallint'),
34
+ );
35
+ expect(result).toBe(1);
36
+
37
+ assertType<typeof result, number>();
38
+ });
39
+
40
+ it('should have toCode', () => {
41
+ expect(new SmallIntColumn().toCode('t')).toBe('t.smallint()');
42
+
43
+ testNumberColumnMethods(new SmallIntColumn(), 'smallint');
44
+ });
45
+ });
46
+
47
+ describe('integer', () => {
48
+ it('should output number', async () => {
49
+ const result = await db.get(
50
+ db.raw(() => new IntegerColumn(), '1::integer'),
51
+ );
52
+ expect(result).toBe(1);
53
+
54
+ assertType<typeof result, number>();
55
+ });
56
+
57
+ it('should have toCode', () => {
58
+ expect(new IntegerColumn().toCode('t')).toBe('t.integer()');
59
+
60
+ testNumberColumnMethods(new IntegerColumn(), 'integer');
61
+ });
62
+ });
63
+
64
+ describe('bigint', () => {
65
+ it('should output string', async () => {
66
+ const result = await db.get(
67
+ db.raw(() => new BigIntColumn(), '1::bigint'),
68
+ );
69
+ expect(result).toBe('1');
70
+
71
+ assertType<typeof result, string>();
72
+ });
73
+
74
+ it('should have toCode', () => {
75
+ expect(new BigIntColumn().toCode('t')).toBe('t.bigint()');
76
+ });
77
+ });
78
+
79
+ describe('decimal', () => {
80
+ it('should output string', async () => {
81
+ const result = await db.get(
82
+ db.raw(() => new DecimalColumn(), '1::decimal'),
83
+ );
84
+ expect(result).toBe('1');
85
+
86
+ assertType<typeof result, string>();
87
+ });
88
+
89
+ it('should have toCode', () => {
90
+ expect(new DecimalColumn().toCode('t')).toBe('t.decimal()');
91
+ expect(new DecimalColumn(1).toCode('t')).toBe('t.decimal(1)');
92
+ expect(new DecimalColumn(1, 2).toCode('t')).toBe('t.decimal(1, 2)');
93
+ });
94
+ });
95
+
96
+ describe('real', () => {
97
+ it('should output number', async () => {
98
+ const result = await db.get(db.raw(() => new RealColumn(), '1::real'));
99
+ expect(result).toBe(1);
100
+
101
+ assertType<typeof result, number>();
102
+ });
103
+
104
+ it('should have toCode', () => {
105
+ expect(new RealColumn().toCode('t')).toBe('t.real()');
106
+
107
+ testNumberColumnMethods(new RealColumn(), 'real');
108
+ });
109
+ });
110
+
111
+ describe('doublePrecision', () => {
112
+ it('should output number', async () => {
113
+ const result = await db.get(
114
+ db.raw(() => new DoublePrecisionColumn(), '1::double precision'),
115
+ );
116
+ expect(result).toBe(1);
117
+
118
+ assertType<typeof result, string>();
119
+ });
120
+
121
+ it('should have toCode', () => {
122
+ expect(new DoublePrecisionColumn().toCode('t')).toBe(
123
+ 't.doublePrecision()',
124
+ );
125
+ });
126
+ });
127
+
128
+ describe('smallSerial', () => {
129
+ it('should output number', async () => {
130
+ const result = await db.get(
131
+ db.raw(() => new SmallSerialColumn(), '1::smallint'),
132
+ );
133
+ expect(result).toBe(1);
134
+
135
+ assertType<typeof result, number>();
136
+ });
137
+
138
+ it('should have toCode', () => {
139
+ expect(new SmallSerialColumn().toCode('t')).toBe('t.smallSerial()');
140
+
141
+ testNumberColumnMethods(new SmallSerialColumn(), 'smallSerial');
142
+ });
143
+ });
144
+
145
+ describe('serial', () => {
146
+ it('should output number', async () => {
147
+ const result = await db.get(
148
+ db.raw(() => new SerialColumn(), '1::integer'),
149
+ );
150
+ expect(result).toBe(1);
151
+
152
+ assertType<typeof result, number>();
153
+ });
154
+
155
+ it('should have toCode', () => {
156
+ expect(new SerialColumn().toCode('t')).toBe('t.serial()');
157
+
158
+ testNumberColumnMethods(new SerialColumn(), 'serial');
159
+ });
160
+ });
161
+
162
+ describe('bigSerial', () => {
163
+ it('should output string', async () => {
164
+ const result = await db.get(
165
+ db.raw(() => new BigSerialColumn(), '1::bigint'),
166
+ );
167
+ expect(result).toBe('1');
168
+
169
+ assertType<typeof result, string>();
170
+ });
171
+
172
+ it('should have toCode', () => {
173
+ expect(new BigSerialColumn().toCode('t')).toBe('t.bigSerial()');
174
+ });
175
+ });
176
+ });
@@ -1,5 +1,5 @@
1
1
  import { Operators } from '../columnsOperators';
2
- import { ColumnData, ColumnType } from './columnType';
2
+ import { Code, columnCode, ColumnData, ColumnType } from './columnType';
3
3
  import { joinTruthy } from '../utils';
4
4
  import { assignMethodsToClass } from './utils';
5
5
  import { numberTypeMethods } from './commonMethods';
@@ -13,6 +13,16 @@ export type BaseNumberData = ColumnData & {
13
13
  int?: boolean;
14
14
  };
15
15
 
16
+ const numberDataToCode = (data: NumberBaseColumn['data']) => {
17
+ let code = '';
18
+ if (data.gte !== undefined) code += `.min(${data.gte})`;
19
+ if (data.gt !== undefined) code += `.gt(${data.gt})`;
20
+ if (data.lte !== undefined) code += `.max(${data.lte})`;
21
+ if (data.lt !== undefined) code += `.lt(${data.lt})`;
22
+ if (data.multipleOf !== undefined) code += `.step(${data.multipleOf})`;
23
+ return code;
24
+ };
25
+
16
26
  export type NumberColumn = ColumnType<number>;
17
27
 
18
28
  export type NumberColumnData = BaseNumberData;
@@ -67,6 +77,15 @@ export class DecimalBaseColumn<
67
77
  } as DecimalColumnData & { precision: Precision; scale: Scale };
68
78
  }
69
79
 
80
+ toCode(t: string): Code {
81
+ const { precision, scale } = this.data;
82
+ return columnCode(
83
+ this,
84
+ t,
85
+ `${t}.decimal(${precision || ''}${scale ? `, ${scale}` : ''})`,
86
+ );
87
+ }
88
+
70
89
  toSQL() {
71
90
  const { precision, scale } = this.data;
72
91
 
@@ -85,17 +104,26 @@ export class DecimalBaseColumn<
85
104
  export class SmallIntColumn extends IntegerBaseColumn {
86
105
  dataType = 'smallint' as const;
87
106
  parseItem = parseInt;
107
+ toCode(t: string): Code {
108
+ return columnCode(this, t, `${t}.smallint()${numberDataToCode(this.data)}`);
109
+ }
88
110
  }
89
111
 
90
112
  // signed four-byte integer
91
113
  export class IntegerColumn extends IntegerBaseColumn {
92
114
  dataType = 'integer' as const;
93
115
  parseItem = parseInt;
116
+ toCode(t: string): Code {
117
+ return columnCode(this, t, `${t}.integer()${numberDataToCode(this.data)}`);
118
+ }
94
119
  }
95
120
 
96
121
  // signed eight-byte integer
97
122
  export class BigIntColumn extends NumberAsStringBaseColumn {
98
123
  dataType = 'bigint' as const;
124
+ toCode(t: string): Code {
125
+ return columnCode(this, t, `${t}.bigint()`);
126
+ }
99
127
  }
100
128
 
101
129
  // exact numeric of selectable precision
@@ -108,11 +136,17 @@ export class DecimalColumn<
108
136
  export class RealColumn extends NumberBaseColumn {
109
137
  dataType = 'real' as const;
110
138
  parseItem = parseFloat;
139
+ toCode(t: string): Code {
140
+ return columnCode(this, t, `${t}.real()${numberDataToCode(this.data)}`);
141
+ }
111
142
  }
112
143
 
113
144
  // double precision floating-point number (8 bytes)
114
145
  export class DoublePrecisionColumn extends NumberAsStringBaseColumn {
115
146
  dataType = 'double precision' as const;
147
+ toCode(t: string): Code {
148
+ return columnCode(this, t, `${t}.doublePrecision()`);
149
+ }
116
150
  }
117
151
 
118
152
  // autoincrementing two-byte integer
@@ -120,6 +154,13 @@ export class SmallSerialColumn extends IntegerBaseColumn {
120
154
  dataType = 'smallserial' as const;
121
155
  parseItem = parseInt;
122
156
  hasDefault = true as const;
157
+ toCode(t: string): Code {
158
+ return columnCode(
159
+ this,
160
+ t,
161
+ `${t}.smallSerial()${numberDataToCode(this.data)}`,
162
+ );
163
+ }
123
164
  }
124
165
 
125
166
  // autoincrementing four-byte integer
@@ -127,10 +168,16 @@ export class SerialColumn extends IntegerBaseColumn {
127
168
  dataType = 'serial' as const;
128
169
  parseItem = parseInt;
129
170
  hasDefault = true as const;
171
+ toCode(t: string): Code {
172
+ return columnCode(this, t, `${t}.serial()${numberDataToCode(this.data)}`);
173
+ }
130
174
  }
131
175
 
132
176
  // autoincrementing eight-byte integer
133
177
  export class BigSerialColumn extends NumberAsStringBaseColumn {
134
178
  dataType = 'bigserial' as const;
135
179
  hasDefault = true as const;
180
+ toCode(t: string): Code {
181
+ return columnCode(this, t, `${t}.bigSerial()`);
182
+ }
136
183
  }
@@ -0,0 +1,412 @@
1
+ import { assertType, db } from '../test-utils/test-utils';
2
+ import {
3
+ BitColumn,
4
+ BitVaryingColumn,
5
+ BoxColumn,
6
+ ByteaColumn,
7
+ CharColumn,
8
+ CidrColumn,
9
+ CircleColumn,
10
+ InetColumn,
11
+ LineColumn,
12
+ LsegColumn,
13
+ MacAddr8Column,
14
+ MacAddrColumn,
15
+ MoneyColumn,
16
+ PathColumn,
17
+ PointColumn,
18
+ PolygonColumn,
19
+ TextBaseColumn,
20
+ TextColumn,
21
+ TsQueryColumn,
22
+ TsVectorColumn,
23
+ UUIDColumn,
24
+ VarCharColumn,
25
+ XMLColumn,
26
+ } from './string';
27
+
28
+ const testNumberColumnMethods = (type: TextBaseColumn, name: string) => {
29
+ expect(type.nonEmpty().toCode('t')).toEqual([`t.${name}()`, '.nonEmpty()']);
30
+
31
+ expect(
32
+ type
33
+ .min(1)
34
+ .max(10)
35
+ .length(15)
36
+ .email()
37
+ .url()
38
+ .uuid()
39
+ .cuid()
40
+ .startsWith('start')
41
+ .endsWith('end')
42
+ .trim()
43
+ .toCode('t'),
44
+ ).toBe(
45
+ `t.${name}().min(1).max(10).length(15).email().url().uuid().cuid().startsWith('start').endsWith('end').trim()`,
46
+ );
47
+
48
+ expect(type.regex(/\d+/g).toCode('t')).toBe(`t.${name}().regex(/\\d+/g)`);
49
+ };
50
+
51
+ describe('string columns', () => {
52
+ describe('text', () => {
53
+ describe('varchar', () => {
54
+ it('should output string', async () => {
55
+ const result = await db.get(
56
+ db.raw(() => new VarCharColumn(4), `'text'::varchar(4)`),
57
+ );
58
+ expect(result).toBe('text');
59
+
60
+ assertType<typeof result, string>();
61
+ });
62
+
63
+ it('should have toCode', () => {
64
+ expect(new VarCharColumn().toCode('t')).toBe('t.varchar()');
65
+ expect(new VarCharColumn(5).toCode('t')).toBe('t.varchar(5)');
66
+
67
+ testNumberColumnMethods(new VarCharColumn(), 'varchar');
68
+ });
69
+ });
70
+
71
+ describe('char', () => {
72
+ it('should output string', async () => {
73
+ const result = await db.get(
74
+ db.raw(() => new CharColumn(4), `'text'::char(4)`),
75
+ );
76
+ expect(result).toBe('text');
77
+
78
+ assertType<typeof result, string>();
79
+ });
80
+
81
+ it('should have toCode', () => {
82
+ expect(new CharColumn().toCode('t')).toBe('t.char()');
83
+ expect(new CharColumn(5).toCode('t')).toBe('t.char(5)');
84
+
85
+ testNumberColumnMethods(new CharColumn(), 'char');
86
+ });
87
+ });
88
+
89
+ describe('text', () => {
90
+ it('should output string', async () => {
91
+ const result = await db.get(
92
+ db.raw(() => new TextColumn(), `'text'::text`),
93
+ );
94
+ expect(result).toBe('text');
95
+
96
+ assertType<typeof result, string>();
97
+ });
98
+
99
+ it('should have toCode', () => {
100
+ expect(new TextColumn().toCode('t')).toBe('t.text()');
101
+
102
+ testNumberColumnMethods(new TextColumn(), 'text');
103
+ });
104
+ });
105
+ });
106
+
107
+ describe('binary', () => {
108
+ describe('bytea', () => {
109
+ it('should output Buffer', async () => {
110
+ const result = await db.get(
111
+ db.raw(() => new ByteaColumn(), `'text'::bytea`),
112
+ );
113
+ expect(result instanceof Buffer).toBe(true);
114
+ expect(result.toString()).toBe('text');
115
+
116
+ assertType<typeof result, Buffer>();
117
+ });
118
+
119
+ it('should have toCode', () => {
120
+ expect(new ByteaColumn().toCode('t')).toBe('t.bytea()');
121
+ });
122
+ });
123
+ });
124
+
125
+ describe('geometric types', () => {
126
+ describe('point', () => {
127
+ it('should output string', async () => {
128
+ const result = await db.get(
129
+ db.raw(() => new PointColumn(), `'(1, 2)'::point`),
130
+ );
131
+ expect(result).toBe('(1,2)');
132
+
133
+ assertType<typeof result, string>();
134
+ });
135
+
136
+ it('should have toCode', () => {
137
+ expect(new PointColumn().toCode('t')).toBe('t.point()');
138
+ });
139
+ });
140
+
141
+ describe('line', () => {
142
+ it('should output string', async () => {
143
+ const result = await db.get(
144
+ db.raw(() => new LineColumn(), `'{1, 2, 3}'::line`),
145
+ );
146
+ expect(result).toBe('{1,2,3}');
147
+
148
+ assertType<typeof result, string>();
149
+ });
150
+
151
+ it('should have toCode', () => {
152
+ expect(new LineColumn().toCode('t')).toBe('t.line()');
153
+ });
154
+ });
155
+
156
+ describe('lseg', () => {
157
+ it('should output string', async () => {
158
+ const result = await db.get(
159
+ db.raw(() => new LsegColumn(), `'[(1, 2), (3, 4)]'::lseg`),
160
+ );
161
+ expect(result).toBe('[(1,2),(3,4)]');
162
+
163
+ assertType<typeof result, string>();
164
+ });
165
+
166
+ it('should have toCode', () => {
167
+ expect(new LsegColumn().toCode('t')).toBe('t.lseg()');
168
+ });
169
+ });
170
+
171
+ describe('box', () => {
172
+ it('should output string', async () => {
173
+ const result = await db.get(
174
+ db.raw(() => new BoxColumn(), `'((3, 4), (1, 2))'::box`),
175
+ );
176
+ expect(result).toBe('(3,4),(1,2)');
177
+
178
+ assertType<typeof result, string>();
179
+ });
180
+
181
+ it('should have toCode', () => {
182
+ expect(new BoxColumn().toCode('t')).toBe('t.box()');
183
+ });
184
+ });
185
+
186
+ describe('path', () => {
187
+ it('should output string', async () => {
188
+ const result = await db.get(
189
+ db.raw(() => new PathColumn(), `'((1, 2), (3, 4))'::path`),
190
+ );
191
+ expect(result).toBe('((1,2),(3,4))');
192
+
193
+ assertType<typeof result, string>();
194
+ });
195
+
196
+ it('should have toCode', () => {
197
+ expect(new PathColumn().toCode('t')).toBe('t.path()');
198
+ });
199
+ });
200
+
201
+ describe('polygon', () => {
202
+ it('should output string', async () => {
203
+ const result = await db.get(
204
+ db.raw(() => new PolygonColumn(), `'((1, 2), (3, 4))'::polygon`),
205
+ );
206
+ expect(result).toBe('((1,2),(3,4))');
207
+
208
+ assertType<typeof result, string>();
209
+ });
210
+
211
+ it('should have toCode', () => {
212
+ expect(new PolygonColumn().toCode('t')).toBe('t.polygon()');
213
+ });
214
+ });
215
+
216
+ describe('circle', () => {
217
+ it('should output string', async () => {
218
+ const result = await db.get(
219
+ db.raw(() => new CircleColumn(), `'<(1,2),3>'::circle`),
220
+ );
221
+ expect(result).toBe('<(1,2),3>');
222
+
223
+ assertType<typeof result, string>();
224
+ });
225
+
226
+ it('should have toCode', () => {
227
+ expect(new CircleColumn().toCode('t')).toBe('t.circle()');
228
+ });
229
+ });
230
+ });
231
+
232
+ describe('network address types', () => {
233
+ describe('cidr', () => {
234
+ it('should output string', async () => {
235
+ const result = await db.get(
236
+ db.raw(() => new CidrColumn(), `'192.168.100.128/25'::cidr`),
237
+ );
238
+ expect(result).toBe('192.168.100.128/25');
239
+
240
+ assertType<typeof result, string>();
241
+ });
242
+
243
+ it('should have toCode', () => {
244
+ expect(new CidrColumn().toCode('t')).toBe('t.cidr()');
245
+ });
246
+ });
247
+
248
+ describe('inet', () => {
249
+ it('should output string', async () => {
250
+ const result = await db.get(
251
+ db.raw(() => new InetColumn(), `'192.168.100.128/25'::inet`),
252
+ );
253
+ expect(result).toBe('192.168.100.128/25');
254
+
255
+ assertType<typeof result, string>();
256
+ });
257
+
258
+ it('should have toCode', () => {
259
+ expect(new InetColumn().toCode('t')).toBe('t.inet()');
260
+ });
261
+ });
262
+
263
+ describe('macaddr', () => {
264
+ it('should output string', async () => {
265
+ const result = await db.get(
266
+ db.raw(() => new MacAddrColumn(), `'08:00:2b:01:02:03'::macaddr`),
267
+ );
268
+ expect(result).toBe('08:00:2b:01:02:03');
269
+
270
+ assertType<typeof result, string>();
271
+ });
272
+
273
+ it('should have toCode', () => {
274
+ expect(new MacAddrColumn().toCode('t')).toBe('t.macaddr()');
275
+ });
276
+ });
277
+
278
+ describe('macaddr8', () => {
279
+ it('should output string', async () => {
280
+ const result = await db.get(
281
+ db.raw(
282
+ () => new MacAddr8Column(),
283
+ `'08:00:2b:ff:fe:01:02:03'::macaddr8`,
284
+ ),
285
+ );
286
+ expect(result).toBe('08:00:2b:ff:fe:01:02:03');
287
+
288
+ assertType<typeof result, string>();
289
+ });
290
+
291
+ it('should have toCode', () => {
292
+ expect(new MacAddr8Column().toCode('t')).toBe('t.macaddr8()');
293
+ });
294
+ });
295
+ });
296
+
297
+ describe('bit string types', () => {
298
+ describe('bit', () => {
299
+ it('should output string', async () => {
300
+ const result = await db.get(db.raw(() => new BitColumn(3), `B'101'`));
301
+ expect(result).toBe('101');
302
+
303
+ assertType<typeof result, string>();
304
+ });
305
+
306
+ it('should have toCode', () => {
307
+ expect(new BitColumn(5).toCode('t')).toBe('t.bit(5)');
308
+ });
309
+ });
310
+
311
+ describe('bit varying', () => {
312
+ it('should output string', async () => {
313
+ const result = await db.get(
314
+ db.raw(() => new BitVaryingColumn(), `'10101'::bit varying(5)`),
315
+ );
316
+ expect(result).toBe('10101');
317
+
318
+ assertType<typeof result, string>();
319
+ });
320
+
321
+ it('should have toCode', () => {
322
+ expect(new BitVaryingColumn().toCode('t')).toBe('t.bitVarying()');
323
+ expect(new BitVaryingColumn(5).toCode('t')).toBe('t.bitVarying(5)');
324
+ });
325
+ });
326
+ });
327
+
328
+ describe('text search types', () => {
329
+ describe('tsvector', () => {
330
+ it('should output string', async () => {
331
+ const result = await db.get(
332
+ db.raw(
333
+ () => new TsVectorColumn(),
334
+ `'a fat cat sat on a mat and ate a fat rat'::tsvector`,
335
+ ),
336
+ );
337
+ expect(result).toBe(
338
+ `'a' 'and' 'ate' 'cat' 'fat' 'mat' 'on' 'rat' 'sat'`,
339
+ );
340
+
341
+ assertType<typeof result, string>();
342
+ });
343
+
344
+ it('should have toCode', () => {
345
+ expect(new TsVectorColumn().toCode('t')).toBe('t.tsvector()');
346
+ });
347
+ });
348
+
349
+ describe('tsquery', () => {
350
+ it('should output string', async () => {
351
+ const result = await db.get(
352
+ db.raw(() => new TsQueryColumn(), `'fat & rat'::tsquery`),
353
+ );
354
+ expect(result).toBe(`'fat' & 'rat'`);
355
+
356
+ assertType<typeof result, string>();
357
+ });
358
+
359
+ it('should have toCode', () => {
360
+ expect(new TsQueryColumn().toCode('t')).toBe('t.tsquery()');
361
+ });
362
+ });
363
+ });
364
+
365
+ describe('uuid', () => {
366
+ it('should output string', async () => {
367
+ const result = await db.get(
368
+ db.raw(
369
+ () => new UUIDColumn(),
370
+ `'a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11'::uuid`,
371
+ ),
372
+ );
373
+ expect(result).toBe(`a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11`);
374
+
375
+ assertType<typeof result, string>();
376
+ });
377
+
378
+ it('should have toCode', () => {
379
+ expect(new UUIDColumn().toCode('t')).toBe('t.uuid()');
380
+ });
381
+ });
382
+
383
+ describe('xml', () => {
384
+ it('should output string', async () => {
385
+ const result = await db.get(
386
+ db.raw(() => new XMLColumn(), `'<xml></xml>'::xml`),
387
+ );
388
+ expect(result).toBe('<xml></xml>');
389
+
390
+ assertType<typeof result, string>();
391
+ });
392
+
393
+ it('should have toCode', () => {
394
+ expect(new XMLColumn().toCode('t')).toBe('t.xml()');
395
+ });
396
+ });
397
+
398
+ describe('money', () => {
399
+ it('should output number', async () => {
400
+ const result = await db.get(
401
+ db.raw(() => new MoneyColumn(), `'1234567890.42'::money`),
402
+ );
403
+ expect(result).toBe(1234567890.42);
404
+
405
+ assertType<typeof result, number>();
406
+ });
407
+
408
+ it('should have toCode', () => {
409
+ expect(new MoneyColumn().toCode('t')).toBe('t.money()');
410
+ });
411
+ });
412
+ });