pqb 0.0.1 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -0
- package/package.json +5 -2
- package/rollup.config.js +2 -34
- package/src/adapter.ts +11 -9
- package/src/columnSchema/array.ts +115 -3
- package/src/columnSchema/boolean.ts +4 -1
- package/src/columnSchema/columnType.test.ts +1 -1
- package/src/columnSchema/columnType.ts +227 -5
- package/src/columnSchema/columnTypes.test.ts +568 -0
- package/src/columnSchema/columnTypes.ts +136 -24
- package/src/columnSchema/columnsSchema.ts +1 -1
- package/src/columnSchema/commonMethods.ts +162 -80
- package/src/columnSchema/dateTime.ts +41 -10
- package/src/columnSchema/enum.ts +11 -6
- package/src/columnSchema/json/discriminatedUnion.ts +51 -42
- package/src/columnSchema/json/enum.ts +9 -9
- package/src/columnSchema/json/lazy.ts +5 -3
- package/src/columnSchema/json/nativeEnum.ts +1 -1
- package/src/columnSchema/json/nullish.ts +1 -1
- package/src/columnSchema/json/record.ts +14 -11
- package/src/columnSchema/json/scalarTypes.ts +17 -8
- package/src/columnSchema/json/set.ts +4 -4
- package/src/columnSchema/json/tuple.ts +17 -2
- package/src/columnSchema/json/typeBase.ts +11 -16
- package/src/columnSchema/json/union.ts +1 -1
- package/src/columnSchema/json.ts +4 -4
- package/src/columnSchema/number.ts +41 -30
- package/src/columnSchema/string.ts +28 -19
- package/src/columnSchema/utils.ts +0 -2
- package/src/{operators.test.ts → columnsOperators.test.ts} +0 -0
- package/src/{operators.ts → columnsOperators.ts} +0 -0
- package/src/common.ts +18 -16
- package/src/db.ts +10 -8
- package/src/index.ts +2 -7
- package/src/query.ts +2 -2
- package/src/queryMethods/aggregate.ts +6 -3
- package/src/queryMethods/get.ts +6 -3
- package/src/queryMethods/index.ts +22 -0
- package/src/queryMethods/join.ts +1 -1
- package/src/queryMethods/log.ts +5 -5
- package/src/queryMethods/select.test.ts +2 -2
- package/src/queryMethods/select.ts +10 -7
- package/src/queryMethods/then.ts +8 -19
- package/src/queryMethods/transaction.test.ts +2 -2
- package/src/queryMethods/transaction.ts +5 -5
- package/src/queryMethods/update.ts +11 -14
- package/src/sql/having.ts +1 -1
- package/src/test-utils.ts +3 -3
- package/src/utils.ts +3 -0
- package/dist/index.d.ts +0 -3630
- package/dist/index.esm.js +0 -4587
- package/dist/index.esm.js.map +0 -1
- package/dist/index.js +0 -4691
- package/dist/index.js.map +0 -1
- package/tsconfig.build.json +0 -6
|
@@ -0,0 +1,568 @@
|
|
|
1
|
+
import { AssertEqual, db } from '../test-utils';
|
|
2
|
+
import { raw } from '../common';
|
|
3
|
+
import { columnTypes } from './columnTypes';
|
|
4
|
+
import { TimeInterval } from './dateTime';
|
|
5
|
+
|
|
6
|
+
describe('column types', () => {
|
|
7
|
+
describe('numeric types', () => {
|
|
8
|
+
describe('smallint', () => {
|
|
9
|
+
it('should output number', async () => {
|
|
10
|
+
const result = await db.get(raw(columnTypes.smallint(), '1::smallint'));
|
|
11
|
+
expect(result).toBe(1);
|
|
12
|
+
|
|
13
|
+
const eq: AssertEqual<typeof result, number> = true;
|
|
14
|
+
expect(eq).toBe(true);
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
describe('integer', () => {
|
|
19
|
+
it('should output number', async () => {
|
|
20
|
+
const result = await db.get(raw(columnTypes.integer(), '1::integer'));
|
|
21
|
+
expect(result).toBe(1);
|
|
22
|
+
|
|
23
|
+
const eq: AssertEqual<typeof result, number> = true;
|
|
24
|
+
expect(eq).toBe(true);
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
describe('bigint', () => {
|
|
29
|
+
it('should output string', async () => {
|
|
30
|
+
const result = await db.get(raw(columnTypes.bigint(), '1::bigint'));
|
|
31
|
+
expect(result).toBe('1');
|
|
32
|
+
|
|
33
|
+
const eq: AssertEqual<typeof result, string> = true;
|
|
34
|
+
expect(eq).toBe(true);
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
describe('numeric', () => {
|
|
39
|
+
it('should output string', async () => {
|
|
40
|
+
const result = await db.get(raw(columnTypes.numeric(), '1::numeric'));
|
|
41
|
+
expect(result).toBe('1');
|
|
42
|
+
|
|
43
|
+
const eq: AssertEqual<typeof result, string> = true;
|
|
44
|
+
expect(eq).toBe(true);
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
describe('decimal', () => {
|
|
49
|
+
it('should output string', async () => {
|
|
50
|
+
const result = await db.get(raw(columnTypes.decimal(), '1::decimal'));
|
|
51
|
+
expect(result).toBe('1');
|
|
52
|
+
|
|
53
|
+
const eq: AssertEqual<typeof result, string> = true;
|
|
54
|
+
expect(eq).toBe(true);
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
describe('real', () => {
|
|
59
|
+
it('should output number', async () => {
|
|
60
|
+
const result = await db.get(raw(columnTypes.real(), '1::real'));
|
|
61
|
+
expect(result).toBe(1);
|
|
62
|
+
|
|
63
|
+
const eq: AssertEqual<typeof result, number> = true;
|
|
64
|
+
expect(eq).toBe(true);
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
describe('doublePrecision', () => {
|
|
69
|
+
it('should output number', async () => {
|
|
70
|
+
const result = await db.get(
|
|
71
|
+
raw(columnTypes.real(), '1::double precision'),
|
|
72
|
+
);
|
|
73
|
+
expect(result).toBe(1);
|
|
74
|
+
|
|
75
|
+
const eq: AssertEqual<typeof result, number> = true;
|
|
76
|
+
expect(eq).toBe(true);
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
describe('smallSerial', () => {
|
|
81
|
+
it('should output number', async () => {
|
|
82
|
+
const result = await db.get(
|
|
83
|
+
raw(columnTypes.smallSerial(), '1::smallint'),
|
|
84
|
+
);
|
|
85
|
+
expect(result).toBe(1);
|
|
86
|
+
|
|
87
|
+
const eq: AssertEqual<typeof result, number> = true;
|
|
88
|
+
expect(eq).toBe(true);
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
describe('serial', () => {
|
|
93
|
+
it('should output number', async () => {
|
|
94
|
+
const result = await db.get(raw(columnTypes.serial(), '1::integer'));
|
|
95
|
+
expect(result).toBe(1);
|
|
96
|
+
|
|
97
|
+
const eq: AssertEqual<typeof result, number> = true;
|
|
98
|
+
expect(eq).toBe(true);
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
describe('bigSerial', () => {
|
|
103
|
+
it('should output string', async () => {
|
|
104
|
+
const result = await db.get(raw(columnTypes.bigSerial(), '1::bigint'));
|
|
105
|
+
expect(result).toBe('1');
|
|
106
|
+
|
|
107
|
+
const eq: AssertEqual<typeof result, string> = true;
|
|
108
|
+
expect(eq).toBe(true);
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
describe('text types', () => {
|
|
114
|
+
describe('varchar', () => {
|
|
115
|
+
it('should output string', async () => {
|
|
116
|
+
const result = await db.get(
|
|
117
|
+
raw(columnTypes.varchar(), `'text'::varchar(4)`),
|
|
118
|
+
);
|
|
119
|
+
expect(result).toBe('text');
|
|
120
|
+
|
|
121
|
+
const eq: AssertEqual<typeof result, string> = true;
|
|
122
|
+
expect(eq).toBe(true);
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
describe('char', () => {
|
|
127
|
+
it('should output string', async () => {
|
|
128
|
+
const result = await db.get(raw(columnTypes.char(), `'text'::char(4)`));
|
|
129
|
+
expect(result).toBe('text');
|
|
130
|
+
|
|
131
|
+
const eq: AssertEqual<typeof result, string> = true;
|
|
132
|
+
expect(eq).toBe(true);
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
describe('text', () => {
|
|
137
|
+
it('should output string', async () => {
|
|
138
|
+
const result = await db.get(raw(columnTypes.text(), `'text'::text`));
|
|
139
|
+
expect(result).toBe('text');
|
|
140
|
+
|
|
141
|
+
const eq: AssertEqual<typeof result, string> = true;
|
|
142
|
+
expect(eq).toBe(true);
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
describe('string', () => {
|
|
147
|
+
it('should be an alias for the text', async () => {
|
|
148
|
+
const result = await db.get(raw(columnTypes.string(), `'text'::text`));
|
|
149
|
+
expect(result).toBe('text');
|
|
150
|
+
|
|
151
|
+
const eq: AssertEqual<typeof result, string> = true;
|
|
152
|
+
expect(eq).toBe(true);
|
|
153
|
+
});
|
|
154
|
+
});
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
describe('binary data type', () => {
|
|
158
|
+
describe('bytea', () => {
|
|
159
|
+
it('should output Buffer', async () => {
|
|
160
|
+
const result = await db.get(raw(columnTypes.bytea(), `'text'::bytea`));
|
|
161
|
+
expect(result instanceof Buffer).toBe(true);
|
|
162
|
+
expect(result.toString()).toBe('text');
|
|
163
|
+
|
|
164
|
+
const eq: AssertEqual<typeof result, Buffer> = true;
|
|
165
|
+
expect(eq).toBe(true);
|
|
166
|
+
});
|
|
167
|
+
});
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
describe('date/time types', () => {
|
|
171
|
+
describe('date', () => {
|
|
172
|
+
it('should output string', async () => {
|
|
173
|
+
const result = await db.get(
|
|
174
|
+
raw(columnTypes.date(), `'1999-01-08'::date`),
|
|
175
|
+
);
|
|
176
|
+
expect(result).toBe('1999-01-08');
|
|
177
|
+
|
|
178
|
+
const eq: AssertEqual<typeof result, string> = true;
|
|
179
|
+
expect(eq).toBe(true);
|
|
180
|
+
});
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
describe('timestamp', () => {
|
|
184
|
+
it('should output string', async () => {
|
|
185
|
+
const result = await db.get(
|
|
186
|
+
raw(columnTypes.timestamp(), `'1999-01-08 04:05:06'::timestamp`),
|
|
187
|
+
);
|
|
188
|
+
expect(result).toBe('1999-01-08 04:05:06');
|
|
189
|
+
|
|
190
|
+
const eq: AssertEqual<typeof result, string> = true;
|
|
191
|
+
expect(eq).toBe(true);
|
|
192
|
+
});
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
describe('timestamp with time zone', () => {
|
|
196
|
+
it('should output string', async () => {
|
|
197
|
+
const result = await db.get(
|
|
198
|
+
raw(
|
|
199
|
+
columnTypes.timestampWithTimeZone(),
|
|
200
|
+
`'1999-01-08 04:05:06 +0'::timestamptz AT TIME ZONE 'UTC'`,
|
|
201
|
+
),
|
|
202
|
+
);
|
|
203
|
+
expect(result).toBe('1999-01-08 04:05:06');
|
|
204
|
+
|
|
205
|
+
const eq: AssertEqual<typeof result, string> = true;
|
|
206
|
+
expect(eq).toBe(true);
|
|
207
|
+
});
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
describe('time', () => {
|
|
211
|
+
it('should output string', async () => {
|
|
212
|
+
const result = await db.get(raw(columnTypes.time(), `'12:00'::time`));
|
|
213
|
+
expect(result).toBe('12:00:00');
|
|
214
|
+
|
|
215
|
+
const eq: AssertEqual<typeof result, string> = true;
|
|
216
|
+
expect(eq).toBe(true);
|
|
217
|
+
});
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
describe('time with time zone', () => {
|
|
221
|
+
it('should output string', async () => {
|
|
222
|
+
const result = await db.get(
|
|
223
|
+
raw(
|
|
224
|
+
columnTypes.timeWithTimeZone(),
|
|
225
|
+
`'12:00 +0'::timetz AT TIME ZONE 'UTC'`,
|
|
226
|
+
),
|
|
227
|
+
);
|
|
228
|
+
expect(result).toBe('12:00:00+00');
|
|
229
|
+
|
|
230
|
+
const eq: AssertEqual<typeof result, string> = true;
|
|
231
|
+
expect(eq).toBe(true);
|
|
232
|
+
});
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
describe('interval', () => {
|
|
236
|
+
it('should output string', async () => {
|
|
237
|
+
const result = await db.get(
|
|
238
|
+
raw(
|
|
239
|
+
columnTypes.interval(),
|
|
240
|
+
`'1 year 2 months 3 days 4 hours 5 minutes 6 seconds'::interval`,
|
|
241
|
+
),
|
|
242
|
+
);
|
|
243
|
+
expect(result).toEqual({
|
|
244
|
+
years: 1,
|
|
245
|
+
months: 2,
|
|
246
|
+
days: 3,
|
|
247
|
+
hours: 4,
|
|
248
|
+
minutes: 5,
|
|
249
|
+
seconds: 6,
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
const eq: AssertEqual<typeof result, TimeInterval> = true;
|
|
253
|
+
expect(eq).toBe(true);
|
|
254
|
+
});
|
|
255
|
+
});
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
describe('boolean type', () => {
|
|
259
|
+
describe('boolean', () => {
|
|
260
|
+
it('should output boolean', async () => {
|
|
261
|
+
const result = await db.get(raw(columnTypes.boolean(), `true`));
|
|
262
|
+
expect(result).toBe(true);
|
|
263
|
+
|
|
264
|
+
const eq: AssertEqual<typeof result, boolean> = true;
|
|
265
|
+
expect(eq).toBe(true);
|
|
266
|
+
});
|
|
267
|
+
});
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
describe('enum type', () => {
|
|
271
|
+
describe('enum', () => {
|
|
272
|
+
beforeAll(async () => {
|
|
273
|
+
await db.adapter.query(`
|
|
274
|
+
DROP TYPE IF EXISTS mood
|
|
275
|
+
`);
|
|
276
|
+
await db.adapter.query(`
|
|
277
|
+
CREATE TYPE mood AS ENUM ('sad', 'ok', 'happy');
|
|
278
|
+
`);
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
type MoodUnion = 'sad' | 'ok' | 'happy';
|
|
282
|
+
|
|
283
|
+
it('should output proper union', async () => {
|
|
284
|
+
const result = await db.get(
|
|
285
|
+
raw(
|
|
286
|
+
columnTypes.enum('mood', ['sad', 'ok', 'happy']),
|
|
287
|
+
`'happy'::mood`,
|
|
288
|
+
),
|
|
289
|
+
);
|
|
290
|
+
expect(result).toBe('happy');
|
|
291
|
+
|
|
292
|
+
const eq: AssertEqual<typeof result, MoodUnion> = true;
|
|
293
|
+
expect(eq).toBe(true);
|
|
294
|
+
});
|
|
295
|
+
});
|
|
296
|
+
});
|
|
297
|
+
|
|
298
|
+
describe('geometric types', () => {
|
|
299
|
+
describe('point', () => {
|
|
300
|
+
it('should output string', async () => {
|
|
301
|
+
const result = await db.get(
|
|
302
|
+
raw(columnTypes.point(), `'(1, 2)'::point`),
|
|
303
|
+
);
|
|
304
|
+
expect(result).toBe('(1,2)');
|
|
305
|
+
|
|
306
|
+
const eq: AssertEqual<typeof result, string> = true;
|
|
307
|
+
expect(eq).toBe(true);
|
|
308
|
+
});
|
|
309
|
+
});
|
|
310
|
+
|
|
311
|
+
describe('line', () => {
|
|
312
|
+
it('should output string', async () => {
|
|
313
|
+
const result = await db.get(
|
|
314
|
+
raw(columnTypes.line(), `'{1, 2, 3}'::line`),
|
|
315
|
+
);
|
|
316
|
+
expect(result).toBe('{1,2,3}');
|
|
317
|
+
|
|
318
|
+
const eq: AssertEqual<typeof result, string> = true;
|
|
319
|
+
expect(eq).toBe(true);
|
|
320
|
+
});
|
|
321
|
+
});
|
|
322
|
+
|
|
323
|
+
describe('lseg', () => {
|
|
324
|
+
it('should output string', async () => {
|
|
325
|
+
const result = await db.get(
|
|
326
|
+
raw(columnTypes.lseg(), `'[(1, 2), (3, 4)]'::lseg`),
|
|
327
|
+
);
|
|
328
|
+
expect(result).toBe('[(1,2),(3,4)]');
|
|
329
|
+
|
|
330
|
+
const eq: AssertEqual<typeof result, string> = true;
|
|
331
|
+
expect(eq).toBe(true);
|
|
332
|
+
});
|
|
333
|
+
});
|
|
334
|
+
|
|
335
|
+
describe('box', () => {
|
|
336
|
+
it('should output string', async () => {
|
|
337
|
+
const result = await db.get(
|
|
338
|
+
raw(columnTypes.box(), `'((3, 4), (1, 2))'::box`),
|
|
339
|
+
);
|
|
340
|
+
expect(result).toBe('(3,4),(1,2)');
|
|
341
|
+
|
|
342
|
+
const eq: AssertEqual<typeof result, string> = true;
|
|
343
|
+
expect(eq).toBe(true);
|
|
344
|
+
});
|
|
345
|
+
});
|
|
346
|
+
|
|
347
|
+
describe('path', () => {
|
|
348
|
+
it('should output string', async () => {
|
|
349
|
+
const result = await db.get(
|
|
350
|
+
raw(columnTypes.path(), `'((1, 2), (3, 4))'::path`),
|
|
351
|
+
);
|
|
352
|
+
expect(result).toBe('((1,2),(3,4))');
|
|
353
|
+
|
|
354
|
+
const eq: AssertEqual<typeof result, string> = true;
|
|
355
|
+
expect(eq).toBe(true);
|
|
356
|
+
});
|
|
357
|
+
});
|
|
358
|
+
|
|
359
|
+
describe('polygon', () => {
|
|
360
|
+
it('should output string', async () => {
|
|
361
|
+
const result = await db.get(
|
|
362
|
+
raw(columnTypes.polygon(), `'((1, 2), (3, 4))'::polygon`),
|
|
363
|
+
);
|
|
364
|
+
expect(result).toBe('((1,2),(3,4))');
|
|
365
|
+
|
|
366
|
+
const eq: AssertEqual<typeof result, string> = true;
|
|
367
|
+
expect(eq).toBe(true);
|
|
368
|
+
});
|
|
369
|
+
});
|
|
370
|
+
|
|
371
|
+
describe('circle', () => {
|
|
372
|
+
it('should output string', async () => {
|
|
373
|
+
const result = await db.get(
|
|
374
|
+
raw(columnTypes.circle(), `'<(1,2),3>'::circle`),
|
|
375
|
+
);
|
|
376
|
+
expect(result).toBe('<(1,2),3>');
|
|
377
|
+
|
|
378
|
+
const eq: AssertEqual<typeof result, string> = true;
|
|
379
|
+
expect(eq).toBe(true);
|
|
380
|
+
});
|
|
381
|
+
});
|
|
382
|
+
});
|
|
383
|
+
|
|
384
|
+
describe('network address types', () => {
|
|
385
|
+
describe('cidr', () => {
|
|
386
|
+
it('should output string', async () => {
|
|
387
|
+
const result = await db.get(
|
|
388
|
+
raw(columnTypes.cidr(), `'192.168.100.128/25'::cidr`),
|
|
389
|
+
);
|
|
390
|
+
expect(result).toBe('192.168.100.128/25');
|
|
391
|
+
|
|
392
|
+
const eq: AssertEqual<typeof result, string> = true;
|
|
393
|
+
expect(eq).toBe(true);
|
|
394
|
+
});
|
|
395
|
+
});
|
|
396
|
+
|
|
397
|
+
describe('inet', () => {
|
|
398
|
+
it('should output string', async () => {
|
|
399
|
+
const result = await db.get(
|
|
400
|
+
raw(columnTypes.inet(), `'192.168.100.128/25'::inet`),
|
|
401
|
+
);
|
|
402
|
+
expect(result).toBe('192.168.100.128/25');
|
|
403
|
+
|
|
404
|
+
const eq: AssertEqual<typeof result, string> = true;
|
|
405
|
+
expect(eq).toBe(true);
|
|
406
|
+
});
|
|
407
|
+
});
|
|
408
|
+
|
|
409
|
+
describe('macaddr', () => {
|
|
410
|
+
it('should output string', async () => {
|
|
411
|
+
const result = await db.get(
|
|
412
|
+
raw(columnTypes.macaddr(), `'08:00:2b:01:02:03'::macaddr`),
|
|
413
|
+
);
|
|
414
|
+
expect(result).toBe('08:00:2b:01:02:03');
|
|
415
|
+
|
|
416
|
+
const eq: AssertEqual<typeof result, string> = true;
|
|
417
|
+
expect(eq).toBe(true);
|
|
418
|
+
});
|
|
419
|
+
});
|
|
420
|
+
|
|
421
|
+
describe('macaddr8', () => {
|
|
422
|
+
it('should output string', async () => {
|
|
423
|
+
const result = await db.get(
|
|
424
|
+
raw(columnTypes.macaddr8(), `'08:00:2b:ff:fe:01:02:03'::macaddr8`),
|
|
425
|
+
);
|
|
426
|
+
expect(result).toBe('08:00:2b:ff:fe:01:02:03');
|
|
427
|
+
|
|
428
|
+
const eq: AssertEqual<typeof result, string> = true;
|
|
429
|
+
expect(eq).toBe(true);
|
|
430
|
+
});
|
|
431
|
+
});
|
|
432
|
+
});
|
|
433
|
+
|
|
434
|
+
describe('bit string types', () => {
|
|
435
|
+
describe('bit', () => {
|
|
436
|
+
it('should output string', async () => {
|
|
437
|
+
const result = await db.get(raw(columnTypes.bit(3), `B'101'`));
|
|
438
|
+
expect(result).toBe('101');
|
|
439
|
+
|
|
440
|
+
const eq: AssertEqual<typeof result, string> = true;
|
|
441
|
+
expect(eq).toBe(true);
|
|
442
|
+
});
|
|
443
|
+
});
|
|
444
|
+
|
|
445
|
+
describe('bit varying', () => {
|
|
446
|
+
it('should output string', async () => {
|
|
447
|
+
const result = await db.get(
|
|
448
|
+
raw(columnTypes.bitVarying(), `'10101'::bit varying(5)`),
|
|
449
|
+
);
|
|
450
|
+
expect(result).toBe('10101');
|
|
451
|
+
|
|
452
|
+
const eq: AssertEqual<typeof result, string> = true;
|
|
453
|
+
expect(eq).toBe(true);
|
|
454
|
+
});
|
|
455
|
+
});
|
|
456
|
+
});
|
|
457
|
+
|
|
458
|
+
describe('text search types', () => {
|
|
459
|
+
describe('tsvector', () => {
|
|
460
|
+
it('should output string', async () => {
|
|
461
|
+
const result = await db.get(
|
|
462
|
+
raw(
|
|
463
|
+
columnTypes.tsvector(),
|
|
464
|
+
`'a fat cat sat on a mat and ate a fat rat'::tsvector`,
|
|
465
|
+
),
|
|
466
|
+
);
|
|
467
|
+
expect(result).toBe(
|
|
468
|
+
`'a' 'and' 'ate' 'cat' 'fat' 'mat' 'on' 'rat' 'sat'`,
|
|
469
|
+
);
|
|
470
|
+
|
|
471
|
+
const eq: AssertEqual<typeof result, string> = true;
|
|
472
|
+
expect(eq).toBe(true);
|
|
473
|
+
});
|
|
474
|
+
});
|
|
475
|
+
|
|
476
|
+
describe('tsquery', () => {
|
|
477
|
+
it('should output string', async () => {
|
|
478
|
+
const result = await db.get(
|
|
479
|
+
raw(columnTypes.tsquery(), `'fat & rat'::tsquery`),
|
|
480
|
+
);
|
|
481
|
+
expect(result).toBe(`'fat' & 'rat'`);
|
|
482
|
+
|
|
483
|
+
const eq: AssertEqual<typeof result, string> = true;
|
|
484
|
+
expect(eq).toBe(true);
|
|
485
|
+
});
|
|
486
|
+
});
|
|
487
|
+
});
|
|
488
|
+
|
|
489
|
+
describe('uuid type', () => {
|
|
490
|
+
describe('uuid', () => {
|
|
491
|
+
it('should output string', async () => {
|
|
492
|
+
const result = await db.get(
|
|
493
|
+
raw(
|
|
494
|
+
columnTypes.uuid(),
|
|
495
|
+
`'a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11'::uuid`,
|
|
496
|
+
),
|
|
497
|
+
);
|
|
498
|
+
expect(result).toBe(`a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11`);
|
|
499
|
+
|
|
500
|
+
const eq: AssertEqual<typeof result, string> = true;
|
|
501
|
+
expect(eq).toBe(true);
|
|
502
|
+
});
|
|
503
|
+
});
|
|
504
|
+
});
|
|
505
|
+
|
|
506
|
+
describe('array type', () => {
|
|
507
|
+
describe('array', () => {
|
|
508
|
+
it('should output nested array of numbers', async () => {
|
|
509
|
+
const result = await db.get(
|
|
510
|
+
raw(
|
|
511
|
+
columnTypes.array(columnTypes.array(columnTypes.integer())),
|
|
512
|
+
`'{{1, 2, 3}, {4, 5, 6}}'::integer[][]`,
|
|
513
|
+
),
|
|
514
|
+
);
|
|
515
|
+
expect(result).toEqual([
|
|
516
|
+
[1, 2, 3],
|
|
517
|
+
[4, 5, 6],
|
|
518
|
+
]);
|
|
519
|
+
|
|
520
|
+
const eq: AssertEqual<typeof result, number[][]> = true;
|
|
521
|
+
expect(eq).toBe(true);
|
|
522
|
+
});
|
|
523
|
+
|
|
524
|
+
it('should output nested array of strings', async () => {
|
|
525
|
+
const result = await db.get(
|
|
526
|
+
raw(
|
|
527
|
+
columnTypes.array(columnTypes.array(columnTypes.text())),
|
|
528
|
+
`'{{"a", "b"}, {"c", "d"}}'::text[][]`,
|
|
529
|
+
),
|
|
530
|
+
);
|
|
531
|
+
expect(result).toEqual([
|
|
532
|
+
['a', 'b'],
|
|
533
|
+
['c', 'd'],
|
|
534
|
+
]);
|
|
535
|
+
|
|
536
|
+
const eq: AssertEqual<typeof result, string[][]> = true;
|
|
537
|
+
expect(eq).toBe(true);
|
|
538
|
+
});
|
|
539
|
+
|
|
540
|
+
it('should output nested array of booleans', async () => {
|
|
541
|
+
const result = await db.get(
|
|
542
|
+
raw(
|
|
543
|
+
columnTypes.array(columnTypes.array(columnTypes.boolean())),
|
|
544
|
+
`'{{true}, {false}}'::text[][]`,
|
|
545
|
+
),
|
|
546
|
+
);
|
|
547
|
+
expect(result).toEqual([[true], [false]]);
|
|
548
|
+
|
|
549
|
+
const eq: AssertEqual<typeof result, boolean[][]> = true;
|
|
550
|
+
expect(eq).toBe(true);
|
|
551
|
+
});
|
|
552
|
+
});
|
|
553
|
+
});
|
|
554
|
+
|
|
555
|
+
describe('other types', () => {
|
|
556
|
+
describe('money', () => {
|
|
557
|
+
it('should output number', async () => {
|
|
558
|
+
const result = await db.get(
|
|
559
|
+
raw(columnTypes.money(), `'1234567890.42'::money`),
|
|
560
|
+
);
|
|
561
|
+
expect(result).toBe(1234567890.42);
|
|
562
|
+
|
|
563
|
+
const eq: AssertEqual<typeof result, number> = true;
|
|
564
|
+
expect(eq).toBe(true);
|
|
565
|
+
});
|
|
566
|
+
});
|
|
567
|
+
});
|
|
568
|
+
});
|