pqb 0.4.5 → 0.4.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.
- package/dist/index.d.ts +24 -13
- package/dist/index.esm.js +44 -33
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +44 -32
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/columnSchema/columnTypes.test.ts +55 -53
- package/src/columnSchema/timestamps.test.ts +3 -4
- package/src/columnSchema/timestamps.ts +1 -1
- package/src/columnsOperators.test.ts +18 -19
- package/src/columnsOperators.ts +1 -1
- package/src/common.ts +17 -30
- package/src/db.ts +19 -8
- package/src/errors.test.ts +2 -4
- package/src/index.ts +1 -1
- package/src/query.ts +7 -1
- package/src/queryMethods/aggregate.test.ts +9 -7
- package/src/queryMethods/create.test.ts +5 -5
- package/src/queryMethods/create.ts +1 -1
- package/src/queryMethods/delete.ts +2 -0
- package/src/queryMethods/for.test.ts +1 -2
- package/src/queryMethods/for.ts +1 -1
- package/src/queryMethods/from.test.ts +2 -3
- package/src/queryMethods/get.test.ts +5 -5
- package/src/queryMethods/having.test.ts +6 -5
- package/src/queryMethods/index.ts +1 -0
- package/src/queryMethods/json.ts +2 -2
- package/src/queryMethods/merge.test.ts +10 -4
- package/src/queryMethods/queryMethods.test.ts +10 -12
- package/src/queryMethods/queryMethods.ts +7 -4
- package/src/queryMethods/raw.test.ts +19 -0
- package/src/queryMethods/raw.ts +27 -0
- package/src/queryMethods/select.test.ts +5 -209
- package/src/queryMethods/then.test.ts +2 -4
- package/src/queryMethods/union.test.ts +11 -6
- package/src/queryMethods/update.test.ts +3 -3
- package/src/queryMethods/where.test.ts +65 -56
- package/src/queryMethods/where.ts +1 -1
- package/src/queryMethods/with.test.ts +5 -6
- package/src/relations.ts +15 -4
- package/src/sql/common.ts +0 -1
- package/src/sql/fromAndAs.ts +1 -1
- package/src/sql/insert.ts +1 -1
- package/src/sql/join.ts +1 -1
- package/src/sql/orderBy.ts +1 -1
- package/src/sql/select.ts +1 -2
- package/src/sql/toSql.ts +1 -1
- package/src/sql/update.ts +1 -1
- package/src/sql/where.ts +1 -1
- package/src/sql/window.ts +3 -4
- package/src/sql/with.ts +1 -1
package/package.json
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { assertType, db } from '../test-utils';
|
|
2
|
-
import { raw } from '../common';
|
|
3
2
|
import { columnTypes } from './columnTypes';
|
|
4
3
|
import { TimeInterval } from './dateTime';
|
|
5
4
|
|
|
@@ -7,7 +6,7 @@ describe('column types', () => {
|
|
|
7
6
|
describe('numeric types', () => {
|
|
8
7
|
describe('smallint', () => {
|
|
9
8
|
it('should output number', async () => {
|
|
10
|
-
const result = await db.get(raw(
|
|
9
|
+
const result = await db.get(db.raw((t) => t.smallint(), '1::smallint'));
|
|
11
10
|
expect(result).toBe(1);
|
|
12
11
|
|
|
13
12
|
assertType<typeof result, number>();
|
|
@@ -16,7 +15,7 @@ describe('column types', () => {
|
|
|
16
15
|
|
|
17
16
|
describe('integer', () => {
|
|
18
17
|
it('should output number', async () => {
|
|
19
|
-
const result = await db.get(raw(
|
|
18
|
+
const result = await db.get(db.raw((t) => t.integer(), '1::integer'));
|
|
20
19
|
expect(result).toBe(1);
|
|
21
20
|
|
|
22
21
|
assertType<typeof result, number>();
|
|
@@ -25,7 +24,7 @@ describe('column types', () => {
|
|
|
25
24
|
|
|
26
25
|
describe('bigint', () => {
|
|
27
26
|
it('should output string', async () => {
|
|
28
|
-
const result = await db.get(raw(
|
|
27
|
+
const result = await db.get(db.raw((t) => t.bigint(), '1::bigint'));
|
|
29
28
|
expect(result).toBe('1');
|
|
30
29
|
|
|
31
30
|
assertType<typeof result, string>();
|
|
@@ -34,7 +33,7 @@ describe('column types', () => {
|
|
|
34
33
|
|
|
35
34
|
describe('numeric', () => {
|
|
36
35
|
it('should output string', async () => {
|
|
37
|
-
const result = await db.get(raw(
|
|
36
|
+
const result = await db.get(db.raw((t) => t.numeric(), '1::numeric'));
|
|
38
37
|
expect(result).toBe('1');
|
|
39
38
|
|
|
40
39
|
assertType<typeof result, string>();
|
|
@@ -43,7 +42,7 @@ describe('column types', () => {
|
|
|
43
42
|
|
|
44
43
|
describe('decimal', () => {
|
|
45
44
|
it('should output string', async () => {
|
|
46
|
-
const result = await db.get(raw(
|
|
45
|
+
const result = await db.get(db.raw((t) => t.decimal(), '1::decimal'));
|
|
47
46
|
expect(result).toBe('1');
|
|
48
47
|
|
|
49
48
|
assertType<typeof result, string>();
|
|
@@ -52,7 +51,7 @@ describe('column types', () => {
|
|
|
52
51
|
|
|
53
52
|
describe('real', () => {
|
|
54
53
|
it('should output number', async () => {
|
|
55
|
-
const result = await db.get(raw(
|
|
54
|
+
const result = await db.get(db.raw((t) => t.real(), '1::real'));
|
|
56
55
|
expect(result).toBe(1);
|
|
57
56
|
|
|
58
57
|
assertType<typeof result, number>();
|
|
@@ -62,7 +61,7 @@ describe('column types', () => {
|
|
|
62
61
|
describe('doublePrecision', () => {
|
|
63
62
|
it('should output number', async () => {
|
|
64
63
|
const result = await db.get(
|
|
65
|
-
raw(
|
|
64
|
+
db.raw((t) => t.real(), '1::double precision'),
|
|
66
65
|
);
|
|
67
66
|
expect(result).toBe(1);
|
|
68
67
|
|
|
@@ -73,7 +72,7 @@ describe('column types', () => {
|
|
|
73
72
|
describe('smallSerial', () => {
|
|
74
73
|
it('should output number', async () => {
|
|
75
74
|
const result = await db.get(
|
|
76
|
-
raw(
|
|
75
|
+
db.raw((t) => t.smallSerial(), '1::smallint'),
|
|
77
76
|
);
|
|
78
77
|
expect(result).toBe(1);
|
|
79
78
|
|
|
@@ -83,7 +82,7 @@ describe('column types', () => {
|
|
|
83
82
|
|
|
84
83
|
describe('serial', () => {
|
|
85
84
|
it('should output number', async () => {
|
|
86
|
-
const result = await db.get(raw(
|
|
85
|
+
const result = await db.get(db.raw((t) => t.serial(), '1::integer'));
|
|
87
86
|
expect(result).toBe(1);
|
|
88
87
|
|
|
89
88
|
assertType<typeof result, number>();
|
|
@@ -92,7 +91,7 @@ describe('column types', () => {
|
|
|
92
91
|
|
|
93
92
|
describe('bigSerial', () => {
|
|
94
93
|
it('should output string', async () => {
|
|
95
|
-
const result = await db.get(raw(
|
|
94
|
+
const result = await db.get(db.raw((t) => t.bigSerial(), '1::bigint'));
|
|
96
95
|
expect(result).toBe('1');
|
|
97
96
|
|
|
98
97
|
assertType<typeof result, string>();
|
|
@@ -104,7 +103,7 @@ describe('column types', () => {
|
|
|
104
103
|
describe('varchar', () => {
|
|
105
104
|
it('should output string', async () => {
|
|
106
105
|
const result = await db.get(
|
|
107
|
-
raw(
|
|
106
|
+
db.raw((t) => t.varchar(), `'text'::varchar(4)`),
|
|
108
107
|
);
|
|
109
108
|
expect(result).toBe('text');
|
|
110
109
|
|
|
@@ -114,7 +113,7 @@ describe('column types', () => {
|
|
|
114
113
|
|
|
115
114
|
describe('char', () => {
|
|
116
115
|
it('should output string', async () => {
|
|
117
|
-
const result = await db.get(raw(
|
|
116
|
+
const result = await db.get(db.raw((t) => t.char(), `'text'::char(4)`));
|
|
118
117
|
expect(result).toBe('text');
|
|
119
118
|
|
|
120
119
|
assertType<typeof result, string>();
|
|
@@ -123,7 +122,7 @@ describe('column types', () => {
|
|
|
123
122
|
|
|
124
123
|
describe('text', () => {
|
|
125
124
|
it('should output string', async () => {
|
|
126
|
-
const result = await db.get(raw(
|
|
125
|
+
const result = await db.get(db.raw((t) => t.text(), `'text'::text`));
|
|
127
126
|
expect(result).toBe('text');
|
|
128
127
|
|
|
129
128
|
assertType<typeof result, string>();
|
|
@@ -132,7 +131,7 @@ describe('column types', () => {
|
|
|
132
131
|
|
|
133
132
|
describe('string', () => {
|
|
134
133
|
it('should be an alias for the text', async () => {
|
|
135
|
-
const result = await db.get(raw(
|
|
134
|
+
const result = await db.get(db.raw((t) => t.string(), `'text'::text`));
|
|
136
135
|
expect(result).toBe('text');
|
|
137
136
|
|
|
138
137
|
assertType<typeof result, string>();
|
|
@@ -143,7 +142,7 @@ describe('column types', () => {
|
|
|
143
142
|
describe('binary data type', () => {
|
|
144
143
|
describe('bytea', () => {
|
|
145
144
|
it('should output Buffer', async () => {
|
|
146
|
-
const result = await db.get(raw(
|
|
145
|
+
const result = await db.get(db.raw((t) => t.bytea(), `'text'::bytea`));
|
|
147
146
|
expect(result instanceof Buffer).toBe(true);
|
|
148
147
|
expect(result.toString()).toBe('text');
|
|
149
148
|
|
|
@@ -156,7 +155,7 @@ describe('column types', () => {
|
|
|
156
155
|
describe('date', () => {
|
|
157
156
|
it('should output string', async () => {
|
|
158
157
|
const result = await db.get(
|
|
159
|
-
raw(
|
|
158
|
+
db.raw((t) => t.date(), `'1999-01-08'::date`),
|
|
160
159
|
);
|
|
161
160
|
expect(result).toBe('1999-01-08');
|
|
162
161
|
|
|
@@ -167,7 +166,10 @@ describe('column types', () => {
|
|
|
167
166
|
describe('timestamp', () => {
|
|
168
167
|
it('should output string', async () => {
|
|
169
168
|
const result = await db.get(
|
|
170
|
-
raw(
|
|
169
|
+
db.raw(
|
|
170
|
+
() => columnTypes.timestamp(),
|
|
171
|
+
`'1999-01-08 04:05:06'::timestamp`,
|
|
172
|
+
),
|
|
171
173
|
);
|
|
172
174
|
expect(result).toBe('1999-01-08 04:05:06');
|
|
173
175
|
|
|
@@ -178,8 +180,8 @@ describe('column types', () => {
|
|
|
178
180
|
describe('timestamp with time zone', () => {
|
|
179
181
|
it('should output string', async () => {
|
|
180
182
|
const result = await db.get(
|
|
181
|
-
raw(
|
|
182
|
-
|
|
183
|
+
db.raw(
|
|
184
|
+
(t) => t.timestampWithTimeZone(),
|
|
183
185
|
`'1999-01-08 04:05:06 +0'::timestamptz AT TIME ZONE 'UTC'`,
|
|
184
186
|
),
|
|
185
187
|
);
|
|
@@ -191,7 +193,7 @@ describe('column types', () => {
|
|
|
191
193
|
|
|
192
194
|
describe('time', () => {
|
|
193
195
|
it('should output string', async () => {
|
|
194
|
-
const result = await db.get(raw(
|
|
196
|
+
const result = await db.get(db.raw((t) => t.time(), `'12:00'::time`));
|
|
195
197
|
expect(result).toBe('12:00:00');
|
|
196
198
|
|
|
197
199
|
assertType<typeof result, string>();
|
|
@@ -201,8 +203,8 @@ describe('column types', () => {
|
|
|
201
203
|
describe('time with time zone', () => {
|
|
202
204
|
it('should output string', async () => {
|
|
203
205
|
const result = await db.get(
|
|
204
|
-
raw(
|
|
205
|
-
|
|
206
|
+
db.raw(
|
|
207
|
+
(t) => t.timeWithTimeZone(),
|
|
206
208
|
`'12:00 +0'::timetz AT TIME ZONE 'UTC'`,
|
|
207
209
|
),
|
|
208
210
|
);
|
|
@@ -215,8 +217,8 @@ describe('column types', () => {
|
|
|
215
217
|
describe('interval', () => {
|
|
216
218
|
it('should output string', async () => {
|
|
217
219
|
const result = await db.get(
|
|
218
|
-
raw(
|
|
219
|
-
|
|
220
|
+
db.raw(
|
|
221
|
+
(t) => t.interval(),
|
|
220
222
|
`'1 year 2 months 3 days 4 hours 5 minutes 6 seconds'::interval`,
|
|
221
223
|
),
|
|
222
224
|
);
|
|
@@ -237,7 +239,7 @@ describe('column types', () => {
|
|
|
237
239
|
describe('boolean type', () => {
|
|
238
240
|
describe('boolean', () => {
|
|
239
241
|
it('should output boolean', async () => {
|
|
240
|
-
const result = await db.get(raw(
|
|
242
|
+
const result = await db.get(db.raw((t) => t.boolean(), `true`));
|
|
241
243
|
expect(result).toBe(true);
|
|
242
244
|
|
|
243
245
|
assertType<typeof result, boolean>();
|
|
@@ -260,8 +262,8 @@ describe('column types', () => {
|
|
|
260
262
|
|
|
261
263
|
it('should output proper union', async () => {
|
|
262
264
|
const result = await db.get(
|
|
263
|
-
raw(
|
|
264
|
-
|
|
265
|
+
db.raw(
|
|
266
|
+
(t) => t.enum('mood', ['sad', 'ok', 'happy']),
|
|
265
267
|
`'happy'::mood`,
|
|
266
268
|
),
|
|
267
269
|
);
|
|
@@ -276,7 +278,7 @@ describe('column types', () => {
|
|
|
276
278
|
describe('point', () => {
|
|
277
279
|
it('should output string', async () => {
|
|
278
280
|
const result = await db.get(
|
|
279
|
-
raw(
|
|
281
|
+
db.raw((t) => t.point(), `'(1, 2)'::point`),
|
|
280
282
|
);
|
|
281
283
|
expect(result).toBe('(1,2)');
|
|
282
284
|
|
|
@@ -287,7 +289,7 @@ describe('column types', () => {
|
|
|
287
289
|
describe('line', () => {
|
|
288
290
|
it('should output string', async () => {
|
|
289
291
|
const result = await db.get(
|
|
290
|
-
raw(
|
|
292
|
+
db.raw((t) => t.line(), `'{1, 2, 3}'::line`),
|
|
291
293
|
);
|
|
292
294
|
expect(result).toBe('{1,2,3}');
|
|
293
295
|
|
|
@@ -298,7 +300,7 @@ describe('column types', () => {
|
|
|
298
300
|
describe('lseg', () => {
|
|
299
301
|
it('should output string', async () => {
|
|
300
302
|
const result = await db.get(
|
|
301
|
-
raw(
|
|
303
|
+
db.raw((t) => t.lseg(), `'[(1, 2), (3, 4)]'::lseg`),
|
|
302
304
|
);
|
|
303
305
|
expect(result).toBe('[(1,2),(3,4)]');
|
|
304
306
|
|
|
@@ -309,7 +311,7 @@ describe('column types', () => {
|
|
|
309
311
|
describe('box', () => {
|
|
310
312
|
it('should output string', async () => {
|
|
311
313
|
const result = await db.get(
|
|
312
|
-
raw(
|
|
314
|
+
db.raw((t) => t.box(), `'((3, 4), (1, 2))'::box`),
|
|
313
315
|
);
|
|
314
316
|
expect(result).toBe('(3,4),(1,2)');
|
|
315
317
|
|
|
@@ -320,7 +322,7 @@ describe('column types', () => {
|
|
|
320
322
|
describe('path', () => {
|
|
321
323
|
it('should output string', async () => {
|
|
322
324
|
const result = await db.get(
|
|
323
|
-
raw(
|
|
325
|
+
db.raw((t) => t.path(), `'((1, 2), (3, 4))'::path`),
|
|
324
326
|
);
|
|
325
327
|
expect(result).toBe('((1,2),(3,4))');
|
|
326
328
|
|
|
@@ -331,7 +333,7 @@ describe('column types', () => {
|
|
|
331
333
|
describe('polygon', () => {
|
|
332
334
|
it('should output string', async () => {
|
|
333
335
|
const result = await db.get(
|
|
334
|
-
raw(
|
|
336
|
+
db.raw((t) => t.polygon(), `'((1, 2), (3, 4))'::polygon`),
|
|
335
337
|
);
|
|
336
338
|
expect(result).toBe('((1,2),(3,4))');
|
|
337
339
|
|
|
@@ -342,7 +344,7 @@ describe('column types', () => {
|
|
|
342
344
|
describe('circle', () => {
|
|
343
345
|
it('should output string', async () => {
|
|
344
346
|
const result = await db.get(
|
|
345
|
-
raw(
|
|
347
|
+
db.raw((t) => t.circle(), `'<(1,2),3>'::circle`),
|
|
346
348
|
);
|
|
347
349
|
expect(result).toBe('<(1,2),3>');
|
|
348
350
|
|
|
@@ -355,7 +357,7 @@ describe('column types', () => {
|
|
|
355
357
|
describe('cidr', () => {
|
|
356
358
|
it('should output string', async () => {
|
|
357
359
|
const result = await db.get(
|
|
358
|
-
raw(
|
|
360
|
+
db.raw((t) => t.cidr(), `'192.168.100.128/25'::cidr`),
|
|
359
361
|
);
|
|
360
362
|
expect(result).toBe('192.168.100.128/25');
|
|
361
363
|
|
|
@@ -366,7 +368,7 @@ describe('column types', () => {
|
|
|
366
368
|
describe('inet', () => {
|
|
367
369
|
it('should output string', async () => {
|
|
368
370
|
const result = await db.get(
|
|
369
|
-
raw(
|
|
371
|
+
db.raw((t) => t.inet(), `'192.168.100.128/25'::inet`),
|
|
370
372
|
);
|
|
371
373
|
expect(result).toBe('192.168.100.128/25');
|
|
372
374
|
|
|
@@ -377,7 +379,7 @@ describe('column types', () => {
|
|
|
377
379
|
describe('macaddr', () => {
|
|
378
380
|
it('should output string', async () => {
|
|
379
381
|
const result = await db.get(
|
|
380
|
-
raw(
|
|
382
|
+
db.raw((t) => t.macaddr(), `'08:00:2b:01:02:03'::macaddr`),
|
|
381
383
|
);
|
|
382
384
|
expect(result).toBe('08:00:2b:01:02:03');
|
|
383
385
|
|
|
@@ -388,7 +390,7 @@ describe('column types', () => {
|
|
|
388
390
|
describe('macaddr8', () => {
|
|
389
391
|
it('should output string', async () => {
|
|
390
392
|
const result = await db.get(
|
|
391
|
-
raw(
|
|
393
|
+
db.raw((t) => t.macaddr8(), `'08:00:2b:ff:fe:01:02:03'::macaddr8`),
|
|
392
394
|
);
|
|
393
395
|
expect(result).toBe('08:00:2b:ff:fe:01:02:03');
|
|
394
396
|
|
|
@@ -400,7 +402,7 @@ describe('column types', () => {
|
|
|
400
402
|
describe('bit string types', () => {
|
|
401
403
|
describe('bit', () => {
|
|
402
404
|
it('should output string', async () => {
|
|
403
|
-
const result = await db.get(raw(
|
|
405
|
+
const result = await db.get(db.raw((t) => t.bit(3), `B'101'`));
|
|
404
406
|
expect(result).toBe('101');
|
|
405
407
|
|
|
406
408
|
assertType<typeof result, string>();
|
|
@@ -410,7 +412,7 @@ describe('column types', () => {
|
|
|
410
412
|
describe('bit varying', () => {
|
|
411
413
|
it('should output string', async () => {
|
|
412
414
|
const result = await db.get(
|
|
413
|
-
raw(
|
|
415
|
+
db.raw((t) => t.bitVarying(), `'10101'::bit varying(5)`),
|
|
414
416
|
);
|
|
415
417
|
expect(result).toBe('10101');
|
|
416
418
|
|
|
@@ -423,8 +425,8 @@ describe('column types', () => {
|
|
|
423
425
|
describe('tsvector', () => {
|
|
424
426
|
it('should output string', async () => {
|
|
425
427
|
const result = await db.get(
|
|
426
|
-
raw(
|
|
427
|
-
|
|
428
|
+
db.raw(
|
|
429
|
+
(t) => t.tsvector(),
|
|
428
430
|
`'a fat cat sat on a mat and ate a fat rat'::tsvector`,
|
|
429
431
|
),
|
|
430
432
|
);
|
|
@@ -439,7 +441,7 @@ describe('column types', () => {
|
|
|
439
441
|
describe('tsquery', () => {
|
|
440
442
|
it('should output string', async () => {
|
|
441
443
|
const result = await db.get(
|
|
442
|
-
raw(
|
|
444
|
+
db.raw((t) => t.tsquery(), `'fat & rat'::tsquery`),
|
|
443
445
|
);
|
|
444
446
|
expect(result).toBe(`'fat' & 'rat'`);
|
|
445
447
|
|
|
@@ -452,8 +454,8 @@ describe('column types', () => {
|
|
|
452
454
|
describe('uuid', () => {
|
|
453
455
|
it('should output string', async () => {
|
|
454
456
|
const result = await db.get(
|
|
455
|
-
raw(
|
|
456
|
-
|
|
457
|
+
db.raw(
|
|
458
|
+
(t) => t.uuid(),
|
|
457
459
|
`'a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11'::uuid`,
|
|
458
460
|
),
|
|
459
461
|
);
|
|
@@ -468,8 +470,8 @@ describe('column types', () => {
|
|
|
468
470
|
describe('array', () => {
|
|
469
471
|
it('should output nested array of numbers', async () => {
|
|
470
472
|
const result = await db.get(
|
|
471
|
-
raw(
|
|
472
|
-
|
|
473
|
+
db.raw(
|
|
474
|
+
(t) => t.array(t.array(t.integer())),
|
|
473
475
|
`'{{1, 2, 3}, {4, 5, 6}}'::integer[][]`,
|
|
474
476
|
),
|
|
475
477
|
);
|
|
@@ -483,8 +485,8 @@ describe('column types', () => {
|
|
|
483
485
|
|
|
484
486
|
it('should output nested array of strings', async () => {
|
|
485
487
|
const result = await db.get(
|
|
486
|
-
raw(
|
|
487
|
-
|
|
488
|
+
db.raw(
|
|
489
|
+
(t) => t.array(t.array(t.text())),
|
|
488
490
|
`'{{"a", "b"}, {"c", "d"}}'::text[][]`,
|
|
489
491
|
),
|
|
490
492
|
);
|
|
@@ -498,8 +500,8 @@ describe('column types', () => {
|
|
|
498
500
|
|
|
499
501
|
it('should output nested array of booleans', async () => {
|
|
500
502
|
const result = await db.get(
|
|
501
|
-
raw(
|
|
502
|
-
|
|
503
|
+
db.raw(
|
|
504
|
+
(t) => t.array(t.array(t.boolean())),
|
|
503
505
|
`'{{true}, {false}}'::text[][]`,
|
|
504
506
|
),
|
|
505
507
|
);
|
|
@@ -514,7 +516,7 @@ describe('column types', () => {
|
|
|
514
516
|
describe('money', () => {
|
|
515
517
|
it('should output number', async () => {
|
|
516
518
|
const result = await db.get(
|
|
517
|
-
raw(
|
|
519
|
+
db.raw((t) => t.money(), `'1234567890.42'::money`),
|
|
518
520
|
);
|
|
519
521
|
expect(result).toBe(1234567890.42);
|
|
520
522
|
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { db, expectSql, now, useTestDatabase } from '../test-utils';
|
|
2
|
-
import { raw } from '../common';
|
|
3
2
|
|
|
4
3
|
describe('timestamps', () => {
|
|
5
4
|
useTestDatabase();
|
|
@@ -37,7 +36,7 @@ describe('timestamps', () => {
|
|
|
37
36
|
});
|
|
38
37
|
|
|
39
38
|
it('should update updatedAt when updating with raw sql', async () => {
|
|
40
|
-
const query = model.updateRaw(raw('name = $1', 'name'), true);
|
|
39
|
+
const query = model.updateRaw(db.raw('name = $1', 'name'), true);
|
|
41
40
|
await query;
|
|
42
41
|
|
|
43
42
|
expectSql(
|
|
@@ -51,7 +50,7 @@ describe('timestamps', () => {
|
|
|
51
50
|
});
|
|
52
51
|
|
|
53
52
|
it('should update updatedAt when updating with raw sql which has updatedAt somewhere but not in set', async () => {
|
|
54
|
-
const query = model.updateRaw(raw('"createdAt" = "updatedAt"'), true);
|
|
53
|
+
const query = model.updateRaw(db.raw('"createdAt" = "updatedAt"'), true);
|
|
55
54
|
await query;
|
|
56
55
|
|
|
57
56
|
expectSql(
|
|
@@ -64,7 +63,7 @@ describe('timestamps', () => {
|
|
|
64
63
|
});
|
|
65
64
|
|
|
66
65
|
it('should not update updatedAt column when updating with raw sql which contains `updatedAt = `', async () => {
|
|
67
|
-
const query = model.updateRaw(raw('"updatedAt" = $1', now), true);
|
|
66
|
+
const query = model.updateRaw(db.raw('"updatedAt" = $1', now), true);
|
|
68
67
|
await query;
|
|
69
68
|
|
|
70
69
|
expectSql(
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { ColumnType } from './columnType';
|
|
2
|
-
import { getRawSql, isRaw, raw } from '../common';
|
|
3
2
|
import { Query } from '../query';
|
|
4
3
|
import { makeRegexToFindInSql, pushOrNewArrayToObject } from '../utils';
|
|
5
4
|
import {
|
|
@@ -7,6 +6,7 @@ import {
|
|
|
7
6
|
UpdateQueryData,
|
|
8
7
|
UpdateQueryDataItem,
|
|
9
8
|
} from '../sql';
|
|
9
|
+
import { getRawSql, isRaw, raw } from '../common';
|
|
10
10
|
|
|
11
11
|
export function timestamps<T extends ColumnType>(this: {
|
|
12
12
|
timestamp(): T;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { expectSql, User } from './test-utils';
|
|
2
|
-
import { raw } from './common';
|
|
1
|
+
import { db, expectSql, User } from './test-utils';
|
|
3
2
|
|
|
4
3
|
describe('operators', () => {
|
|
5
4
|
describe('equals', () => {
|
|
@@ -27,7 +26,7 @@ describe('operators', () => {
|
|
|
27
26
|
|
|
28
27
|
it('should handle raw query', () => {
|
|
29
28
|
expectSql(
|
|
30
|
-
User.where({ name: { equals: raw("'name'") } }).toSql(),
|
|
29
|
+
User.where({ name: { equals: db.raw("'name'") } }).toSql(),
|
|
31
30
|
`
|
|
32
31
|
SELECT * FROM "user"
|
|
33
32
|
WHERE "user"."name" = 'name'
|
|
@@ -61,7 +60,7 @@ describe('operators', () => {
|
|
|
61
60
|
|
|
62
61
|
it('should handle raw query', () => {
|
|
63
62
|
expectSql(
|
|
64
|
-
User.where({ name: { not: raw("'name'") } }).toSql(),
|
|
63
|
+
User.where({ name: { not: db.raw("'name'") } }).toSql(),
|
|
65
64
|
`
|
|
66
65
|
SELECT * FROM "user"
|
|
67
66
|
WHERE "user"."name" <> 'name'
|
|
@@ -94,7 +93,7 @@ describe('operators', () => {
|
|
|
94
93
|
|
|
95
94
|
it('should handle raw query', () => {
|
|
96
95
|
expectSql(
|
|
97
|
-
User.where({ name: { in: raw("('a', 'b')") } }).toSql(),
|
|
96
|
+
User.where({ name: { in: db.raw("('a', 'b')") } }).toSql(),
|
|
98
97
|
`
|
|
99
98
|
SELECT * FROM "user"
|
|
100
99
|
WHERE "user"."name" IN ('a', 'b')
|
|
@@ -127,7 +126,7 @@ describe('operators', () => {
|
|
|
127
126
|
|
|
128
127
|
it('should handle raw query', () => {
|
|
129
128
|
expectSql(
|
|
130
|
-
User.where({ name: { notIn: raw("('a', 'b')") } }).toSql(),
|
|
129
|
+
User.where({ name: { notIn: db.raw("('a', 'b')") } }).toSql(),
|
|
131
130
|
`
|
|
132
131
|
SELECT * FROM "user"
|
|
133
132
|
WHERE NOT "user"."name" IN ('a', 'b')
|
|
@@ -161,7 +160,7 @@ describe('operators', () => {
|
|
|
161
160
|
|
|
162
161
|
it('should handle raw query', () => {
|
|
163
162
|
expectSql(
|
|
164
|
-
User.where({ id: { lt: raw('5') } }).toSql(),
|
|
163
|
+
User.where({ id: { lt: db.raw('5') } }).toSql(),
|
|
165
164
|
`
|
|
166
165
|
SELECT * FROM "user"
|
|
167
166
|
WHERE "user"."id" < 5
|
|
@@ -195,7 +194,7 @@ describe('operators', () => {
|
|
|
195
194
|
|
|
196
195
|
it('should handle raw query', () => {
|
|
197
196
|
expectSql(
|
|
198
|
-
User.where({ id: { lte: raw('5') } }).toSql(),
|
|
197
|
+
User.where({ id: { lte: db.raw('5') } }).toSql(),
|
|
199
198
|
`
|
|
200
199
|
SELECT * FROM "user"
|
|
201
200
|
WHERE "user"."id" <= 5
|
|
@@ -229,7 +228,7 @@ describe('operators', () => {
|
|
|
229
228
|
|
|
230
229
|
it('should handle raw query', () => {
|
|
231
230
|
expectSql(
|
|
232
|
-
User.where({ id: { gt: raw('5') } }).toSql(),
|
|
231
|
+
User.where({ id: { gt: db.raw('5') } }).toSql(),
|
|
233
232
|
`
|
|
234
233
|
SELECT * FROM "user"
|
|
235
234
|
WHERE "user"."id" > 5
|
|
@@ -263,7 +262,7 @@ describe('operators', () => {
|
|
|
263
262
|
|
|
264
263
|
it('should handle raw query', () => {
|
|
265
264
|
expectSql(
|
|
266
|
-
User.where({ id: { gte: raw('5') } }).toSql(),
|
|
265
|
+
User.where({ id: { gte: db.raw('5') } }).toSql(),
|
|
267
266
|
`
|
|
268
267
|
SELECT * FROM "user"
|
|
269
268
|
WHERE "user"."id" >= 5
|
|
@@ -297,7 +296,7 @@ describe('operators', () => {
|
|
|
297
296
|
|
|
298
297
|
it('should handle raw query', () => {
|
|
299
298
|
expectSql(
|
|
300
|
-
User.where({ name: { contains: raw("'ko'") } }).toSql(),
|
|
299
|
+
User.where({ name: { contains: db.raw("'ko'") } }).toSql(),
|
|
301
300
|
`
|
|
302
301
|
SELECT * FROM "user"
|
|
303
302
|
WHERE "user"."name" LIKE '%' || 'ko' || '%'
|
|
@@ -333,7 +332,7 @@ describe('operators', () => {
|
|
|
333
332
|
|
|
334
333
|
it('should handle raw query', () => {
|
|
335
334
|
expectSql(
|
|
336
|
-
User.where({ name: { containsInsensitive: raw("'ko'") } }).toSql(),
|
|
335
|
+
User.where({ name: { containsInsensitive: db.raw("'ko'") } }).toSql(),
|
|
337
336
|
`
|
|
338
337
|
SELECT * FROM "user"
|
|
339
338
|
WHERE "user"."name" ILIKE '%' || 'ko' || '%'
|
|
@@ -369,7 +368,7 @@ describe('operators', () => {
|
|
|
369
368
|
|
|
370
369
|
it('should handle raw query', () => {
|
|
371
370
|
expectSql(
|
|
372
|
-
User.where({ name: { startsWith: raw("'ko'") } }).toSql(),
|
|
371
|
+
User.where({ name: { startsWith: db.raw("'ko'") } }).toSql(),
|
|
373
372
|
`
|
|
374
373
|
SELECT * FROM "user"
|
|
375
374
|
WHERE "user"."name" LIKE 'ko' || '%'
|
|
@@ -405,7 +404,7 @@ describe('operators', () => {
|
|
|
405
404
|
|
|
406
405
|
it('should handle raw query', () => {
|
|
407
406
|
expectSql(
|
|
408
|
-
User.where({ name: { startsWithInsensitive: raw("'ko'") } }).toSql(),
|
|
407
|
+
User.where({ name: { startsWithInsensitive: db.raw("'ko'") } }).toSql(),
|
|
409
408
|
`
|
|
410
409
|
SELECT * FROM "user"
|
|
411
410
|
WHERE "user"."name" ILIKE 'ko' || '%'
|
|
@@ -441,7 +440,7 @@ describe('operators', () => {
|
|
|
441
440
|
|
|
442
441
|
it('should handle raw query', () => {
|
|
443
442
|
expectSql(
|
|
444
|
-
User.where({ name: { endsWith: raw("'ko'") } }).toSql(),
|
|
443
|
+
User.where({ name: { endsWith: db.raw("'ko'") } }).toSql(),
|
|
445
444
|
`
|
|
446
445
|
SELECT * FROM "user"
|
|
447
446
|
WHERE "user"."name" LIKE '%' || 'ko'
|
|
@@ -477,7 +476,7 @@ describe('operators', () => {
|
|
|
477
476
|
|
|
478
477
|
it('should handle raw query', () => {
|
|
479
478
|
expectSql(
|
|
480
|
-
User.where({ name: { endsWithInsensitive: raw("'ko'") } }).toSql(),
|
|
479
|
+
User.where({ name: { endsWithInsensitive: db.raw("'ko'") } }).toSql(),
|
|
481
480
|
`
|
|
482
481
|
SELECT * FROM "user"
|
|
483
482
|
WHERE "user"."name" ILIKE '%' || 'ko'
|
|
@@ -515,7 +514,7 @@ describe('operators', () => {
|
|
|
515
514
|
|
|
516
515
|
it('should handle raw query', () => {
|
|
517
516
|
expectSql(
|
|
518
|
-
User.where({ id: { between: [raw('1'), raw('10')] } }).toSql(),
|
|
517
|
+
User.where({ id: { between: [db.raw('1'), db.raw('10')] } }).toSql(),
|
|
519
518
|
`
|
|
520
519
|
SELECT * FROM "user"
|
|
521
520
|
WHERE "user"."id" BETWEEN 1 AND 10
|
|
@@ -554,7 +553,7 @@ describe('operators', () => {
|
|
|
554
553
|
it('should handle raw query', () => {
|
|
555
554
|
expectSql(
|
|
556
555
|
User.where({
|
|
557
|
-
data: { jsonPath: ['$.name', '=', raw("'name'")] },
|
|
556
|
+
data: { jsonPath: ['$.name', '=', db.raw("'name'")] },
|
|
558
557
|
}).toSql(),
|
|
559
558
|
`
|
|
560
559
|
SELECT * FROM "user"
|
|
@@ -596,7 +595,7 @@ describe('operators', () => {
|
|
|
596
595
|
it('should handle raw query', () => {
|
|
597
596
|
expectSql(
|
|
598
597
|
User.where({
|
|
599
|
-
data: { [method]: raw(`'{"a":"b"}'`) },
|
|
598
|
+
data: { [method]: db.raw(`'{"a":"b"}'`) },
|
|
600
599
|
}).toSql(),
|
|
601
600
|
`
|
|
602
601
|
SELECT * FROM "user"
|
package/src/columnsOperators.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Query } from './query';
|
|
2
|
-
import { getRaw, isRaw, RawExpression } from './common';
|
|
3
2
|
import { quote } from './quote';
|
|
4
3
|
import { addValue } from './sql/common';
|
|
4
|
+
import { getRaw, isRaw, RawExpression } from './common';
|
|
5
5
|
|
|
6
6
|
type Fn<T> = (key: string, value: T, values: unknown[]) => string;
|
|
7
7
|
|