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.
Files changed (51) hide show
  1. package/dist/index.d.ts +24 -13
  2. package/dist/index.esm.js +44 -33
  3. package/dist/index.esm.js.map +1 -1
  4. package/dist/index.js +44 -32
  5. package/dist/index.js.map +1 -1
  6. package/package.json +1 -1
  7. package/src/columnSchema/columnTypes.test.ts +55 -53
  8. package/src/columnSchema/timestamps.test.ts +3 -4
  9. package/src/columnSchema/timestamps.ts +1 -1
  10. package/src/columnsOperators.test.ts +18 -19
  11. package/src/columnsOperators.ts +1 -1
  12. package/src/common.ts +17 -30
  13. package/src/db.ts +19 -8
  14. package/src/errors.test.ts +2 -4
  15. package/src/index.ts +1 -1
  16. package/src/query.ts +7 -1
  17. package/src/queryMethods/aggregate.test.ts +9 -7
  18. package/src/queryMethods/create.test.ts +5 -5
  19. package/src/queryMethods/create.ts +1 -1
  20. package/src/queryMethods/delete.ts +2 -0
  21. package/src/queryMethods/for.test.ts +1 -2
  22. package/src/queryMethods/for.ts +1 -1
  23. package/src/queryMethods/from.test.ts +2 -3
  24. package/src/queryMethods/get.test.ts +5 -5
  25. package/src/queryMethods/having.test.ts +6 -5
  26. package/src/queryMethods/index.ts +1 -0
  27. package/src/queryMethods/json.ts +2 -2
  28. package/src/queryMethods/merge.test.ts +10 -4
  29. package/src/queryMethods/queryMethods.test.ts +10 -12
  30. package/src/queryMethods/queryMethods.ts +7 -4
  31. package/src/queryMethods/raw.test.ts +19 -0
  32. package/src/queryMethods/raw.ts +27 -0
  33. package/src/queryMethods/select.test.ts +5 -209
  34. package/src/queryMethods/then.test.ts +2 -4
  35. package/src/queryMethods/union.test.ts +11 -6
  36. package/src/queryMethods/update.test.ts +3 -3
  37. package/src/queryMethods/where.test.ts +65 -56
  38. package/src/queryMethods/where.ts +1 -1
  39. package/src/queryMethods/with.test.ts +5 -6
  40. package/src/relations.ts +15 -4
  41. package/src/sql/common.ts +0 -1
  42. package/src/sql/fromAndAs.ts +1 -1
  43. package/src/sql/insert.ts +1 -1
  44. package/src/sql/join.ts +1 -1
  45. package/src/sql/orderBy.ts +1 -1
  46. package/src/sql/select.ts +1 -2
  47. package/src/sql/toSql.ts +1 -1
  48. package/src/sql/update.ts +1 -1
  49. package/src/sql/where.ts +1 -1
  50. package/src/sql/window.ts +3 -4
  51. package/src/sql/with.ts +1 -1
@@ -1,5 +1,4 @@
1
- import { expectSql, Message, User } from '../test-utils';
2
- import { raw } from '../common';
1
+ import { db, expectSql, Message, User } from '../test-utils';
3
2
  import { Sql } from '../sql';
4
3
  import { Query } from '../query';
5
4
  import { pushQueryOn } from './join';
@@ -107,7 +106,7 @@ export const testWhere = (
107
106
 
108
107
  it('should handle condition with operator and raw', () => {
109
108
  expectSql(
110
- buildSql((q) => q.where({ id: { in: raw('(1, 2, 3)') } })),
109
+ buildSql((q) => q.where({ id: { in: db.raw('(1, 2, 3)') } })),
111
110
  `
112
111
  ${startSql}
113
112
  "user"."id" IN (1, 2, 3)
@@ -117,7 +116,7 @@ export const testWhere = (
117
116
 
118
117
  it('should accept raw sql', () => {
119
118
  expectSql(
120
- buildSql((q) => q.where({ id: raw('1 + 2') })),
119
+ buildSql((q) => q.where({ id: db.raw('1 + 2') })),
121
120
  `
122
121
  ${startSql} "user"."id" = 1 + 2
123
122
  `,
@@ -195,8 +194,10 @@ export const testWhere = (
195
194
  it('should handle condition with operator and raw', () => {
196
195
  expectSql(
197
196
  [
198
- buildSql((q) => q.where({ NOT: { id: { in: raw('(1, 2, 3)') } } })),
199
- buildSql((q) => q.whereNot({ id: { in: raw('(1, 2, 3)') } })),
197
+ buildSql((q) =>
198
+ q.where({ NOT: { id: { in: db.raw('(1, 2, 3)') } } }),
199
+ ),
200
+ buildSql((q) => q.whereNot({ id: { in: db.raw('(1, 2, 3)') } })),
200
201
  ],
201
202
  `
202
203
  ${startSql}
@@ -208,8 +209,8 @@ export const testWhere = (
208
209
  it('should accept raw sql', () => {
209
210
  expectSql(
210
211
  [
211
- buildSql((q) => q.where({ NOT: { id: raw('1 + 2') } })),
212
- buildSql((q) => q.whereNot({ id: raw('1 + 2') })),
212
+ buildSql((q) => q.where({ NOT: { id: db.raw('1 + 2') } })),
213
+ buildSql((q) => q.whereNot({ id: db.raw('1 + 2') })),
213
214
  ],
214
215
  `
215
216
  ${startSql} NOT "user"."id" = 1 + 2
@@ -284,9 +285,13 @@ export const testWhere = (
284
285
  expectSql(
285
286
  [
286
287
  buildSql((q) =>
287
- q.where({ OR: [{ id: raw('1 + 2') }, { name: raw('2 + 3') }] }),
288
+ q.where({
289
+ OR: [{ id: db.raw('1 + 2') }, { name: db.raw('2 + 3') }],
290
+ }),
291
+ ),
292
+ buildSql((q) =>
293
+ q.or({ id: db.raw('1 + 2') }, { name: db.raw('2 + 3') }),
288
294
  ),
289
- buildSql((q) => q.or({ id: raw('1 + 2') }, { name: raw('2 + 3') })),
290
295
  ],
291
296
  `
292
297
  ${startSql}
@@ -347,13 +352,13 @@ export const testWhere = (
347
352
  buildSql((q) =>
348
353
  q.where({
349
354
  OR: [
350
- { NOT: { id: raw('1 + 2') } },
351
- { NOT: { name: raw('2 + 3') } },
355
+ { NOT: { id: db.raw('1 + 2') } },
356
+ { NOT: { name: db.raw('2 + 3') } },
352
357
  ],
353
358
  }),
354
359
  ),
355
360
  buildSql((q) =>
356
- q.orNot({ id: raw('1 + 2') }, { name: raw('2 + 3') }),
361
+ q.orNot({ id: db.raw('1 + 2') }, { name: db.raw('2 + 3') }),
357
362
  ),
358
363
  ],
359
364
  `
@@ -412,9 +417,9 @@ export const testWhere = (
412
417
  expectSql(
413
418
  [
414
419
  buildSql((q) =>
415
- q.where({ IN: { columns: ['id'], values: raw('(1, 2, 3)') } }),
420
+ q.where({ IN: { columns: ['id'], values: db.raw('(1, 2, 3)') } }),
416
421
  ),
417
- buildSql((q) => q.whereIn('id', raw('(1, 2, 3)'))),
422
+ buildSql((q) => q.whereIn('id', db.raw('(1, 2, 3)'))),
418
423
  ],
419
424
  `
420
425
  ${startSql}
@@ -427,15 +432,15 @@ export const testWhere = (
427
432
  buildSql((q) =>
428
433
  q.where({
429
434
  IN: [
430
- { columns: ['id'], values: raw('(1, 2, 3)') },
431
- { columns: ['name'], values: raw(`('a', 'b', 'c')`) },
435
+ { columns: ['id'], values: db.raw('(1, 2, 3)') },
436
+ { columns: ['name'], values: db.raw(`('a', 'b', 'c')`) },
432
437
  ],
433
438
  }),
434
439
  ),
435
440
  buildSql((q) =>
436
441
  q.whereIn({
437
- id: raw('(1, 2, 3)'),
438
- name: raw(`('a', 'b', 'c')`),
442
+ id: db.raw('(1, 2, 3)'),
443
+ name: db.raw(`('a', 'b', 'c')`),
439
444
  }),
440
445
  ),
441
446
  ],
@@ -526,12 +531,12 @@ export const testWhere = (
526
531
  q.where({
527
532
  IN: {
528
533
  columns: ['id', 'name'],
529
- values: raw(`((1, 'a'), (2, 'b'))`),
534
+ values: db.raw(`((1, 'a'), (2, 'b'))`),
530
535
  },
531
536
  }),
532
537
  ),
533
538
  buildSql((q) =>
534
- q.whereIn(['id', 'name'], raw(`((1, 'a'), (2, 'b'))`)),
539
+ q.whereIn(['id', 'name'], db.raw(`((1, 'a'), (2, 'b'))`)),
535
540
  ),
536
541
  ],
537
542
  `
@@ -624,12 +629,12 @@ export const testWhere = (
624
629
  q.where({
625
630
  OR: [
626
631
  { id: 1 },
627
- { IN: { columns: ['id'], values: raw('(1, 2, 3)') } },
632
+ { IN: { columns: ['id'], values: db.raw('(1, 2, 3)') } },
628
633
  ],
629
634
  }),
630
635
  ),
631
636
  buildSql((q) =>
632
- q.where({ id: 1 }).orWhereIn({ id: raw('(1, 2, 3)') }),
637
+ q.where({ id: 1 }).orWhereIn({ id: db.raw('(1, 2, 3)') }),
633
638
  ),
634
639
  ],
635
640
  `
@@ -647,8 +652,8 @@ export const testWhere = (
647
652
  { id: 1 },
648
653
  {
649
654
  IN: [
650
- { columns: ['id'], values: raw('(1, 2, 3)') },
651
- { columns: ['name'], values: raw(`('a', 'b', 'c')`) },
655
+ { columns: ['id'], values: db.raw('(1, 2, 3)') },
656
+ { columns: ['name'], values: db.raw(`('a', 'b', 'c')`) },
652
657
  ],
653
658
  },
654
659
  ],
@@ -656,8 +661,8 @@ export const testWhere = (
656
661
  ),
657
662
  buildSql((q) =>
658
663
  q.where({ id: 1 }).orWhereIn({
659
- id: raw('(1, 2, 3)'),
660
- name: raw(`('a', 'b', 'c')`),
664
+ id: db.raw('(1, 2, 3)'),
665
+ name: db.raw(`('a', 'b', 'c')`),
661
666
  }),
662
667
  ),
663
668
  ],
@@ -775,7 +780,7 @@ export const testWhere = (
775
780
  {
776
781
  IN: {
777
782
  columns: ['id', 'name'],
778
- values: raw(`((1, 'a'), (2, 'b'))`),
783
+ values: db.raw(`((1, 'a'), (2, 'b'))`),
779
784
  },
780
785
  },
781
786
  ],
@@ -784,7 +789,7 @@ export const testWhere = (
784
789
  buildSql((q) =>
785
790
  q
786
791
  .where({ id: 1 })
787
- .orWhereIn(['id', 'name'], raw(`((1, 'a'), (2, 'b'))`)),
792
+ .orWhereIn(['id', 'name'], db.raw(`((1, 'a'), (2, 'b'))`)),
788
793
  ),
789
794
  ],
790
795
  `
@@ -882,12 +887,12 @@ export const testWhere = (
882
887
  [
883
888
  buildSql((q) =>
884
889
  q.where({
885
- NOT: { IN: { columns: ['id'], values: raw('(1, 2, 3)') } },
890
+ NOT: { IN: { columns: ['id'], values: db.raw('(1, 2, 3)') } },
886
891
  }),
887
892
  ),
888
893
  buildSql((q) =>
889
894
  q.whereNotIn({
890
- id: raw('(1, 2, 3)'),
895
+ id: db.raw('(1, 2, 3)'),
891
896
  }),
892
897
  ),
893
898
  ],
@@ -903,16 +908,16 @@ export const testWhere = (
903
908
  q.where({
904
909
  NOT: {
905
910
  IN: [
906
- { columns: ['id'], values: raw('(1, 2, 3)') },
907
- { columns: ['name'], values: raw(`('a', 'b', 'c')`) },
911
+ { columns: ['id'], values: db.raw('(1, 2, 3)') },
912
+ { columns: ['name'], values: db.raw(`('a', 'b', 'c')`) },
908
913
  ],
909
914
  },
910
915
  }),
911
916
  ),
912
917
  buildSql((q) =>
913
918
  q.whereNotIn({
914
- id: raw('(1, 2, 3)'),
915
- name: raw(`('a', 'b', 'c')`),
919
+ id: db.raw('(1, 2, 3)'),
920
+ name: db.raw(`('a', 'b', 'c')`),
916
921
  }),
917
922
  ),
918
923
  ],
@@ -1014,13 +1019,13 @@ export const testWhere = (
1014
1019
  NOT: {
1015
1020
  IN: {
1016
1021
  columns: ['id', 'name'],
1017
- values: raw(`((1, 'a'), (2, 'b'))`),
1022
+ values: db.raw(`((1, 'a'), (2, 'b'))`),
1018
1023
  },
1019
1024
  },
1020
1025
  }),
1021
1026
  ),
1022
1027
  buildSql((q) =>
1023
- q.whereNotIn(['id', 'name'], raw(`((1, 'a'), (2, 'b'))`)),
1028
+ q.whereNotIn(['id', 'name'], db.raw(`((1, 'a'), (2, 'b'))`)),
1024
1029
  ),
1025
1030
  ],
1026
1031
  `
@@ -1125,14 +1130,14 @@ export const testWhere = (
1125
1130
  OR: [
1126
1131
  { id: 1 },
1127
1132
  {
1128
- NOT: { IN: { columns: ['id'], values: raw('(1, 2, 3)') } },
1133
+ NOT: { IN: { columns: ['id'], values: db.raw('(1, 2, 3)') } },
1129
1134
  },
1130
1135
  ],
1131
1136
  }),
1132
1137
  ),
1133
1138
  buildSql((q) =>
1134
1139
  q.where({ id: 1 }).orWhereNotIn({
1135
- id: raw('(1, 2, 3)'),
1140
+ id: db.raw('(1, 2, 3)'),
1136
1141
  }),
1137
1142
  ),
1138
1143
  ],
@@ -1152,8 +1157,8 @@ export const testWhere = (
1152
1157
  {
1153
1158
  NOT: {
1154
1159
  IN: [
1155
- { columns: ['id'], values: raw('(1, 2, 3)') },
1156
- { columns: ['name'], values: raw(`('a', 'b', 'c')`) },
1160
+ { columns: ['id'], values: db.raw('(1, 2, 3)') },
1161
+ { columns: ['name'], values: db.raw(`('a', 'b', 'c')`) },
1157
1162
  ],
1158
1163
  },
1159
1164
  },
@@ -1162,8 +1167,8 @@ export const testWhere = (
1162
1167
  ),
1163
1168
  buildSql((q) =>
1164
1169
  q.where({ id: 1 }).orWhereNotIn({
1165
- id: raw('(1, 2, 3)'),
1166
- name: raw(`('a', 'b', 'c')`),
1170
+ id: db.raw('(1, 2, 3)'),
1171
+ name: db.raw(`('a', 'b', 'c')`),
1167
1172
  }),
1168
1173
  ),
1169
1174
  ],
@@ -1288,7 +1293,7 @@ export const testWhere = (
1288
1293
  NOT: {
1289
1294
  IN: {
1290
1295
  columns: ['id', 'name'],
1291
- values: raw(`((1, 'a'), (2, 'b'))`),
1296
+ values: db.raw(`((1, 'a'), (2, 'b'))`),
1292
1297
  },
1293
1298
  },
1294
1299
  },
@@ -1298,7 +1303,7 @@ export const testWhere = (
1298
1303
  buildSql((q) =>
1299
1304
  q
1300
1305
  .where({ id: 1 })
1301
- .orWhereNotIn(['id', 'name'], raw(`((1, 'a'), (2, 'b'))`)),
1306
+ .orWhereNotIn(['id', 'name'], db.raw(`((1, 'a'), (2, 'b'))`)),
1302
1307
  ),
1303
1308
  ],
1304
1309
  `
@@ -1446,15 +1451,19 @@ export const testJoin = (
1446
1451
 
1447
1452
  it('should accept raw and raw', () => {
1448
1453
  expectSql(
1449
- q[join](Message, raw('"message"."authorId"'), raw('"user"."id"')).toSql(),
1454
+ q[join](
1455
+ Message,
1456
+ db.raw('"message"."authorId"'),
1457
+ db.raw('"user"."id"'),
1458
+ ).toSql(),
1450
1459
  sql(`"message"`, `"message"."authorId" = "user"."id"`),
1451
1460
  values,
1452
1461
  );
1453
1462
  expectSql(
1454
1463
  q[join](
1455
1464
  Message.as('as'),
1456
- raw('"as"."authorId"'),
1457
- raw('"user"."id"'),
1465
+ db.raw('"as"."authorId"'),
1466
+ db.raw('"user"."id"'),
1458
1467
  ).toSql(),
1459
1468
  sql(`"message" AS "as"`, `"as"."authorId" = "user"."id"`),
1460
1469
  values,
@@ -1466,9 +1475,9 @@ export const testJoin = (
1466
1475
  expectSql(
1467
1476
  q[join](
1468
1477
  Message,
1469
- raw('"message"."authorId"'),
1478
+ db.raw('"message"."authorId"'),
1470
1479
  '=',
1471
- raw('"user"."id"'),
1480
+ db.raw('"user"."id"'),
1472
1481
  ).toSql(),
1473
1482
  sql(`"message"`, `"message"."authorId" = "user"."id"`),
1474
1483
  values,
@@ -1476,9 +1485,9 @@ export const testJoin = (
1476
1485
  expectSql(
1477
1486
  q[join](
1478
1487
  Message.as('as'),
1479
- raw('"as"."authorId"'),
1488
+ db.raw('"as"."authorId"'),
1480
1489
  '=',
1481
- raw('"user"."id"'),
1490
+ db.raw('"user"."id"'),
1482
1491
  ).toSql(),
1483
1492
  sql(`"message" AS "as"`, `"as"."authorId" = "user"."id"`),
1484
1493
  values,
@@ -1502,12 +1511,12 @@ export const testJoin = (
1502
1511
 
1503
1512
  it('should accept object of columns with raw value', () => {
1504
1513
  expectSql(
1505
- q[join](Message, { authorId: raw('"user"."id"') }).toSql(),
1514
+ q[join](Message, { authorId: db.raw('"user"."id"') }).toSql(),
1506
1515
  sql(`"message"`, `"message"."authorId" = "user"."id"`),
1507
1516
  values,
1508
1517
  );
1509
1518
  expectSql(
1510
- q[join](Message.as('as'), { authorId: raw('"user"."id"') }).toSql(),
1519
+ q[join](Message.as('as'), { authorId: db.raw('"user"."id"') }).toSql(),
1511
1520
  sql(`"message" AS "as"`, `"as"."authorId" = "user"."id"`),
1512
1521
  values,
1513
1522
  );
@@ -1516,12 +1525,12 @@ export const testJoin = (
1516
1525
 
1517
1526
  it('should accept raw sql', () => {
1518
1527
  expectSql(
1519
- q[join](Message, raw('"authorId" = "user".id')).toSql(),
1528
+ q[join](Message, db.raw('"authorId" = "user".id')).toSql(),
1520
1529
  sql(`"message"`, `"authorId" = "user".id`),
1521
1530
  values,
1522
1531
  );
1523
1532
  expectSql(
1524
- q[join](Message.as('as'), raw('"authorId" = "user".id')).toSql(),
1533
+ q[join](Message.as('as'), db.raw('"authorId" = "user".id')).toSql(),
1525
1534
  sql(`"message" AS "as"`, `"authorId" = "user".id`),
1526
1535
  values,
1527
1536
  );
@@ -1,11 +1,11 @@
1
1
  import { Query, QueryBase, SelectableBase, WithDataBase } from '../query';
2
2
  import { ColumnOperators, QueryData } from '../sql';
3
3
  import { pushQueryArray, pushQueryValue } from '../queryDataUtils';
4
- import { RawExpression } from '../common';
5
4
  import { getClonedQueryData, MaybeArray } from '../utils';
6
5
  import { JoinArgs, JoinCallback, JoinCallbackArg } from './join';
7
6
  import { RelationsBase } from '../relations';
8
7
  import { ColumnsShape } from '../columnSchema';
8
+ import { RawExpression } from '../common';
9
9
 
10
10
  export type WhereArg<T extends QueryBase> =
11
11
  | (Omit<
@@ -1,7 +1,6 @@
1
1
  import { WithOptions } from '../sql';
2
- import { expectQueryNotMutated, expectSql, User } from '../test-utils';
3
- import { columnTypes, NumberColumn } from '../columnSchema';
4
- import { raw } from '../common';
2
+ import { db, expectQueryNotMutated, expectSql, User } from '../test-utils';
3
+ import { columnTypes } from '../columnSchema';
5
4
 
6
5
  describe('with', () => {
7
6
  const options: (
@@ -51,7 +50,7 @@ describe('with', () => {
51
50
  const args: Parameters<typeof q.with> = [
52
51
  'withAlias',
53
52
  columnShape,
54
- raw(`(VALUES (1, 'two')) t(one, two)`),
53
+ db.raw(`(VALUES (1, 'two')) t(one, two)`),
55
54
  ];
56
55
 
57
56
  if (options) {
@@ -106,7 +105,7 @@ describe('with', () => {
106
105
  options.forEach((options) => {
107
106
  const args: Parameters<typeof q.with> = [
108
107
  'withAlias',
109
- (qb) => qb.select({ one: raw<NumberColumn>('1') }),
108
+ (qb) => qb.select({ one: db.raw((t) => t.integer(), '1') }),
110
109
  ];
111
110
 
112
111
  if (options) {
@@ -147,7 +146,7 @@ describe('with', () => {
147
146
 
148
147
  const received3 = q
149
148
  .with('withAlias', User.all())
150
- .join('withAlias', raw(`"withAlias"."id" = "user"."id"`))
149
+ .join('withAlias', db.raw(`"withAlias"."id" = "user"."id"`))
151
150
  .select('withAlias.id')
152
151
  .toSql();
153
152
 
package/src/relations.ts CHANGED
@@ -1,6 +1,11 @@
1
1
  import { defaultsKey, Query, QueryBase, QueryWithTable } from './query';
2
- import { WhereArg, UpdateData, CreateMethodsNames } from './queryMethods';
3
- import { MaybeArray } from './utils';
2
+ import {
3
+ WhereArg,
4
+ UpdateData,
5
+ CreateMethodsNames,
6
+ DeleteMethodsNames,
7
+ } from './queryMethods';
8
+ import { EmptyObject, MaybeArray } from './utils';
4
9
 
5
10
  export type NestedInsertOneItem = {
6
11
  create?: Record<string, unknown>;
@@ -209,9 +214,15 @@ export type RelationQuery<
209
214
  T extends Query = Query,
210
215
  Required extends boolean = boolean,
211
216
  ChainedCreate extends boolean = false,
212
- Q extends RelationQueryBase = ChainedCreate extends true
217
+ ChainedDelete extends boolean = false,
218
+ Q extends RelationQueryBase = (ChainedCreate extends true
213
219
  ? PrepareRelationQuery<T, Name, Required, Populate>
214
220
  : PrepareRelationQuery<T, Name, Required, Populate> & {
215
221
  [K in CreateMethodsNames]: never;
216
- },
222
+ }) &
223
+ (ChainedDelete extends true
224
+ ? EmptyObject
225
+ : {
226
+ [K in DeleteMethodsNames]: never;
227
+ }),
217
228
  > = ((params: Params) => Q) & Q;
package/src/sql/common.ts CHANGED
@@ -1,4 +1,3 @@
1
- // quote table or column
2
1
  import { Query } from '../query';
3
2
  import { Expression, getRaw, isRaw } from '../common';
4
3
 
@@ -1,8 +1,8 @@
1
- import { getRaw, isRaw } from '../common';
2
1
  import { quoteSchemaAndTable } from './common';
3
2
  import { QueryBase } from '../query';
4
3
  import { checkIfASimpleQuery, SelectQueryData } from './types';
5
4
  import { ToSqlCtx } from './toSql';
5
+ import { getRaw, isRaw } from '../common';
6
6
 
7
7
  export const pushFromAndAs = (
8
8
  ctx: ToSqlCtx,
package/src/sql/insert.ts CHANGED
@@ -1,11 +1,11 @@
1
1
  import { InsertQueryData, QueryData } from './types';
2
2
  import { addValue, q } from './common';
3
- import { getRaw, isRaw, raw } from '../common';
4
3
  import { pushWhereStatementSql } from './where';
5
4
  import { QueryBase } from '../query';
6
5
  import { selectToSql } from './select';
7
6
  import { ToSqlCtx } from './toSql';
8
7
  import { pushQueryValue } from '../queryDataUtils';
8
+ import { getRaw, isRaw, raw } from '../common';
9
9
 
10
10
  export const pushInsertSql = (
11
11
  ctx: ToSqlCtx,
package/src/sql/join.ts CHANGED
@@ -1,10 +1,10 @@
1
1
  import { q, quoteFullColumn, quoteSchemaAndTable } from './common';
2
- import { getRaw, isRaw, RawExpression } from '../common';
3
2
  import { JoinItem, QueryData } from './types';
4
3
  import { QueryBase, QueryWithTable } from '../query';
5
4
  import { whereToSql } from './where';
6
5
  import { Relation } from '../relations';
7
6
  import { ToSqlCtx } from './toSql';
7
+ import { getRaw, isRaw, RawExpression } from '../common';
8
8
 
9
9
  type ItemOf3Or4Length =
10
10
  | [
@@ -1,7 +1,7 @@
1
1
  import { OrderItem, SelectQueryData } from './types';
2
- import { getRaw, isRaw } from '../common';
3
2
  import { qc } from './common';
4
3
  import { ToSqlCtx } from './toSql';
4
+ import { getRaw, isRaw } from '../common';
5
5
 
6
6
  export const pushOrderBySql = (
7
7
  ctx: ToSqlCtx,
package/src/sql/select.ts CHANGED
@@ -9,7 +9,6 @@ import { Query, QueryBase } from '../query';
9
9
  import { addValue, q, quoteFullColumn } from './common';
10
10
  import { aggregateToSql } from './aggregate';
11
11
  import { PormInternalError, UnhandledTypeError } from '../errors';
12
- import { StringColumn } from '../columnSchema';
13
12
  import { quote } from '../quote';
14
13
  import { ToSqlCtx } from './toSql';
15
14
  import { relationQueryKey } from '../relations';
@@ -166,7 +165,7 @@ const pushSubQuerySql = (
166
165
  select.length = 0;
167
166
  select[0] = { selectAs: { c: first } } as SelectItem;
168
167
  query = query._wrap(query.__model.clone()) as unknown as typeof query;
169
- query._getOptional(raw<StringColumn>(`COALESCE(json_agg("c"), '[]')`));
168
+ query._getOptional(raw(`COALESCE(json_agg("c"), '[]')`));
170
169
  break;
171
170
  }
172
171
  case 'rows':
package/src/sql/toSql.ts CHANGED
@@ -1,4 +1,3 @@
1
- import { getRaw, isRaw } from '../common';
2
1
  import { Query, queryTypeWithLimitOne } from '../query';
3
2
  import { addValue, q, qc } from './common';
4
3
  import { JoinItem, QueryData, Sql } from './types';
@@ -17,6 +16,7 @@ import { pushTruncateSql } from './truncate';
17
16
  import { pushColumnInfoSql } from './columnInfo';
18
17
  import { pushOrderBySql } from './orderBy';
19
18
  import { OnQueryBuilder, WhereQueryBuilder } from '../queryMethods';
19
+ import { getRaw, isRaw } from '../common';
20
20
 
21
21
  export type ToSqlCtx = {
22
22
  whereQueryBuilder: typeof WhereQueryBuilder;
package/src/sql/update.ts CHANGED
@@ -5,11 +5,11 @@ import {
5
5
  UpdateQueryDataObject,
6
6
  } from './types';
7
7
  import { addValue, q, quoteSchemaAndTable } from './common';
8
- import { getRaw, isRaw } from '../common';
9
8
  import { pushReturningSql } from './insert';
10
9
  import { pushWhereStatementSql } from './where';
11
10
  import { ToSqlCtx } from './toSql';
12
11
  import { pushOrNewArray } from '../utils';
12
+ import { getRaw, isRaw } from '../common';
13
13
 
14
14
  export const pushUpdateSql = (
15
15
  ctx: ToSqlCtx,
package/src/sql/where.ts CHANGED
@@ -9,10 +9,10 @@ import {
9
9
  WhereOnJoinItem,
10
10
  } from './types';
11
11
  import { addValue, q, qc, quoteFullColumn } from './common';
12
- import { getRaw, isRaw, RawExpression } from '../common';
13
12
  import { getQueryAs, MaybeArray, toArray } from '../utils';
14
13
  import { processJoinItem } from './join';
15
14
  import { ToSqlCtx } from './toSql';
15
+ import { getRaw, isRaw, RawExpression } from '../common';
16
16
 
17
17
  export const pushWhereStatementSql = (
18
18
  ctx: ToSqlCtx,
package/src/sql/window.ts CHANGED
@@ -1,11 +1,10 @@
1
- import { Query } from '../query';
2
1
  import { WindowDeclaration } from './types';
3
- import { getRaw, isRaw, RawExpression } from '../common';
4
2
  import { expressionToSql, q } from './common';
5
3
  import { orderByToSql } from './orderBy';
4
+ import { getRaw, isRaw, RawExpression } from '../common';
6
5
 
7
- export const windowToSql = <T extends Query>(
8
- window: keyof T['windows'] | WindowDeclaration | RawExpression,
6
+ export const windowToSql = (
7
+ window: string | WindowDeclaration | RawExpression,
9
8
  values: unknown[],
10
9
  quotedAs?: string,
11
10
  ) => {
package/src/sql/with.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { QueryData } from './types';
2
2
  import { q } from './common';
3
- import { isRaw, getRaw } from '../common';
4
3
  import { ToSqlCtx } from './toSql';
4
+ import { getRaw, isRaw } from '../common';
5
5
 
6
6
  export const pushWithSql = (
7
7
  ctx: ToSqlCtx,