pqb 0.42.4 → 0.42.5

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.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { ExpressionTypeMethod, Expression, RawSQLBase, emptyObject, isTemplateLiteralArgs, ColumnTypeBase, setColumnData, pushColumnData, quoteObjectKey, toArray, singleQuote, addCode, singleQuoteArray, objectHasValues, toSnakeCase, columnDefaultArgumentToCode, columnErrorMessagesToCode, getValueKey, emptyArray, addValue, isExpression, joinTruthy, stringDataToCode, getDefaultLanguage, dateDataToCode, returnArg as returnArg$1, noop, pushOrNewArrayToObject, arrayDataToCode, numberDataToCode, logColors, applyTransforms, callWithThis, setParserToQuery, isRawSQL, pushOrNewArray, setDefaultNowFn, setDefaultLanguage, makeTimestampsHelpers, setCurrentColumnName, setAdapterConnectRetry, isObjectEmpty, ValExpression, applyMixins, snakeCaseKey } from 'orchid-core';
1
+ import { ExpressionTypeMethod, Expression, RawSQLBase, emptyObject, isTemplateLiteralArgs, ColumnTypeBase, setColumnData, pushColumnData, quoteObjectKey, toArray, singleQuote, addCode, singleQuoteArray, objectHasValues, toSnakeCase, columnDefaultArgumentToCode, columnErrorMessagesToCode, getValueKey, emptyArray, addValue, isExpression, joinTruthy, stringDataToCode, getDefaultLanguage, dateDataToCode, returnArg as returnArg$1, noop, pushOrNewArrayToObject, arrayDataToCode, numberDataToCode, logColors, applyTransforms, callWithThis, setParserToQuery, isRawSQL, pushOrNewArray, setDefaultNowFn, setDefaultLanguage, setCurrentColumnName, makeTimestampsHelpers, setAdapterConnectRetry, isObjectEmpty, ValExpression, applyMixins, snakeCaseKey } from 'orchid-core';
2
2
  import pg from 'pg';
3
3
  import { inspect } from 'node:util';
4
4
  import { AsyncLocalStorage } from 'node:async_hooks';
@@ -54,8 +54,7 @@ class RawSQL extends RawSQLBase {
54
54
  used.length = 0;
55
55
  for (let i = 0; i < len; i += 2) {
56
56
  arr[i] = arr[i].replace(/\$\$?(\w+)/g, (match, key, i2) => {
57
- if (isTemplate && literalValues.includes(i2))
58
- return match;
57
+ if (isTemplate && literalValues.includes(i2)) return match;
59
58
  const value = data[key];
60
59
  if (value === void 0) {
61
60
  throw new Error(`Query variable \`${key}\` is not provided`);
@@ -117,25 +116,6 @@ const sqlFn = (...args) => {
117
116
  return (...args2) => new RawSQL(args2, arg);
118
117
  };
119
118
 
120
- var __defProp$p = Object.defineProperty;
121
- var __defProps$f = Object.defineProperties;
122
- var __getOwnPropDescs$f = Object.getOwnPropertyDescriptors;
123
- var __getOwnPropSymbols$q = Object.getOwnPropertySymbols;
124
- var __hasOwnProp$q = Object.prototype.hasOwnProperty;
125
- var __propIsEnum$q = Object.prototype.propertyIsEnumerable;
126
- var __defNormalProp$p = (obj, key, value) => key in obj ? __defProp$p(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
127
- var __spreadValues$p = (a, b) => {
128
- for (var prop in b || (b = {}))
129
- if (__hasOwnProp$q.call(b, prop))
130
- __defNormalProp$p(a, prop, b[prop]);
131
- if (__getOwnPropSymbols$q)
132
- for (var prop of __getOwnPropSymbols$q(b)) {
133
- if (__propIsEnum$q.call(b, prop))
134
- __defNormalProp$p(a, prop, b[prop]);
135
- }
136
- return a;
137
- };
138
- var __spreadProps$f = (a, b) => __defProps$f(a, __getOwnPropDescs$f(b));
139
119
  class ColumnType extends ColumnTypeBase {
140
120
  /**
141
121
  * Mark the column as a primary key.
@@ -162,7 +142,7 @@ class ColumnType extends ColumnTypeBase {
162
142
  * @param name - to specify a constraint name
163
143
  */
164
144
  primaryKey(name) {
165
- return setColumnData(this, "primaryKey", name != null ? name : true);
145
+ return setColumnData(this, "primaryKey", name ?? true);
166
146
  }
167
147
  foreignKey(fnOrTable, column, options = emptyObject) {
168
148
  return pushColumnData(this, "foreignKeys", {
@@ -224,9 +204,8 @@ class ColumnType extends ColumnTypeBase {
224
204
  * @param args
225
205
  */
226
206
  index(...args) {
227
- var _a;
228
207
  return pushColumnData(this, "indexes", {
229
- options: (_a = typeof args[0] === "string" ? args[1] : args[0]) != null ? _a : emptyObject,
208
+ options: (typeof args[0] === "string" ? args[1] : args[0]) ?? emptyObject,
230
209
  name: typeof args[0] === "string" ? args[0] : void 0
231
210
  });
232
211
  }
@@ -334,15 +313,19 @@ class ColumnType extends ColumnTypeBase {
334
313
  */
335
314
  searchIndex(...args) {
336
315
  return pushColumnData(this, "indexes", {
337
- options: __spreadValues$p(__spreadValues$p({}, typeof args[0] === "string" ? args[1] : args[0]), this.dataType === "tsvector" ? { using: "GIN" } : { tsVector: true }),
316
+ options: {
317
+ ...typeof args[0] === "string" ? args[1] : args[0],
318
+ ...this.dataType === "tsvector" ? { using: "GIN" } : { tsVector: true }
319
+ },
338
320
  name: typeof args[0] === "string" ? args[0] : void 0
339
321
  });
340
322
  }
341
323
  unique(...args) {
342
324
  return pushColumnData(this, "indexes", {
343
- options: __spreadProps$f(__spreadValues$p({}, typeof args[0] === "string" ? args[1] : args[0]), {
325
+ options: {
326
+ ...typeof args[0] === "string" ? args[1] : args[0],
344
327
  unique: true
345
- }),
328
+ },
346
329
  name: typeof args[0] === "string" ? args[0] : void 0
347
330
  });
348
331
  }
@@ -383,25 +366,6 @@ class ColumnType extends ColumnTypeBase {
383
366
  }
384
367
  }
385
368
 
386
- var __defProp$o = Object.defineProperty;
387
- var __defProps$e = Object.defineProperties;
388
- var __getOwnPropDescs$e = Object.getOwnPropertyDescriptors;
389
- var __getOwnPropSymbols$p = Object.getOwnPropertySymbols;
390
- var __hasOwnProp$p = Object.prototype.hasOwnProperty;
391
- var __propIsEnum$p = Object.prototype.propertyIsEnumerable;
392
- var __defNormalProp$o = (obj, key, value) => key in obj ? __defProp$o(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
393
- var __spreadValues$o = (a, b) => {
394
- for (var prop in b || (b = {}))
395
- if (__hasOwnProp$p.call(b, prop))
396
- __defNormalProp$o(a, prop, b[prop]);
397
- if (__getOwnPropSymbols$p)
398
- for (var prop of __getOwnPropSymbols$p(b)) {
399
- if (__propIsEnum$p.call(b, prop))
400
- __defNormalProp$o(a, prop, b[prop]);
401
- }
402
- return a;
403
- };
404
- var __spreadProps$e = (a, b) => __defProps$e(a, __getOwnPropDescs$e(b));
405
369
  const knownDefaults = {
406
370
  current_timestamp: "now()",
407
371
  "transaction_timestamp()": "now()"
@@ -417,28 +381,26 @@ const simplifyColumnDefault = (value) => {
417
381
  const instantiateColumn = (typeFn, params) => {
418
382
  const column = typeFn();
419
383
  const { dateTimePrecision } = params;
420
- Object.assign(column.data, __spreadProps$e(__spreadValues$o({}, params), {
384
+ Object.assign(column.data, {
385
+ ...params,
421
386
  dateTimePrecision: (
422
387
  // 0 is default for date, 6 is default for timestamp
423
388
  dateTimePrecision && dateTimePrecision !== 6 ? dateTimePrecision : void 0
424
389
  ),
425
390
  collate: params.collate,
426
391
  default: simplifyColumnDefault(params.default)
427
- }));
392
+ });
428
393
  return column;
429
394
  };
430
395
 
431
396
  const isDefaultTimeStamp = (item) => {
432
- if (item.dataType !== "timestamptz")
433
- return false;
397
+ if (item.dataType !== "timestamptz") return false;
434
398
  const def = item.data.default;
435
- if (!(def instanceof RawSQLBase))
436
- return false;
399
+ if (!(def instanceof RawSQLBase)) return false;
437
400
  return typeof def._sql === "string" && def._sql.startsWith("now()");
438
401
  };
439
402
  const combineCodeElements = (input) => {
440
- if (typeof input === "string")
441
- return input;
403
+ if (typeof input === "string") return input;
442
404
  const output = [];
443
405
  let i = -1;
444
406
  for (const item of input) {
@@ -458,12 +420,10 @@ const columnsShapeToCode = (ctx, shape) => {
458
420
  const hasTimestamps = "createdAt" in shape && isDefaultTimeStamp(shape.createdAt) && "updatedAt" in shape && isDefaultTimeStamp(shape.updatedAt);
459
421
  const code = [];
460
422
  for (const key in shape) {
461
- if (hasTimestamps && (key === "createdAt" || key === "updatedAt"))
462
- continue;
423
+ if (hasTimestamps && (key === "createdAt" || key === "updatedAt")) continue;
463
424
  const column = shape[key];
464
425
  const name = column.data.name;
465
- if (name === key)
466
- column.data.name = void 0;
426
+ if (name === key) column.data.name = void 0;
467
427
  code.push(
468
428
  ...combineCodeElements([
469
429
  `${quoteObjectKey(key)}: `,
@@ -471,8 +431,7 @@ const columnsShapeToCode = (ctx, shape) => {
471
431
  ","
472
432
  ])
473
433
  );
474
- if (name === key)
475
- column.data.name = name;
434
+ if (name === key) column.data.name = name;
476
435
  }
477
436
  if (hasTimestamps) {
478
437
  code.push(`...${ctx.t}.timestamps(),`);
@@ -509,11 +468,9 @@ const primaryKeyInnerToCode = (primaryKey, t) => {
509
468
  };
510
469
  const indexToCode = (index, t, prefix) => {
511
470
  const code = indexInnerToCode(index, t);
512
- if (prefix)
513
- code[0] = prefix + code[0];
471
+ if (prefix) code[0] = prefix + code[0];
514
472
  const last = code[code.length - 1];
515
- if (typeof last === "string" && !last.endsWith(","))
516
- addCode(code, ",");
473
+ if (typeof last === "string" && !last.endsWith(",")) addCode(code, ",");
517
474
  return code;
518
475
  };
519
476
  const indexInnerToCode = (index, t) => {
@@ -590,11 +547,9 @@ const indexInnerToCode = (index, t) => {
590
547
  }
591
548
  const options = [];
592
549
  for (const key of indexOptionsKeys) {
593
- if (!key)
594
- continue;
550
+ if (!key) continue;
595
551
  const value = index.options[key];
596
- if (value === null || value === void 0)
597
- continue;
552
+ if (value === null || value === void 0) continue;
598
553
  options.push(
599
554
  `${key}: ${Array.isArray(value) ? singleQuoteArray(value) : typeof value === "string" ? singleQuote(value) : value},`
600
555
  );
@@ -615,8 +570,7 @@ const indexInnerToCode = (index, t) => {
615
570
  };
616
571
  const constraintToCode = (item, t, m, prefix) => {
617
572
  const code = constraintInnerToCode(item, t, m);
618
- if (prefix)
619
- code[0] = prefix + code[0];
573
+ if (prefix) code[0] = prefix + code[0];
620
574
  const last = code[code.length - 1];
621
575
  if (typeof last === "string" && !last.endsWith(","))
622
576
  code[code.length - 1] += ",";
@@ -639,7 +593,7 @@ const referencesArgsToCode = ({
639
593
  fnOrTable,
640
594
  foreignColumns,
641
595
  options
642
- }, name = (options == null ? void 0 : options.name) || false, m) => {
596
+ }, name = options?.name || false, m) => {
643
597
  const args = [];
644
598
  args.push(`${singleQuoteArray(columns)},`);
645
599
  if (m && typeof fnOrTable !== "string") {
@@ -652,14 +606,11 @@ const referencesArgsToCode = ({
652
606
  args.push(`${singleQuoteArray(foreignColumns)},`);
653
607
  if (objectHasValues(options) || name) {
654
608
  const lines = [];
655
- if (name)
656
- lines.push(`name: ${singleQuote(name)},`);
609
+ if (name) lines.push(`name: ${singleQuote(name)},`);
657
610
  for (const key in options) {
658
- if (key === "name")
659
- continue;
611
+ if (key === "name") continue;
660
612
  const value = options[key];
661
- if (value)
662
- lines.push(`${key}: ${singleQuote(value)},`);
613
+ if (value) lines.push(`${key}: ${singleQuote(value)},`);
663
614
  }
664
615
  args.push("{", lines, "},");
665
616
  }
@@ -693,10 +644,8 @@ const foreignKeyArgumentToCode = ({
693
644
  const hasOptions = options.name || options.match || options.onUpdate || options.onDelete;
694
645
  if (hasOptions) {
695
646
  const arr = [];
696
- if (options.name)
697
- arr.push(`name: ${singleQuote(options.name)},`);
698
- if (options.match)
699
- arr.push(`match: ${singleQuote(options.match)},`);
647
+ if (options.name) arr.push(`name: ${singleQuote(options.name)},`);
648
+ if (options.match) arr.push(`match: ${singleQuote(options.match)},`);
700
649
  if (options.onUpdate)
701
650
  arr.push(`onUpdate: ${singleQuote(options.onUpdate)},`);
702
651
  if (options.onDelete)
@@ -712,28 +661,20 @@ const columnIndexesToCode = (indexes) => {
712
661
  for (const { options, name } of indexes) {
713
662
  addCode(code, `.${options.unique ? "unique" : "index"}(`);
714
663
  const arr = [];
715
- if (options.collate)
716
- arr.push(`collate: ${singleQuote(options.collate)},`);
717
- if (options.opclass)
718
- arr.push(`opclass: ${singleQuote(options.opclass)},`);
719
- if (options.order)
720
- arr.push(`order: ${singleQuote(options.order)},`);
721
- if (name)
722
- arr.push(`name: ${singleQuote(name)},`);
723
- if (options.using)
724
- arr.push(`using: ${singleQuote(options.using)},`);
664
+ if (options.collate) arr.push(`collate: ${singleQuote(options.collate)},`);
665
+ if (options.opclass) arr.push(`opclass: ${singleQuote(options.opclass)},`);
666
+ if (options.order) arr.push(`order: ${singleQuote(options.order)},`);
667
+ if (name) arr.push(`name: ${singleQuote(name)},`);
668
+ if (options.using) arr.push(`using: ${singleQuote(options.using)},`);
725
669
  if (options.include)
726
670
  arr.push(
727
671
  `include: ${typeof options.include === "string" ? singleQuote(options.include) : `[${options.include.map(singleQuote).join(", ")}]`},`
728
672
  );
729
- if (options.nullsNotDistinct)
730
- arr.push(`nullsNotDistinct: true,`);
731
- if (options.with)
732
- arr.push(`with: ${singleQuote(options.with)},`);
673
+ if (options.nullsNotDistinct) arr.push(`nullsNotDistinct: true,`);
674
+ if (options.with) arr.push(`with: ${singleQuote(options.with)},`);
733
675
  if (options.tablespace)
734
676
  arr.push(`tablespace: ${singleQuote(options.tablespace)},`);
735
- if (options.where)
736
- arr.push(`where: ${singleQuote(options.where)},`);
677
+ if (options.where) arr.push(`where: ${singleQuote(options.where)},`);
737
678
  if (arr.length) {
738
679
  addCode(code, "{");
739
680
  addCode(code, arr);
@@ -754,20 +695,16 @@ const identityToCode = (identity, dataType) => {
754
695
  code.push(`${dataType}().identity(`);
755
696
  }
756
697
  const props = [];
757
- if (identity.always)
758
- props.push(`always: true,`);
698
+ if (identity.always) props.push(`always: true,`);
759
699
  if (identity.increment && identity.increment !== 1)
760
700
  props.push(`increment: ${identity.increment},`);
761
701
  if (identity.start && identity.start !== 1)
762
702
  props.push(`start: ${identity.start},`);
763
- if (identity.min)
764
- props.push(`min: ${identity.min},`);
765
- if (identity.max)
766
- props.push(`max: ${identity.max},`);
703
+ if (identity.min) props.push(`min: ${identity.min},`);
704
+ if (identity.max) props.push(`max: ${identity.max},`);
767
705
  if (identity.cache && identity.cache !== 1)
768
706
  props.push(`cache: ${identity.cache},`);
769
- if (identity.cycle)
770
- props.push(`cycle: true,`);
707
+ if (identity.cycle) props.push(`cycle: true,`);
771
708
  if (props.length) {
772
709
  addCode(code, "{");
773
710
  code.push(props, "}");
@@ -776,12 +713,11 @@ const identityToCode = (identity, dataType) => {
776
713
  return code;
777
714
  };
778
715
  const columnCode = (type, ctx, key, code) => {
779
- var _a;
780
716
  const { data } = type;
781
717
  code = toArray(code);
782
718
  let prepend = `${ctx.t}.`;
783
719
  const keyName = ctx.snakeCase ? toSnakeCase(key) : key;
784
- const name = (_a = data.name) != null ? _a : keyName;
720
+ const name = data.name ?? keyName;
785
721
  if (name !== keyName) {
786
722
  prepend += `name(${singleQuote(name)}).`;
787
723
  }
@@ -804,18 +740,15 @@ const columnCode = (type, ctx, key, code) => {
804
740
  addCode(code, part);
805
741
  }
806
742
  }
807
- if (data.explicitSelect)
808
- addCode(code, ".select(false)");
809
- if (data.isNullable)
810
- addCode(code, ".nullable()");
743
+ if (data.explicitSelect) addCode(code, ".select(false)");
744
+ if (data.isNullable) addCode(code, ".nullable()");
811
745
  if (data.encode && data.encode !== data.defaultEncode)
812
746
  addCode(code, `.encode(${data.encode.toString()})`);
813
747
  if (data.parse && data.parse !== data.defaultParse)
814
748
  addCode(code, `.parse(${data.parse.toString()})`);
815
749
  if (type.data.parseNull)
816
750
  addCode(code, `.parseNull(${type.data.parseNull.toString()})`);
817
- if (data.as)
818
- addCode(code, `.as(${data.as.toCode(ctx, key)})`);
751
+ if (data.as) addCode(code, `.as(${data.as.toCode(ctx, key)})`);
819
752
  if (data.default !== void 0 && data.default !== data.defaultDefault && (!ctx.migration || typeof data.default !== "function")) {
820
753
  addCode(
821
754
  code,
@@ -827,8 +760,7 @@ const columnCode = (type, ctx, key, code) => {
827
760
  addCode(code, part);
828
761
  }
829
762
  }
830
- if (data.comment)
831
- addCode(code, `.comment(${singleQuote(data.comment)})`);
763
+ if (data.comment) addCode(code, `.comment(${singleQuote(data.comment)})`);
832
764
  if (data.check) {
833
765
  addCode(code, columnCheckToCode(ctx, data.check, name));
834
766
  }
@@ -846,42 +778,20 @@ const columnCode = (type, ctx, key, code) => {
846
778
  }
847
779
  if (data.compression)
848
780
  addCode(code, `.compression(${singleQuote(data.compression)})`);
849
- if (data.collate)
850
- addCode(code, `.collate(${singleQuote(data.collate)})`);
781
+ if (data.collate) addCode(code, `.collate(${singleQuote(data.collate)})`);
851
782
  if (data.modifyQuery)
852
783
  addCode(code, `.modifyQuery(${data.modifyQuery.toString()})`);
853
784
  return code.length === 1 && typeof code[0] === "string" ? code[0] : code;
854
785
  };
855
786
 
856
787
  const getSqlText = (sql) => {
857
- if ("text" in sql)
858
- return sql.text;
788
+ if ("text" in sql) return sql.text;
859
789
  throw new Error(`Batch SQL is not supported in this query`);
860
790
  };
861
791
 
862
- var __defProp$n = Object.defineProperty;
863
- var __defProps$d = Object.defineProperties;
864
- var __getOwnPropDescs$d = Object.getOwnPropertyDescriptors;
865
- var __getOwnPropSymbols$o = Object.getOwnPropertySymbols;
866
- var __hasOwnProp$o = Object.prototype.hasOwnProperty;
867
- var __propIsEnum$o = Object.prototype.propertyIsEnumerable;
868
- var __defNormalProp$n = (obj, key, value) => key in obj ? __defProp$n(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
869
- var __spreadValues$n = (a, b) => {
870
- for (var prop in b || (b = {}))
871
- if (__hasOwnProp$o.call(b, prop))
872
- __defNormalProp$n(a, prop, b[prop]);
873
- if (__getOwnPropSymbols$o)
874
- for (var prop of __getOwnPropSymbols$o(b)) {
875
- if (__propIsEnum$o.call(b, prop))
876
- __defNormalProp$n(a, prop, b[prop]);
877
- }
878
- return a;
879
- };
880
- var __spreadProps$d = (a, b) => __defProps$d(a, __getOwnPropDescs$d(b));
881
792
  const addColumnParserToQuery = (q, key, column) => {
882
- var _a;
883
793
  if (column._parse) {
884
- ((_a = q.parsers) != null ? _a : q.parsers = {})[key] = column._parse;
794
+ (q.parsers ?? (q.parsers = {}))[key] = column._parse;
885
795
  }
886
796
  };
887
797
  const setColumnDefaultParse = (column, parse) => {
@@ -891,7 +801,7 @@ const setColumnDefaultParse = (column, parse) => {
891
801
  const setColumnParse = (column, fn, outputSchema) => {
892
802
  const c = Object.create(column);
893
803
  c.outputSchema = outputSchema;
894
- c.data = __spreadProps$d(__spreadValues$n({}, column.data), { parse: fn });
804
+ c.data = { ...column.data, parse: fn };
895
805
  const { parseNull } = column.data;
896
806
  c._parse = parseNull ? (input) => input === null ? parseNull() : fn(input) : (input) => input === null ? null : fn(input);
897
807
  return c;
@@ -899,7 +809,7 @@ const setColumnParse = (column, fn, outputSchema) => {
899
809
  const setColumnParseNull = (column, fn, nullSchema) => {
900
810
  const c = Object.create(column);
901
811
  c.nullSchema = nullSchema;
902
- c.data = __spreadProps$d(__spreadValues$n({}, column.data), { parseNull: fn });
812
+ c.data = { ...column.data, parseNull: fn };
903
813
  const { parse } = column.data;
904
814
  c._parse = parse ? (input) => input === null ? fn() : parse(input) : (input) => input === null ? fn() : input;
905
815
  return c;
@@ -907,29 +817,10 @@ const setColumnParseNull = (column, fn, nullSchema) => {
907
817
  const setColumnEncode = (column, fn, inputSchema) => {
908
818
  const c = Object.create(column);
909
819
  c.inputSchema = inputSchema;
910
- c.data = __spreadProps$d(__spreadValues$n({}, column.data), { encode: fn });
820
+ c.data = { ...column.data, encode: fn };
911
821
  return c;
912
822
  };
913
823
 
914
- var __defProp$m = Object.defineProperty;
915
- var __defProps$c = Object.defineProperties;
916
- var __getOwnPropDescs$c = Object.getOwnPropertyDescriptors;
917
- var __getOwnPropSymbols$n = Object.getOwnPropertySymbols;
918
- var __hasOwnProp$n = Object.prototype.hasOwnProperty;
919
- var __propIsEnum$n = Object.prototype.propertyIsEnumerable;
920
- var __defNormalProp$m = (obj, key, value) => key in obj ? __defProp$m(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
921
- var __spreadValues$m = (a, b) => {
922
- for (var prop in b || (b = {}))
923
- if (__hasOwnProp$n.call(b, prop))
924
- __defNormalProp$m(a, prop, b[prop]);
925
- if (__getOwnPropSymbols$n)
926
- for (var prop of __getOwnPropSymbols$n(b)) {
927
- if (__propIsEnum$n.call(b, prop))
928
- __defNormalProp$m(a, prop, b[prop]);
929
- }
930
- return a;
931
- };
932
- var __spreadProps$c = (a, b) => __defProps$c(a, __getOwnPropDescs$c(b));
933
824
  function setQueryOperators(query, operators) {
934
825
  const q = query.q;
935
826
  if (q.operators !== operators) {
@@ -942,9 +833,9 @@ const make = (_op) => {
942
833
  return Object.assign(
943
834
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
944
835
  function(value) {
945
- var _a, _b, _c;
946
- ((_b = (_a = this.q).chain) != null ? _b : _a.chain = []).push(_op, value);
947
- if ((_c = this.q.parsers) == null ? void 0 : _c[getValueKey]) {
836
+ var _a;
837
+ ((_a = this.q).chain ?? (_a.chain = [])).push(_op, value);
838
+ if (this.q.parsers?.[getValueKey]) {
948
839
  this.q.parsers[getValueKey] = void 0;
949
840
  }
950
841
  return setQueryOperators(this, boolean);
@@ -960,9 +851,9 @@ const makeVarArg = (_op) => {
960
851
  return Object.assign(
961
852
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
962
853
  function(...args) {
963
- var _a, _b, _c;
964
- ((_b = (_a = this.q).chain) != null ? _b : _a.chain = []).push(_op, args);
965
- if ((_c = this.q.parsers) == null ? void 0 : _c[getValueKey]) {
854
+ var _a;
855
+ ((_a = this.q).chain ?? (_a.chain = [])).push(_op, args);
856
+ if (this.q.parsers?.[getValueKey]) {
966
857
  this.q.parsers[getValueKey] = void 0;
967
858
  }
968
859
  return setQueryOperators(this, boolean);
@@ -990,7 +881,7 @@ const quoteValue = (arg, ctx, quotedAs, jsonArray) => {
990
881
  };
991
882
  const quoteLikeValue = (arg, ctx, quotedAs, jsonArray) => {
992
883
  if (arg && typeof arg === "object") {
993
- if (!jsonArray && Array.isArray(arg)) {
884
+ if (Array.isArray(arg)) {
994
885
  return `(${arg.map((value) => addValue(ctx.values, value)).join(", ")})`;
995
886
  }
996
887
  if (isExpression(arg)) {
@@ -1018,15 +909,17 @@ const base = {
1018
909
  (key, value, ctx, quotedAs) => `NOT ${key} IN ${quoteValue(value, ctx, quotedAs)}`
1019
910
  )
1020
911
  };
1021
- const boolean = __spreadProps$c(__spreadValues$m({}, base), {
912
+ const boolean = {
913
+ ...base,
1022
914
  and: make(
1023
915
  (key, value, ctx, quotedAs) => `${key} AND ${value.q.expr.toSQL(ctx, quotedAs)}`
1024
916
  ),
1025
917
  or: make(
1026
918
  (key, value, ctx, quotedAs) => `(${key}) OR (${value.q.expr.toSQL(ctx, quotedAs)})`
1027
919
  )
1028
- });
1029
- const numeric = __spreadProps$c(__spreadValues$m({}, base), {
920
+ };
921
+ const numeric = {
922
+ ...base,
1030
923
  lt: make(
1031
924
  (key, value, ctx, quotedAs) => `${key} < ${quoteValue(value, ctx, quotedAs)}`
1032
925
  ),
@@ -1046,8 +939,9 @@ const numeric = __spreadProps$c(__spreadValues$m({}, base), {
1046
939
  quotedAs
1047
940
  )}`
1048
941
  )
1049
- });
1050
- const text = __spreadProps$c(__spreadValues$m({}, base), {
942
+ };
943
+ const text = {
944
+ ...base,
1051
945
  contains: make(
1052
946
  (key, value, ctx, quotedAs) => `${key} ILIKE '%' || ${quoteLikeValue(value, ctx, quotedAs)} || '%'`
1053
947
  ),
@@ -1066,20 +960,20 @@ const text = __spreadProps$c(__spreadValues$m({}, base), {
1066
960
  endsWithSensitive: make(
1067
961
  (key, value, ctx, quotedAs) => `${key} LIKE '%' || ${quoteLikeValue(value, ctx, quotedAs)}`
1068
962
  )
1069
- });
963
+ };
1070
964
  const encodeJsonPath = (ctx, path) => addValue(ctx.values, `{${Array.isArray(path) ? path.join(", ") : path}}`);
1071
- const jsonPathQueryOp = (key, [path, options], ctx) => `jsonb_path_query_first(${key}, ${addValue(ctx.values, path)}${(options == null ? void 0 : options.vars) ? `, ${addValue(ctx.values, JSON.stringify(options.vars))}${options.silent ? ", true" : ""}` : (options == null ? void 0 : options.silent) ? ", NULL, true" : ""})`;
1072
- const json = __spreadProps$c(__spreadValues$m({}, base), {
965
+ const jsonPathQueryOp = (key, [path, options], ctx) => `jsonb_path_query_first(${key}, ${addValue(ctx.values, path)}${options?.vars ? `, ${addValue(ctx.values, JSON.stringify(options.vars))}${options.silent ? ", true" : ""}` : options?.silent ? ", NULL, true" : ""})`;
966
+ const json = {
967
+ ...base,
1073
968
  jsonPathQueryFirst: Object.assign(
1074
969
  function(path, options) {
1075
- var _a, _b;
1076
970
  const { q, columnTypes } = this;
1077
- const chain = (_a = q.chain) != null ? _a : q.chain = [];
971
+ const chain = q.chain ?? (q.chain = []);
1078
972
  chain.push(jsonPathQueryOp, [path, options]);
1079
- if ((_b = q.parsers) == null ? void 0 : _b[getValueKey]) {
973
+ if (q.parsers?.[getValueKey]) {
1080
974
  q.parsers[getValueKey] = void 0;
1081
975
  }
1082
- if (options == null ? void 0 : options.type) {
976
+ if (options?.type) {
1083
977
  const type = options.type(columnTypes);
1084
978
  addColumnParserToQuery(q, getValueKey, type);
1085
979
  chain.push = (...args) => {
@@ -1115,12 +1009,12 @@ const json = __spreadProps$c(__spreadValues$m({}, base), {
1115
1009
  (key, [path, value, options], ctx) => `jsonb_insert(${key}, ${encodeJsonPath(ctx, path)}, ${addValue(
1116
1010
  ctx.values,
1117
1011
  JSON.stringify(value)
1118
- )}${(options == null ? void 0 : options.after) ? ", true" : ""})`
1012
+ )}${options?.after ? ", true" : ""})`
1119
1013
  ),
1120
1014
  jsonRemove: makeVarArg(
1121
1015
  (key, [path], ctx) => `(${key} #- ${encodeJsonPath(ctx, path)})`
1122
1016
  )
1123
- });
1017
+ };
1124
1018
  const Operators = {
1125
1019
  any: base,
1126
1020
  boolean,
@@ -1132,22 +1026,6 @@ const Operators = {
1132
1026
  array: base
1133
1027
  };
1134
1028
 
1135
- var __defProp$l = Object.defineProperty;
1136
- var __getOwnPropSymbols$m = Object.getOwnPropertySymbols;
1137
- var __hasOwnProp$m = Object.prototype.hasOwnProperty;
1138
- var __propIsEnum$m = Object.prototype.propertyIsEnumerable;
1139
- var __defNormalProp$l = (obj, key, value) => key in obj ? __defProp$l(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1140
- var __spreadValues$l = (a, b) => {
1141
- for (var prop in b || (b = {}))
1142
- if (__hasOwnProp$m.call(b, prop))
1143
- __defNormalProp$l(a, prop, b[prop]);
1144
- if (__getOwnPropSymbols$m)
1145
- for (var prop of __getOwnPropSymbols$m(b)) {
1146
- if (__propIsEnum$m.call(b, prop))
1147
- __defNormalProp$l(a, prop, b[prop]);
1148
- }
1149
- return a;
1150
- };
1151
1029
  class TextBaseColumn extends ColumnType {
1152
1030
  constructor(schema, schemaType = schema.stringSchema()) {
1153
1031
  super(schema, schemaType);
@@ -1180,7 +1058,7 @@ class VarCharColumn extends LimitedTextBaseColumn {
1180
1058
  this,
1181
1059
  ctx,
1182
1060
  key,
1183
- `varchar(${maxChars != null ? maxChars : ""})${stringDataToCode(this.data, ctx.migration)}`
1061
+ `varchar(${maxChars ?? ""})${stringDataToCode(this.data, ctx.migration)}`
1184
1062
  );
1185
1063
  }
1186
1064
  }
@@ -1190,18 +1068,17 @@ class StringColumn extends VarCharColumn {
1190
1068
  }
1191
1069
  toCode(ctx, key) {
1192
1070
  let max = this.data.maxChars;
1193
- if (max === 255)
1194
- max = void 0;
1071
+ if (max === 255) max = void 0;
1195
1072
  return columnCode(
1196
1073
  this,
1197
1074
  ctx,
1198
1075
  key,
1199
- `string(${max != null ? max : ""})${stringDataToCode(this.data, ctx.migration)}`
1076
+ `string(${max ?? ""})${stringDataToCode(this.data, ctx.migration)}`
1200
1077
  );
1201
1078
  }
1202
1079
  }
1203
1080
  const textColumnToCode = (column, ctx, key) => {
1204
- const data = __spreadValues$l({}, column.data);
1081
+ const data = { ...column.data };
1205
1082
  let args = "";
1206
1083
  const hasMax = data.maxArg !== void 0 && data.max === data.maxArg;
1207
1084
  if (data.minArg !== void 0 && data.min === data.minArg || hasMax) {
@@ -1399,7 +1276,7 @@ class BitVaryingColumn extends ColumnType {
1399
1276
  }
1400
1277
  toCode(ctx, key) {
1401
1278
  const { length } = this.data;
1402
- return columnCode(this, ctx, key, `bitVarying(${length != null ? length : ""})`);
1279
+ return columnCode(this, ctx, key, `bitVarying(${length ?? ""})`);
1403
1280
  }
1404
1281
  toSQL() {
1405
1282
  return joinTruthy(
@@ -1496,8 +1373,7 @@ class UUIDColumn extends ColumnType {
1496
1373
  */
1497
1374
  primaryKey(name) {
1498
1375
  const column = super.primaryKey(name);
1499
- if (!column.data.default)
1500
- column.data.default = uuidDefault;
1376
+ if (!column.data.default) column.data.default = uuidDefault;
1501
1377
  return column;
1502
1378
  }
1503
1379
  toCode(ctx, key) {
@@ -1720,8 +1596,7 @@ const applySqlComputed = (ctx, q, computed, as, quotedAs) => {
1720
1596
  return computed.toSQL(ctx, quotedAs);
1721
1597
  };
1722
1598
  function simpleColumnToSQL(ctx, q, key, column, quotedAs) {
1723
- if (!column)
1724
- return `"${key}"`;
1599
+ if (!column) return `"${key}"`;
1725
1600
  const { data } = column;
1726
1601
  return data.computed ? applySqlComputed(ctx, q, data.computed, key, quotedAs) : `${quotedAs ? `${quotedAs}.` : ""}"${data.name || key}"`;
1727
1602
  }
@@ -1730,7 +1605,6 @@ function simpleExistingColumnToSQL(ctx, q, key, column, quotedAs) {
1730
1605
  return data.computed ? applySqlComputed(ctx, q, data.computed, key, quotedAs) : `${quotedAs ? `${quotedAs}.` : ""}"${data.name || key}"`;
1731
1606
  }
1732
1607
  const columnToSql = (ctx, data, shape, column, quotedAs, select) => {
1733
- var _a;
1734
1608
  const index = column.indexOf(".");
1735
1609
  if (index !== -1) {
1736
1610
  return columnWithDotToSql(
@@ -1743,18 +1617,17 @@ const columnToSql = (ctx, data, shape, column, quotedAs, select) => {
1743
1617
  select
1744
1618
  );
1745
1619
  }
1746
- if (!select && ((_a = data.joinedShapes) == null ? void 0 : _a[column])) {
1620
+ if (!select && data.joinedShapes?.[column]) {
1747
1621
  return `"${column}".r`;
1748
1622
  }
1749
1623
  return simpleColumnToSQL(ctx, data, column, shape[column], quotedAs);
1750
1624
  };
1751
1625
  const maybeSelectedColumnToSql = (ctx, data, column, quotedAs) => {
1752
- var _a;
1753
1626
  const index = column.indexOf(".");
1754
1627
  if (index !== -1) {
1755
1628
  return columnWithDotToSql(ctx, data, data.shape, column, index, quotedAs);
1756
1629
  } else {
1757
- if ((_a = data.joinedShapes) == null ? void 0 : _a[column]) {
1630
+ if (data.joinedShapes?.[column]) {
1758
1631
  return `"${column}".r`;
1759
1632
  }
1760
1633
  if (data.select) {
@@ -1770,15 +1643,14 @@ const maybeSelectedColumnToSql = (ctx, data, column, quotedAs) => {
1770
1643
  }
1771
1644
  };
1772
1645
  const columnWithDotToSql = (ctx, data, shape, column, index, quotedAs, select) => {
1773
- var _a, _b, _c, _d;
1774
1646
  const table = column.slice(0, index);
1775
1647
  const key = column.slice(index + 1);
1776
1648
  if (key === "*") {
1777
- return ((_a = data.joinedShapes) == null ? void 0 : _a[table]) ? select ? `row_to_json("${table}".*)` : `"${table}".*` : column;
1649
+ return data.joinedShapes?.[table] ? select ? `row_to_json("${table}".*)` : `"${table}".*` : column;
1778
1650
  }
1779
- const tableName = ((_b = data.aliases) == null ? void 0 : _b[table]) || table;
1651
+ const tableName = data.aliases?.[table] || table;
1780
1652
  const quoted = `"${table}"`;
1781
- const col = quoted === quotedAs ? shape[key] : (_d = (_c = data.joinedShapes) == null ? void 0 : _c[tableName]) == null ? void 0 : _d[key];
1653
+ const col = quoted === quotedAs ? shape[key] : data.joinedShapes?.[tableName]?.[key];
1782
1654
  if (col) {
1783
1655
  if (col.data.name) {
1784
1656
  return `"${tableName}"."${col.data.name}"`;
@@ -1799,16 +1671,13 @@ const columnToSqlWithAs = (ctx, data, column, as, quotedAs, select) => {
1799
1671
  column.slice(0, index),
1800
1672
  column.slice(index + 1),
1801
1673
  as,
1802
- quotedAs,
1803
- select
1804
- ) : ownColumnToSqlWithAs(ctx, data, column, as, quotedAs, select);
1674
+ quotedAs) : ownColumnToSqlWithAs(ctx, data, column, as, quotedAs, select);
1805
1675
  };
1806
1676
  const tableColumnToSqlWithAs = (ctx, data, column, table, key, as, quotedAs, select) => {
1807
- var _a, _b, _c;
1808
1677
  if (key === "*") {
1809
- const shape = (_a = data.joinedShapes) == null ? void 0 : _a[table];
1678
+ const shape = data.joinedShapes?.[table];
1810
1679
  if (shape) {
1811
- if (select) {
1680
+ {
1812
1681
  let isSimple = true;
1813
1682
  const list = [];
1814
1683
  for (const key2 in shape) {
@@ -1823,13 +1692,12 @@ const tableColumnToSqlWithAs = (ctx, data, column, table, key, as, quotedAs, sel
1823
1692
  }
1824
1693
  return (isSimple ? `row_to_json("${table}".*)` : "json_build_object(" + list.join(", ") + ")") + ` "${as}"`;
1825
1694
  }
1826
- return `"${table}".r "${as}"`;
1827
1695
  }
1828
1696
  return column;
1829
1697
  }
1830
- const tableName = ((_b = data.aliases) == null ? void 0 : _b[table]) || table;
1698
+ const tableName = data.aliases?.[table] || table;
1831
1699
  const quoted = `"${table}"`;
1832
- const col = quoted === quotedAs ? data.shape[key] : (_c = data.joinedShapes) == null ? void 0 : _c[tableName][key];
1700
+ const col = quoted === quotedAs ? data.shape[key] : data.joinedShapes?.[tableName][key];
1833
1701
  if (col) {
1834
1702
  if (col.data.name && col.data.name !== key) {
1835
1703
  return `"${tableName}"."${col.data.name}" "${as}"`;
@@ -1847,8 +1715,7 @@ const tableColumnToSqlWithAs = (ctx, data, column, table, key, as, quotedAs, sel
1847
1715
  return `"${tableName}"."${key}"${key === as ? "" : ` "${as}"`}`;
1848
1716
  };
1849
1717
  const ownColumnToSqlWithAs = (ctx, data, column, as, quotedAs, select) => {
1850
- var _a;
1851
- if (!select && ((_a = data.joinedShapes) == null ? void 0 : _a[column])) {
1718
+ if (!select && data.joinedShapes?.[column]) {
1852
1719
  return select ? `row_to_json("${column}".*) "${as}"` : `"${column}".r "${as}"`;
1853
1720
  }
1854
1721
  const col = data.shape[column];
@@ -1878,31 +1745,20 @@ const quoteSchemaAndTable = (schema, table) => {
1878
1745
  const pushDistinctSql = (ctx, table, distinct, quotedAs) => {
1879
1746
  ctx.sql.push("DISTINCT");
1880
1747
  if (distinct.length) {
1881
- const columns = distinct == null ? void 0 : distinct.map(
1748
+ const columns = distinct?.map(
1882
1749
  (item) => rawOrColumnToSql(ctx, table.q, item, quotedAs)
1883
1750
  );
1884
- ctx.sql.push(`ON (${(columns == null ? void 0 : columns.join(", ")) || ""})`);
1751
+ ctx.sql.push(`ON (${columns?.join(", ") || ""})`);
1885
1752
  }
1886
1753
  };
1887
1754
 
1888
- var __accessCheck = (obj, member, msg) => {
1889
- if (!member.has(obj))
1890
- throw TypeError("Cannot " + msg);
1891
- };
1892
- var __privateGet = (obj, member, getter) => {
1893
- __accessCheck(obj, member, "read from private field");
1894
- return getter ? getter.call(obj) : member.get(obj);
1895
- };
1896
- var __privateAdd = (obj, member, value) => {
1897
- if (member.has(obj))
1898
- throw TypeError("Cannot add the same private member more than once");
1899
- member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
1900
- };
1901
- var __privateSet = (obj, member, value, setter) => {
1902
- __accessCheck(obj, member, "write to private field");
1903
- setter ? setter.call(obj, value) : member.set(obj, value);
1904
- return value;
1755
+ var __typeError = (msg) => {
1756
+ throw TypeError(msg);
1905
1757
  };
1758
+ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
1759
+ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
1760
+ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
1761
+ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), member.set(obj, value), value);
1906
1762
  var _query, _query2;
1907
1763
  class OrchidOrmError extends Error {
1908
1764
  }
@@ -1910,7 +1766,7 @@ class NotFoundError extends OrchidOrmError {
1910
1766
  constructor(query, message = "Record is not found") {
1911
1767
  super(message);
1912
1768
  // `#query` is private to prevent it from serializing to not cause problems to test runner reports
1913
- __privateAdd(this, _query, void 0);
1769
+ __privateAdd(this, _query);
1914
1770
  __privateSet(this, _query, query);
1915
1771
  }
1916
1772
  get query() {
@@ -1922,7 +1778,7 @@ class OrchidOrmInternalError extends Error {
1922
1778
  constructor(query, message) {
1923
1779
  super(message);
1924
1780
  // `#query` is private to prevent it from serializing to not cause problems to test runner reports
1925
- __privateAdd(this, _query2, void 0);
1781
+ __privateAdd(this, _query2);
1926
1782
  __privateSet(this, _query2, query);
1927
1783
  }
1928
1784
  get query() {
@@ -1935,17 +1791,14 @@ class QueryError extends OrchidOrmInternalError {
1935
1791
  return this.code === "23505";
1936
1792
  }
1937
1793
  get columns() {
1938
- var _a;
1939
- if (this.columnsCache)
1940
- return this.columnsCache;
1794
+ if (this.columnsCache) return this.columnsCache;
1941
1795
  const columns = {};
1942
1796
  if (this.detail) {
1943
- const list = (_a = this.detail.match(/\((.*)\)=/)) == null ? void 0 : _a[1];
1797
+ const list = this.detail.match(/\((.*)\)=/)?.[1];
1944
1798
  if (list) {
1945
1799
  list.split(", ").forEach((item) => {
1946
- var _a2;
1947
1800
  const column = item.startsWith('"') ? item.slice(1, -1) : item;
1948
- const key = (_a2 = this.query.columnNameToKey(column)) != null ? _a2 : column;
1801
+ const key = this.query.columnNameToKey(column) ?? column;
1949
1802
  columns[key] = true;
1950
1803
  });
1951
1804
  }
@@ -1985,18 +1838,16 @@ const whereToSql = (ctx, table, query, quotedAs, parens) => {
1985
1838
  data.and = scope.and;
1986
1839
  data.or = scope.or;
1987
1840
  const scopeSql = andOrToSql(ctx, table, data, quotedAs, true);
1988
- if (scopeSql)
1989
- sql = sql ? sql + " AND " + scopeSql : scopeSql;
1841
+ if (scopeSql) sql = sql ? sql + " AND " + scopeSql : scopeSql;
1990
1842
  }
1991
1843
  return sql;
1992
1844
  }
1993
1845
  return andOrToSql(ctx, table, query, quotedAs, parens);
1994
1846
  };
1995
1847
  const andOrToSql = (ctx, table, query, quotedAs, parens) => {
1996
- var _a;
1997
1848
  let sql;
1998
1849
  if (query.or) {
1999
- const ors = ((_a = query.and) == null ? void 0 : _a.length) ? [query.and, ...query.or] : query.or;
1850
+ const ors = query.and?.length ? [query.and, ...query.or] : query.or;
2000
1851
  sql = ors.map((and) => processAnds(and, ctx, table, query, quotedAs)).join(" OR ");
2001
1852
  } else if (query.and) {
2002
1853
  sql = processAnds(query.and, ctx, table, query, quotedAs);
@@ -2014,7 +1865,6 @@ const processAnds = (and, ctx, table, query, quotedAs, parens) => {
2014
1865
  return parens && ands.length > 1 ? `(${sql})` : sql;
2015
1866
  };
2016
1867
  const processWhere = (ands, ctx, table, query, data, quotedAs) => {
2017
- var _a, _b, _c, _d;
2018
1868
  if ("prototype" in data || "baseQuery" in data) {
2019
1869
  const query2 = data;
2020
1870
  if (query2.q.expr) {
@@ -2043,8 +1893,7 @@ const processWhere = (ands, ctx, table, query, data, quotedAs) => {
2043
1893
  }
2044
1894
  for (const key in data) {
2045
1895
  const value = data[key];
2046
- if (value === void 0)
2047
- continue;
1896
+ if (value === void 0) continue;
2048
1897
  if (key === "AND") {
2049
1898
  const arr = toArray(value);
2050
1899
  ands.push(processAnds(arr, ctx, table, query, quotedAs));
@@ -2114,8 +1963,7 @@ const processWhere = (ands, ctx, table, query, data, quotedAs) => {
2114
1963
  );
2115
1964
  const sql = `EXISTS (SELECT 1 FROM ${target}${on ? ` WHERE ${on}` : ""})`;
2116
1965
  if (joinSet) {
2117
- if (joinSet.has(sql))
2118
- continue;
1966
+ if (joinSet.has(sql)) continue;
2119
1967
  joinSet.add(sql);
2120
1968
  }
2121
1969
  ands.push(sql);
@@ -2151,10 +1999,10 @@ const processWhere = (ands, ctx, table, query, data, quotedAs) => {
2151
1999
  const table2 = key.slice(0, index);
2152
2000
  const quoted = `"${table2}"`;
2153
2001
  const name = key.slice(index + 1);
2154
- column = quotedAs === quoted ? query.shape[name] : (_b = (_a = query.joinedShapes) == null ? void 0 : _a[table2]) == null ? void 0 : _b[name];
2002
+ column = quotedAs === quoted ? query.shape[name] : query.joinedShapes?.[table2]?.[name];
2155
2003
  quotedColumn = simpleColumnToSQL(ctx, query, name, column, quoted);
2156
2004
  } else {
2157
- column = (_d = (_c = query.joinedShapes) == null ? void 0 : _c[key]) == null ? void 0 : _d.value;
2005
+ column = query.joinedShapes?.[key]?.value;
2158
2006
  quotedColumn = `"${key}".r`;
2159
2007
  }
2160
2008
  if (!column || !quotedColumn) {
@@ -2171,8 +2019,7 @@ const processWhere = (ands, ctx, table, query, data, quotedAs) => {
2171
2019
  if (!operator) {
2172
2020
  throw new Error(`Unknown operator ${op} provided to condition`);
2173
2021
  }
2174
- if (value[op] === void 0)
2175
- continue;
2022
+ if (value[op] === void 0) continue;
2176
2023
  ands.push(
2177
2024
  `${operator._op(
2178
2025
  quotedColumn,
@@ -2218,25 +2065,6 @@ const pushIn = (ctx, query, ands, quotedAs, arg) => {
2218
2065
  ands.push(`${multiple ? `(${columnsSql})` : columnsSql} IN ${value}`);
2219
2066
  };
2220
2067
 
2221
- var __defProp$k = Object.defineProperty;
2222
- var __defProps$b = Object.defineProperties;
2223
- var __getOwnPropDescs$b = Object.getOwnPropertyDescriptors;
2224
- var __getOwnPropSymbols$l = Object.getOwnPropertySymbols;
2225
- var __hasOwnProp$l = Object.prototype.hasOwnProperty;
2226
- var __propIsEnum$l = Object.prototype.propertyIsEnumerable;
2227
- var __defNormalProp$k = (obj, key, value) => key in obj ? __defProp$k(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2228
- var __spreadValues$k = (a, b) => {
2229
- for (var prop in b || (b = {}))
2230
- if (__hasOwnProp$l.call(b, prop))
2231
- __defNormalProp$k(a, prop, b[prop]);
2232
- if (__getOwnPropSymbols$l)
2233
- for (var prop of __getOwnPropSymbols$l(b)) {
2234
- if (__propIsEnum$l.call(b, prop))
2235
- __defNormalProp$k(a, prop, b[prop]);
2236
- }
2237
- return a;
2238
- };
2239
- var __spreadProps$b = (a, b) => __defProps$b(a, __getOwnPropDescs$b(b));
2240
2068
  const processJoinItem = (ctx, table, query, args, quotedAs) => {
2241
2069
  let target;
2242
2070
  let on;
@@ -2298,18 +2126,19 @@ const processJoinItem = (ctx, table, query, args, quotedAs) => {
2298
2126
  const whereSql = whereToSql(
2299
2127
  ctx,
2300
2128
  q,
2301
- __spreadProps$b(__spreadValues$k({}, q.q), {
2302
- joinedShapes: __spreadProps$b(__spreadValues$k(__spreadValues$k({}, query.joinedShapes), q.q.joinedShapes), {
2129
+ {
2130
+ ...q.q,
2131
+ joinedShapes: {
2132
+ ...query.joinedShapes,
2133
+ ...q.q.joinedShapes,
2303
2134
  [table.q.as || table.table]: table.q.shape
2304
- })
2305
- }),
2135
+ }
2136
+ },
2306
2137
  joinAs
2307
2138
  );
2308
2139
  if (whereSql) {
2309
- if (on)
2310
- on += ` AND ${whereSql}`;
2311
- else
2312
- on = whereSql;
2140
+ if (on) on += ` AND ${whereSql}`;
2141
+ else on = whereSql;
2313
2142
  }
2314
2143
  }
2315
2144
  }
@@ -2337,8 +2166,7 @@ const getArgQueryTarget = (ctx, first, joinSubQuery, cloned) => {
2337
2166
  };
2338
2167
  const subJoinToSql = (ctx, jq, innerAs, outerAs, cloned) => {
2339
2168
  if (!jq.q.select && jq.q.selectAllColumns) {
2340
- if (!cloned)
2341
- jq = jq.clone();
2169
+ if (!cloned) jq = jq.clone();
2342
2170
  jq.q.select = [new RawSQL(`${innerAs}.*`)];
2343
2171
  }
2344
2172
  return `(${getSqlText(
@@ -2393,7 +2221,6 @@ const getObjectOrRawConditions = (ctx, query, data, quotedAs, joinAs, joinShape)
2393
2221
  }
2394
2222
  };
2395
2223
  const pushJoinSql = (ctx, table, query, quotedAs) => {
2396
- var _a;
2397
2224
  const joinSet = query.join.length > 1 ? /* @__PURE__ */ new Set() : null;
2398
2225
  for (const item of query.join) {
2399
2226
  let sql;
@@ -2402,7 +2229,7 @@ const pushJoinSql = (ctx, table, query, quotedAs) => {
2402
2229
  const { aliasValue } = ctx;
2403
2230
  ctx.aliasValue = true;
2404
2231
  const as = item[2];
2405
- sql = `${item[0]} LATERAL (${getSqlText(q.toSQL(ctx))}) "${((_a = query.aliases) == null ? void 0 : _a[as]) || as}" ON true`;
2232
+ sql = `${item[0]} LATERAL (${getSqlText(q.toSQL(ctx))}) "${query.aliases?.[as] || as}" ON true`;
2406
2233
  ctx.aliasValue = aliasValue;
2407
2234
  } else {
2408
2235
  const { target, on = "true" } = processJoinItem(
@@ -2415,8 +2242,7 @@ const pushJoinSql = (ctx, table, query, quotedAs) => {
2415
2242
  sql = `${item.type} ${target} ON ${on}`;
2416
2243
  }
2417
2244
  if (joinSet) {
2418
- if (joinSet.has(sql))
2419
- continue;
2245
+ if (joinSet.has(sql)) continue;
2420
2246
  joinSet.add(sql);
2421
2247
  }
2422
2248
  ctx.sql.push(sql);
@@ -2447,27 +2273,7 @@ const getIsJoinSubQuery = (query) => {
2447
2273
  return false;
2448
2274
  };
2449
2275
 
2450
- var __defProp$j = Object.defineProperty;
2451
- var __defProps$a = Object.defineProperties;
2452
- var __getOwnPropDescs$a = Object.getOwnPropertyDescriptors;
2453
- var __getOwnPropSymbols$k = Object.getOwnPropertySymbols;
2454
- var __hasOwnProp$k = Object.prototype.hasOwnProperty;
2455
- var __propIsEnum$k = Object.prototype.propertyIsEnumerable;
2456
- var __defNormalProp$j = (obj, key, value) => key in obj ? __defProp$j(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2457
- var __spreadValues$j = (a, b) => {
2458
- for (var prop in b || (b = {}))
2459
- if (__hasOwnProp$k.call(b, prop))
2460
- __defNormalProp$j(a, prop, b[prop]);
2461
- if (__getOwnPropSymbols$k)
2462
- for (var prop of __getOwnPropSymbols$k(b)) {
2463
- if (__propIsEnum$k.call(b, prop))
2464
- __defNormalProp$j(a, prop, b[prop]);
2465
- }
2466
- return a;
2467
- };
2468
- var __spreadProps$a = (a, b) => __defProps$a(a, __getOwnPropDescs$a(b));
2469
2276
  const processJoinArgs = (joinTo, first, args, joinSubQuery, whereExists) => {
2470
- var _a;
2471
2277
  if (typeof first === "string") {
2472
2278
  if (first in joinTo.relations) {
2473
2279
  const { query: toQuery, joinQuery } = joinTo.relations[first].relationConfig;
@@ -2487,7 +2293,7 @@ const processJoinArgs = (joinTo, first, args, joinSubQuery, whereExists) => {
2487
2293
  return { w: first, a: args };
2488
2294
  } else {
2489
2295
  const joinToQ = joinTo.q;
2490
- const w = (_a = joinToQ.withShapes) == null ? void 0 : _a[first];
2296
+ const w = joinToQ.withShapes?.[first];
2491
2297
  if (!w) {
2492
2298
  throw new Error("Cannot find a `with` statement");
2493
2299
  }
@@ -2502,13 +2308,17 @@ const processJoinArgs = (joinTo, first, args, joinSubQuery, whereExists) => {
2502
2308
  logger: joinToQ.logger
2503
2309
  };
2504
2310
  j.baseQuery = j;
2505
- const joinedShapes = __spreadProps$a(__spreadValues$j({}, joinToQ.joinedShapes), {
2311
+ const joinedShapes = {
2312
+ ...joinToQ.joinedShapes,
2506
2313
  [joinToQ.as || joinTo.table]: joinTo.shape
2507
- });
2314
+ };
2508
2315
  const r = args[0](
2509
2316
  makeJoinQueryBuilder(
2510
2317
  j,
2511
- j.q.joinedShapes ? __spreadValues$j(__spreadValues$j({}, j.q.joinedShapes), joinedShapes) : joinedShapes,
2318
+ j.q.joinedShapes ? {
2319
+ ...j.q.joinedShapes,
2320
+ ...joinedShapes
2321
+ } : joinedShapes,
2512
2322
  joinTo
2513
2323
  )
2514
2324
  );
@@ -2538,16 +2348,20 @@ const processJoinArgs = (joinTo, first, args, joinSubQuery, whereExists) => {
2538
2348
  pushQueryArray(q, "or", query.or);
2539
2349
  }
2540
2350
  if (query.scopes) {
2541
- q.q.scopes = __spreadValues$j(__spreadValues$j({}, q.q.scopes), query.scopes);
2351
+ q.q.scopes = { ...q.q.scopes, ...query.scopes };
2542
2352
  }
2543
2353
  }
2544
- const joinedShapes = __spreadProps$a(__spreadValues$j({}, joinTo.q.joinedShapes), {
2354
+ const joinedShapes = {
2355
+ ...joinTo.q.joinedShapes,
2545
2356
  [joinTo.q.as || joinTo.table]: joinTo.shape
2546
- });
2357
+ };
2547
2358
  const r = args0(
2548
2359
  makeJoinQueryBuilder(
2549
2360
  q,
2550
- q.q.joinedShapes ? __spreadValues$j(__spreadValues$j({}, q.q.joinedShapes), joinedShapes) : joinedShapes,
2361
+ q.q.joinedShapes ? {
2362
+ ...q.q.joinedShapes,
2363
+ ...joinedShapes
2364
+ } : joinedShapes,
2551
2365
  joinTo
2552
2366
  )
2553
2367
  );
@@ -2561,8 +2375,7 @@ const processJoinArgs = (joinTo, first, args, joinSubQuery, whereExists) => {
2561
2375
  };
2562
2376
  };
2563
2377
  const preprocessJoinArg = (q, arg) => {
2564
- if (typeof arg !== "function")
2565
- return arg;
2378
+ if (typeof arg !== "function") return arg;
2566
2379
  arg = arg(q.relations);
2567
2380
  arg.joinQueryAfterCallback = arg.joinQuery;
2568
2381
  return arg;
@@ -2582,20 +2395,16 @@ const noneMethods = {
2582
2395
  async then(resolve, reject) {
2583
2396
  const type = this.q.returnType;
2584
2397
  if (!type || type === "all" || type === "rows" || type === "pluck")
2585
- resolve == null ? void 0 : resolve([]);
2586
- else if (type === "one" || type === "value" || type === "void")
2587
- resolve == null ? void 0 : resolve();
2588
- else if (type === "valueOrThrow" && this.q.returning)
2589
- resolve == null ? void 0 : resolve(0);
2590
- else
2591
- reject == null ? void 0 : reject(new NotFoundError(this));
2398
+ resolve?.([]);
2399
+ else if (type === "one" || type === "value" || type === "void") resolve?.();
2400
+ else if (type === "valueOrThrow" && this.q.returning) resolve?.(0);
2401
+ else reject?.(new NotFoundError(this));
2592
2402
  },
2593
2403
  // `catch` returns a Promise, so it is chainable with then/catch.
2594
2404
  catch: () => new Promise(noop)
2595
2405
  };
2596
2406
  const _queryNone = (q) => {
2597
- if (isQueryNone(q))
2598
- return q;
2407
+ if (isQueryNone(q)) return q;
2599
2408
  q = extendQuery(q, noneMethods);
2600
2409
  pushQueryValue(q, "and", new RawSQL("false"));
2601
2410
  return q;
@@ -2693,8 +2502,7 @@ const _queryWhereIn = (q, and, arg, values, not) => {
2693
2502
  item[key] = { in: values2 };
2694
2503
  }
2695
2504
  }
2696
- if (not)
2697
- item = { NOT: item };
2505
+ if (not) item = { NOT: item };
2698
2506
  if (and) {
2699
2507
  pushQueryValue(q, "and", item);
2700
2508
  } else {
@@ -3394,8 +3202,7 @@ const setQueryObjectValue = (q, object, key, value) => {
3394
3202
  q.q[object] = {
3395
3203
  [key]: value
3396
3204
  };
3397
- else
3398
- q.q[object][key] = value;
3205
+ else q.q[object][key] = value;
3399
3206
  return q;
3400
3207
  };
3401
3208
  const throwIfNoWhere = (q, method) => {
@@ -3407,8 +3214,7 @@ const throwIfNoWhere = (q, method) => {
3407
3214
  }
3408
3215
  };
3409
3216
  const throwIfJoinLateral = (q, method) => {
3410
- var _a;
3411
- if ((_a = q.q.join) == null ? void 0 : _a.some(
3217
+ if (q.q.join?.some(
3412
3218
  (x) => Array.isArray(x) || "s" in x.args && x.args.s
3413
3219
  )) {
3414
3220
  throw new OrchidOrmInternalError(
@@ -3419,7 +3225,7 @@ const throwIfJoinLateral = (q, method) => {
3419
3225
  };
3420
3226
  const saveSearchAlias = (q, as, key) => {
3421
3227
  const shapes = q.q[key];
3422
- if (shapes == null ? void 0 : shapes[as]) {
3228
+ if (shapes?.[as]) {
3423
3229
  let suffix = 2;
3424
3230
  while (shapes[as = `${as}${suffix}`]) {
3425
3231
  suffix++;
@@ -3437,8 +3243,8 @@ const extendQuery = (q, methods) => {
3437
3243
  return cloned;
3438
3244
  };
3439
3245
  const getPrimaryKeys = (q) => {
3440
- var _a, _b;
3441
- return (_b = (_a = q.internal).primaryKeys) != null ? _b : _a.primaryKeys = collectPrimaryKeys(q);
3246
+ var _a;
3247
+ return (_a = q.internal).primaryKeys ?? (_a.primaryKeys = collectPrimaryKeys(q));
3442
3248
  };
3443
3249
  const collectPrimaryKeys = (q) => {
3444
3250
  const primaryKeys = [];
@@ -3448,8 +3254,9 @@ const collectPrimaryKeys = (q) => {
3448
3254
  primaryKeys.push(key);
3449
3255
  }
3450
3256
  }
3451
- if (q.internal.primaryKeys) {
3452
- primaryKeys.push(...q.internal.primaryKeys);
3257
+ const pKeys = q.internal.primaryKeys;
3258
+ if (pKeys) {
3259
+ primaryKeys.push(...pKeys);
3453
3260
  }
3454
3261
  return primaryKeys;
3455
3262
  };
@@ -3481,27 +3288,8 @@ const _queryRows = (q) => {
3481
3288
  return q;
3482
3289
  };
3483
3290
 
3484
- var __defProp$i = Object.defineProperty;
3485
- var __defProps$9 = Object.defineProperties;
3486
- var __getOwnPropDescs$9 = Object.getOwnPropertyDescriptors;
3487
- var __getOwnPropSymbols$j = Object.getOwnPropertySymbols;
3488
- var __hasOwnProp$j = Object.prototype.hasOwnProperty;
3489
- var __propIsEnum$j = Object.prototype.propertyIsEnumerable;
3490
- var __defNormalProp$i = (obj, key, value) => key in obj ? __defProp$i(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3491
- var __spreadValues$i = (a, b) => {
3492
- for (var prop in b || (b = {}))
3493
- if (__hasOwnProp$j.call(b, prop))
3494
- __defNormalProp$i(a, prop, b[prop]);
3495
- if (__getOwnPropSymbols$j)
3496
- for (var prop of __getOwnPropSymbols$j(b)) {
3497
- if (__propIsEnum$j.call(b, prop))
3498
- __defNormalProp$i(a, prop, b[prop]);
3499
- }
3500
- return a;
3501
- };
3502
- var __spreadProps$9 = (a, b) => __defProps$9(a, __getOwnPropDescs$9(b));
3503
- const _join = (query, require2, type, first, args) => {
3504
- var _a, _b, _c, _d;
3291
+ const _join = (query, require, type, first, args) => {
3292
+ var _a;
3505
3293
  let joinKey;
3506
3294
  let shape;
3507
3295
  let parsers;
@@ -3510,7 +3298,7 @@ const _join = (query, require2, type, first, args) => {
3510
3298
  let joinSubQuery = false;
3511
3299
  first = preprocessJoinArg(query, first);
3512
3300
  if (typeof first === "object") {
3513
- if (require2 && isQueryNone(first)) {
3301
+ if (require && isQueryNone(first)) {
3514
3302
  return _queryNone(query);
3515
3303
  }
3516
3304
  const q2 = first;
@@ -3536,12 +3324,11 @@ const _join = (query, require2, type, first, args) => {
3536
3324
  batchParsers = r.q.batchParsers;
3537
3325
  computeds = r.q.computeds;
3538
3326
  } else {
3539
- const w = (_a = query.q.withShapes) == null ? void 0 : _a[joinKey];
3540
- shape = w == null ? void 0 : w.shape;
3541
- computeds = w == null ? void 0 : w.computeds;
3327
+ const w = query.q.withShapes?.[joinKey];
3328
+ shape = w?.shape;
3329
+ computeds = w?.computeds;
3542
3330
  if (shape) {
3543
- if (!require2)
3544
- shape = __spreadValues$i({}, shape);
3331
+ if (!require) shape = { ...shape };
3545
3332
  const arg = { parsers: {} };
3546
3333
  for (const key in shape) {
3547
3334
  addColumnParserToQuery(arg, key, shape[key]);
@@ -3556,7 +3343,7 @@ const _join = (query, require2, type, first, args) => {
3556
3343
  joinSubQuery
3557
3344
  );
3558
3345
  if (joinKey && "s" in joinArgs && joinArgs.s) {
3559
- const j = "j" in joinArgs ? (_b = joinArgs.r) != null ? _b : joinArgs.j : "r" in joinArgs ? joinArgs.r : joinArgs.q;
3346
+ const j = "j" in joinArgs ? joinArgs.r ?? joinArgs.j : "r" in joinArgs ? joinArgs.r : joinArgs.q;
3560
3347
  if (j.q.select || !j.q.selectAllColumns) {
3561
3348
  const shape2 = getShapeFromSelect(j, true);
3562
3349
  setQueryObjectValue(
@@ -3572,7 +3359,7 @@ const _join = (query, require2, type, first, args) => {
3572
3359
  j.q.parsers
3573
3360
  );
3574
3361
  if (j.q.batchParsers) {
3575
- ((_d = (_c = query.q).joinedBatchParsers) != null ? _d : _c.joinedBatchParsers = {})[joinKey] = j.q.batchParsers;
3362
+ ((_a = query.q).joinedBatchParsers ?? (_a.joinedBatchParsers = {}))[joinKey] = j.q.batchParsers;
3576
3363
  }
3577
3364
  setQueryObjectValue(
3578
3365
  query,
@@ -3590,7 +3377,7 @@ const _join = (query, require2, type, first, args) => {
3590
3377
  computeds
3591
3378
  );
3592
3379
  }
3593
- } else if (require2 && "r" in joinArgs && isQueryNone(joinArgs.r)) {
3380
+ } else if (require && "r" in joinArgs && isQueryNone(joinArgs.r)) {
3594
3381
  return _queryNone(query);
3595
3382
  } else {
3596
3383
  addAllShapesAndParsers(
@@ -3612,13 +3399,12 @@ const _join = (query, require2, type, first, args) => {
3612
3399
  return q;
3613
3400
  };
3614
3401
  const addAllShapesAndParsers = (query, joinKey, shape, parsers, batchParsers, computeds) => {
3615
- var _a, _b;
3616
- if (!joinKey)
3617
- return;
3402
+ var _a;
3403
+ if (!joinKey) return;
3618
3404
  setQueryObjectValue(query, "joinedShapes", joinKey, shape);
3619
3405
  setQueryObjectValue(query, "joinedParsers", joinKey, parsers);
3620
3406
  if (batchParsers) {
3621
- ((_b = (_a = query.q).joinedBatchParsers) != null ? _b : _a.joinedBatchParsers = {})[joinKey] = batchParsers;
3407
+ ((_a = query.q).joinedBatchParsers ?? (_a.joinedBatchParsers = {}))[joinKey] = batchParsers;
3622
3408
  }
3623
3409
  setQueryObjectValue(
3624
3410
  query,
@@ -3628,7 +3414,7 @@ const addAllShapesAndParsers = (query, joinKey, shape, parsers, batchParsers, co
3628
3414
  );
3629
3415
  };
3630
3416
  const _joinLateral = (self, type, arg, cb, as) => {
3631
- var _a, _b, _c, _d, _e, _f, _g;
3417
+ var _a, _b, _c;
3632
3418
  const q = self;
3633
3419
  let relation;
3634
3420
  if (typeof arg === "string") {
@@ -3636,15 +3422,16 @@ const _joinLateral = (self, type, arg, cb, as) => {
3636
3422
  if (relation) {
3637
3423
  arg = _clone(relation.relationConfig.query);
3638
3424
  } else {
3639
- const w = (_a = q.q.withShapes) == null ? void 0 : _a[arg];
3425
+ const w = q.q.withShapes?.[arg];
3640
3426
  if (w) {
3641
3427
  const t = Object.create(q.queryBuilder);
3642
3428
  t.table = arg;
3643
3429
  t.shape = w.shape;
3644
3430
  t.computeds = w.computeds;
3645
- t.q = __spreadProps$9(__spreadValues$i({}, t.q), {
3431
+ t.q = {
3432
+ ...t.q,
3646
3433
  shape: w.shape
3647
- });
3434
+ };
3648
3435
  t.baseQuery = t;
3649
3436
  arg = t;
3650
3437
  }
@@ -3653,7 +3440,7 @@ const _joinLateral = (self, type, arg, cb, as) => {
3653
3440
  const query = arg;
3654
3441
  query.q.joinTo = q;
3655
3442
  const joinedAs = getQueryAs(q);
3656
- ((_c = (_b = query.q).joinedShapes) != null ? _c : _b.joinedShapes = {})[joinedAs] = q.q.shape;
3443
+ ((_a = query.q).joinedShapes ?? (_a.joinedShapes = {}))[joinedAs] = q.q.shape;
3657
3444
  let result = resolveSubQueryCallback(query, cb);
3658
3445
  if (relation) {
3659
3446
  result = relation.relationConfig.joinQuery(
@@ -3667,11 +3454,11 @@ const _joinLateral = (self, type, arg, cb, as) => {
3667
3454
  setQueryObjectValue(q, "joinedShapes", joinKey, shape);
3668
3455
  setQueryObjectValue(q, "joinedParsers", joinKey, result.q.parsers);
3669
3456
  if (result.q.batchParsers) {
3670
- ((_e = (_d = q.q).joinedBatchParsers) != null ? _e : _d.joinedBatchParsers = {})[joinKey] = result.q.batchParsers;
3457
+ ((_b = q.q).joinedBatchParsers ?? (_b.joinedBatchParsers = {}))[joinKey] = result.q.batchParsers;
3671
3458
  }
3672
3459
  }
3673
3460
  as || (as = getQueryAs(result));
3674
- ((_g = (_f = q.q).joinedComputeds) != null ? _g : _f.joinedComputeds = {})[as] = result.q.computeds;
3461
+ ((_c = q.q).joinedComputeds ?? (_c.joinedComputeds = {}))[as] = result.q.computeds;
3675
3462
  return pushQueryValue(q, "join", [type, result, as]);
3676
3463
  };
3677
3464
 
@@ -3735,11 +3522,9 @@ const parsePostgresArray = (source, entries, transform) => {
3735
3522
  let pos = 0;
3736
3523
  if (source[0] === "[") {
3737
3524
  pos = source.indexOf("=") + 1;
3738
- if (!pos)
3739
- pos = source.length;
3525
+ if (!pos) pos = source.length;
3740
3526
  }
3741
- if (source[pos] === "{")
3742
- pos++;
3527
+ if (source[pos] === "{") pos++;
3743
3528
  let recorded = "";
3744
3529
  while (pos < source.length) {
3745
3530
  const character = source[pos++];
@@ -3760,8 +3545,7 @@ const parsePostgresArray = (source, entries, transform) => {
3760
3545
  while (pos < source.length) {
3761
3546
  let char;
3762
3547
  while ((char = source[pos++]) === "\\") {
3763
- if (!(esc = !esc))
3764
- rec += "\\";
3548
+ if (!(esc = !esc)) rec += "\\";
3765
3549
  }
3766
3550
  if (esc) {
3767
3551
  esc = false;
@@ -4048,20 +3832,14 @@ const defaultSchemaConfig = {
4048
3832
 
4049
3833
  const escape = (value, migration, nested) => {
4050
3834
  const type = typeof value;
4051
- if (type === "number" || type === "bigint")
4052
- return String(value);
4053
- else if (type === "string")
4054
- return escapeString(value);
4055
- else if (type === "boolean")
4056
- return value ? "true" : "false";
4057
- else if (value instanceof Date)
4058
- return `'${value.toISOString()}'`;
3835
+ if (type === "number" || type === "bigint") return String(value);
3836
+ else if (type === "string") return escapeString(value);
3837
+ else if (type === "boolean") return value ? "true" : "false";
3838
+ else if (value instanceof Date) return `'${value.toISOString()}'`;
4059
3839
  else if (Array.isArray(value))
4060
3840
  return migration && nested && !value.length ? "" : (migration ? nested ? "{" : "'{" : nested ? "[" : "ARRAY[") + value.map((el) => escape(el, migration, true)).join(",") + (migration ? nested ? "}" : "}'" : "]");
4061
- else if (value === null || value === void 0)
4062
- return "NULL";
4063
- else
4064
- return escapeString(JSON.stringify(value));
3841
+ else if (value === null || value === void 0) return "NULL";
3842
+ else return escapeString(JSON.stringify(value));
4065
3843
  };
4066
3844
  const escapeForLog = (value) => escape(value);
4067
3845
  const escapeForMigration = (value) => escape(value, true);
@@ -4071,15 +3849,14 @@ const makeMessage = (colors, timeColor, time, sqlColor, sql, valuesColor, values
4071
3849
  const elapsed = process.hrtime(time);
4072
3850
  const formattedTime = `(${elapsed[0] ? `${elapsed[0]}s ` : ""}${(elapsed[1] / 1e6).toFixed(1)}ms)`;
4073
3851
  const result = `${colors ? timeColor(formattedTime) : formattedTime} ${colors ? sqlColor(sql) : sql}`;
4074
- if (!(values == null ? void 0 : values.length)) {
3852
+ if (!values?.length) {
4075
3853
  return result;
4076
3854
  }
4077
3855
  const formattedValues = `[${values.map(escapeForLog).join(", ")}]`;
4078
3856
  return `${result} ${colors ? valuesColor(formattedValues) : formattedValues}`;
4079
3857
  };
4080
3858
  const logParamToLogObject = (logger, log) => {
4081
- if (!log)
4082
- return;
3859
+ if (!log) return;
4083
3860
  const logObject = Object.assign(
4084
3861
  {
4085
3862
  colors: true,
@@ -4127,25 +3904,6 @@ class QueryLog {
4127
3904
  }
4128
3905
  }
4129
3906
 
4130
- var __defProp$h = Object.defineProperty;
4131
- var __defProps$8 = Object.defineProperties;
4132
- var __getOwnPropDescs$8 = Object.getOwnPropertyDescriptors;
4133
- var __getOwnPropSymbols$i = Object.getOwnPropertySymbols;
4134
- var __hasOwnProp$i = Object.prototype.hasOwnProperty;
4135
- var __propIsEnum$i = Object.prototype.propertyIsEnumerable;
4136
- var __defNormalProp$h = (obj, key, value) => key in obj ? __defProp$h(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
4137
- var __spreadValues$h = (a, b) => {
4138
- for (var prop in b || (b = {}))
4139
- if (__hasOwnProp$i.call(b, prop))
4140
- __defNormalProp$h(a, prop, b[prop]);
4141
- if (__getOwnPropSymbols$i)
4142
- for (var prop of __getOwnPropSymbols$i(b)) {
4143
- if (__propIsEnum$i.call(b, prop))
4144
- __defNormalProp$h(a, prop, b[prop]);
4145
- }
4146
- return a;
4147
- };
4148
- var __spreadProps$8 = (a, b) => __defProps$8(a, __getOwnPropDescs$8(b));
4149
3907
  const commitSql$1 = {
4150
3908
  text: "COMMIT"
4151
3909
  };
@@ -4169,7 +3927,6 @@ const _afterCommitError = (result, hookResults, catchAfterCommitError) => {
4169
3927
  };
4170
3928
  class Transaction {
4171
3929
  async transaction(cbOrOptions, cb) {
4172
- var _a;
4173
3930
  let options;
4174
3931
  let fn;
4175
3932
  if (typeof cbOrOptions === "function") {
@@ -4182,15 +3939,13 @@ class Transaction {
4182
3939
  const sql = {
4183
3940
  values: emptyArray
4184
3941
  };
4185
- const log = options.log !== void 0 ? (_a = this.q.log) != null ? _a : logParamToLogObject(this.q.logger, options.log) : this.q.log;
3942
+ const log = options.log !== void 0 ? this.q.log ?? logParamToLogObject(this.q.logger, options.log) : this.q.log;
4186
3943
  let logData;
4187
3944
  let trx = this.internal.transactionStorage.getStore();
4188
3945
  const transactionId = trx ? trx.transactionId + 1 : 0;
4189
3946
  const callback = (adapter) => {
4190
- if (log)
4191
- log.afterQuery(sql, logData);
4192
- if (log)
4193
- logData = log.beforeQuery(commitSql$1);
3947
+ if (log) log.afterQuery(sql, logData);
3948
+ if (log) logData = log.beforeQuery(commitSql$1);
4194
3949
  if (trx) {
4195
3950
  trx.transactionId = transactionId;
4196
3951
  return fn();
@@ -4206,15 +3961,12 @@ class Transaction {
4206
3961
  };
4207
3962
  if (!trx) {
4208
3963
  sql.text = `BEGIN${options.level ? ` ISOLATION LEVEL ${options.level}` : ""}${options.readOnly !== void 0 ? ` READ ${options.readOnly ? "ONLY" : "WRITE"}` : ""}${options.deferrable !== void 0 ? ` ${options.deferrable ? "" : "NOT "}DEFERRABLE` : ""}`;
4209
- if (log)
4210
- logData = log.beforeQuery(sql);
3964
+ if (log) logData = log.beforeQuery(sql);
4211
3965
  const result = await this.q.adapter.transaction(sql, callback).catch((err) => {
4212
- if (log)
4213
- log.afterQuery(rollbackSql$1, logData);
3966
+ if (log) log.afterQuery(rollbackSql$1, logData);
4214
3967
  throw err;
4215
3968
  });
4216
- if (log)
4217
- log.afterQuery(commitSql$1, logData);
3969
+ if (log) log.afterQuery(commitSql$1, logData);
4218
3970
  await runAfterCommit(
4219
3971
  trx.afterCommit,
4220
3972
  result
@@ -4223,8 +3975,7 @@ class Transaction {
4223
3975
  } else {
4224
3976
  try {
4225
3977
  sql.text = `SAVEPOINT "${transactionId}"`;
4226
- if (log)
4227
- logData = log.beforeQuery(sql);
3978
+ if (log) logData = log.beforeQuery(sql);
4228
3979
  const { adapter } = trx;
4229
3980
  await adapter.query(sql);
4230
3981
  let result;
@@ -4232,19 +3983,15 @@ class Transaction {
4232
3983
  result = await callback(adapter);
4233
3984
  } catch (err) {
4234
3985
  sql.text = `ROLLBACK TO SAVEPOINT "${transactionId}"`;
4235
- if (log)
4236
- logData = log.beforeQuery(sql);
3986
+ if (log) logData = log.beforeQuery(sql);
4237
3987
  await adapter.query(sql);
4238
- if (log)
4239
- log.afterQuery(sql, logData);
3988
+ if (log) log.afterQuery(sql, logData);
4240
3989
  throw err;
4241
3990
  }
4242
3991
  sql.text = `RELEASE SAVEPOINT "${transactionId}"`;
4243
- if (log)
4244
- logData = log.beforeQuery(sql);
3992
+ if (log) logData = log.beforeQuery(sql);
4245
3993
  await adapter.query(sql);
4246
- if (log)
4247
- log.afterQuery(sql, logData);
3994
+ if (log) log.afterQuery(sql, logData);
4248
3995
  if (transactionId === trx.testTransactionCount) {
4249
3996
  await runAfterCommit(
4250
3997
  trx.afterCommit,
@@ -4279,8 +4026,7 @@ class Transaction {
4279
4026
  */
4280
4027
  ensureTransaction(cb) {
4281
4028
  const trx = this.internal.transactionStorage.getStore();
4282
- if (trx)
4283
- return cb();
4029
+ if (trx) return cb();
4284
4030
  return Transaction.prototype.transaction.call(this, cb);
4285
4031
  }
4286
4032
  isInTransaction() {
@@ -4312,9 +4058,10 @@ const runAfterCommit = async (afterCommit, result) => {
4312
4058
  let r = 0;
4313
4059
  for (let i = 0, len = afterCommit.length; i < len; i += 3) {
4314
4060
  for (const fn of afterCommit[i + 2]) {
4315
- resultsWithNames.push(__spreadProps$8(__spreadValues$h({}, hookResults[r++]), {
4061
+ resultsWithNames.push({
4062
+ ...hookResults[r++],
4316
4063
  name: fn.name
4317
- }));
4064
+ });
4318
4065
  }
4319
4066
  }
4320
4067
  _afterCommitError(result, resultsWithNames, catchAfterCommitError);
@@ -4334,7 +4081,6 @@ const applyBatchTransforms = (query, batches) => {
4334
4081
  }
4335
4082
  };
4336
4083
  const finalizeNestedHookSelect = (batches, returnType, tempColumns, renames, key) => {
4337
- var _a;
4338
4084
  if (renames) {
4339
4085
  for (const { data } of batches) {
4340
4086
  for (const record of data) {
@@ -4346,7 +4092,7 @@ const finalizeNestedHookSelect = (batches, returnType, tempColumns, renames, key
4346
4092
  }
4347
4093
  }
4348
4094
  }
4349
- if (tempColumns == null ? void 0 : tempColumns.size) {
4095
+ if (tempColumns?.size) {
4350
4096
  for (const { data } of batches) {
4351
4097
  for (const record of data) {
4352
4098
  if (record) {
@@ -4369,30 +4115,11 @@ const finalizeNestedHookSelect = (batches, returnType, tempColumns, renames, key
4369
4115
  }
4370
4116
  } else if (returnType === "value" || returnType === "valueOrThrow") {
4371
4117
  for (const item of batches) {
4372
- item.parent[item.key] = (_a = item.data[0]) == null ? void 0 : _a[key];
4118
+ item.parent[item.key] = item.data[0]?.[key];
4373
4119
  }
4374
4120
  }
4375
4121
  };
4376
4122
 
4377
- var __defProp$g = Object.defineProperty;
4378
- var __defProps$7 = Object.defineProperties;
4379
- var __getOwnPropDescs$7 = Object.getOwnPropertyDescriptors;
4380
- var __getOwnPropSymbols$h = Object.getOwnPropertySymbols;
4381
- var __hasOwnProp$h = Object.prototype.hasOwnProperty;
4382
- var __propIsEnum$h = Object.prototype.propertyIsEnumerable;
4383
- var __defNormalProp$g = (obj, key, value) => key in obj ? __defProp$g(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
4384
- var __spreadValues$g = (a, b) => {
4385
- for (var prop in b || (b = {}))
4386
- if (__hasOwnProp$h.call(b, prop))
4387
- __defNormalProp$g(a, prop, b[prop]);
4388
- if (__getOwnPropSymbols$h)
4389
- for (var prop of __getOwnPropSymbols$h(b)) {
4390
- if (__propIsEnum$h.call(b, prop))
4391
- __defNormalProp$g(a, prop, b[prop]);
4392
- }
4393
- return a;
4394
- };
4395
- var __spreadProps$7 = (a, b) => __defProps$7(a, __getOwnPropDescs$7(b));
4396
4123
  class ComputedColumn {
4397
4124
  constructor(kind, deps, fn) {
4398
4125
  this.kind = kind;
@@ -4409,9 +4136,10 @@ const applyComputedColumns = (q, fn) => {
4409
4136
  for (const key in computed) {
4410
4137
  const item = computed[key];
4411
4138
  if (item instanceof ComputedColumn) {
4412
- q.q.computeds = __spreadProps$7(__spreadValues$g({}, q.q.computeds), {
4139
+ q.q.computeds = {
4140
+ ...q.q.computeds,
4413
4141
  [key]: item
4414
- });
4142
+ };
4415
4143
  } else {
4416
4144
  const data = (q.shape[key] = item.result.value || UnknownColumn.instance).data;
4417
4145
  data.computed = item;
@@ -4433,7 +4161,7 @@ const processComputedResult = (query, result) => {
4433
4161
  if (Array.isArray(res)) {
4434
4162
  saveBatchComputed(key, result, res);
4435
4163
  } else {
4436
- (promises != null ? promises : promises = []).push(
4164
+ (promises ?? (promises = [])).push(
4437
4165
  res.then(
4438
4166
  (res2) => saveBatchComputed(key, result, res2)
4439
4167
  )
@@ -4441,8 +4169,7 @@ const processComputedResult = (query, result) => {
4441
4169
  }
4442
4170
  }
4443
4171
  }
4444
- if (!promises)
4445
- return;
4172
+ if (!promises) return;
4446
4173
  return Promise.all(promises);
4447
4174
  };
4448
4175
  const processComputedBatches = (query, batches, originalReturnType, returnType, tempColumns, renames, key) => {
@@ -4478,7 +4205,7 @@ const processComputedBatches = (query, batches, originalReturnType, returnType,
4478
4205
  if (Array.isArray(res)) {
4479
4206
  saveBatchComputed(key2, data, res, blanks);
4480
4207
  } else {
4481
- (promises != null ? promises : promises = []).push(
4208
+ (promises ?? (promises = [])).push(
4482
4209
  res.then(
4483
4210
  (res2) => saveBatchComputed(key2, data, res2, blanks)
4484
4211
  )
@@ -4487,8 +4214,7 @@ const processComputedBatches = (query, batches, originalReturnType, returnType,
4487
4214
  }
4488
4215
  }
4489
4216
  }
4490
- if (!promises)
4491
- return;
4217
+ if (!promises) return;
4492
4218
  return Promise.all(promises).then(() => {
4493
4219
  finalizeNestedHookSelect(
4494
4220
  batches,
@@ -4502,7 +4228,7 @@ const processComputedBatches = (query, batches, originalReturnType, returnType,
4502
4228
  };
4503
4229
  const saveBatchComputed = (key, result, res, blanks) => {
4504
4230
  const len = result.length;
4505
- const actual = res.length + ((blanks == null ? void 0 : blanks.size) || 0);
4231
+ const actual = res.length + (blanks?.size || 0);
4506
4232
  if (len !== actual) {
4507
4233
  throw new Error(
4508
4234
  `Incorrect length of batch computed result for column ${key}. Expected ${len}, received ${actual}.`
@@ -4521,25 +4247,6 @@ const saveBatchComputed = (key, result, res, blanks) => {
4521
4247
  }
4522
4248
  };
4523
4249
 
4524
- var __defProp$f = Object.defineProperty;
4525
- var __defProps$6 = Object.defineProperties;
4526
- var __getOwnPropDescs$6 = Object.getOwnPropertyDescriptors;
4527
- var __getOwnPropSymbols$g = Object.getOwnPropertySymbols;
4528
- var __hasOwnProp$g = Object.prototype.hasOwnProperty;
4529
- var __propIsEnum$g = Object.prototype.propertyIsEnumerable;
4530
- var __defNormalProp$f = (obj, key, value) => key in obj ? __defProp$f(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
4531
- var __spreadValues$f = (a, b) => {
4532
- for (var prop in b || (b = {}))
4533
- if (__hasOwnProp$g.call(b, prop))
4534
- __defNormalProp$f(a, prop, b[prop]);
4535
- if (__getOwnPropSymbols$g)
4536
- for (var prop of __getOwnPropSymbols$g(b)) {
4537
- if (__propIsEnum$g.call(b, prop))
4538
- __defNormalProp$f(a, prop, b[prop]);
4539
- }
4540
- return a;
4541
- };
4542
- var __spreadProps$6 = (a, b) => __defProps$6(a, __getOwnPropDescs$6(b));
4543
4250
  const queryMethodByReturnType = {
4544
4251
  undefined: "query",
4545
4252
  all: "query",
@@ -4562,11 +4269,9 @@ let getThen;
4562
4269
  if (process.versions.bun) {
4563
4270
  getThen = function() {
4564
4271
  queryError = new Error();
4565
- if (!this.internal)
4566
- return maybeWrappedThen;
4272
+ if (!this.internal) return maybeWrappedThen;
4567
4273
  const trx = this.internal.transactionStorage.getStore();
4568
- if (!trx)
4569
- return maybeWrappedThen;
4274
+ if (!trx) return maybeWrappedThen;
4570
4275
  return (resolve, reject) => {
4571
4276
  return this.internal.transactionStorage.run(trx, () => {
4572
4277
  return maybeWrappedThen.call(this, resolve, reject);
@@ -4628,7 +4333,7 @@ function maybeWrappedThen(resolve, reject) {
4628
4333
  } else {
4629
4334
  return then(
4630
4335
  this,
4631
- (trx == null ? void 0 : trx.adapter) || this.q.adapter,
4336
+ trx?.adapter || this.q.adapter,
4632
4337
  trx,
4633
4338
  beforeHooks,
4634
4339
  afterHooks,
@@ -4645,11 +4350,10 @@ const callAfterHook = function(cb) {
4645
4350
  };
4646
4351
  const beginSql = { text: "BEGIN" };
4647
4352
  const then = async (q, adapter, trx, beforeHooks, afterHooks, afterCommitHooks, resolve, reject) => {
4648
- var _a, _b, _c;
4649
4353
  const { q: query } = q;
4650
4354
  let sql;
4651
4355
  let logData;
4652
- const log = (_a = trx == null ? void 0 : trx.log) != null ? _a : query.log;
4356
+ const log = trx?.log ?? query.log;
4653
4357
  const localError = queryError;
4654
4358
  try {
4655
4359
  if (beforeHooks || query.before) {
@@ -4685,11 +4389,9 @@ const then = async (q, adapter, trx, beforeHooks, afterHooks, afterCommitHooks,
4685
4389
  } else {
4686
4390
  const queryMethod = queryMethodByReturnType[tempReturnType];
4687
4391
  if (!trx) {
4688
- if (log)
4689
- logData = log.beforeQuery(beginSql);
4392
+ if (log) logData = log.beforeQuery(beginSql);
4690
4393
  await adapter.arrays(beginSql);
4691
- if (log)
4692
- log.afterQuery(beginSql, logData);
4394
+ if (log) log.afterQuery(beginSql, logData);
4693
4395
  }
4694
4396
  for (const item of sql.batch) {
4695
4397
  sql = item;
@@ -4709,11 +4411,9 @@ const then = async (q, adapter, trx, beforeHooks, afterHooks, afterCommitHooks,
4709
4411
  }
4710
4412
  }
4711
4413
  if (!trx) {
4712
- if (log)
4713
- logData = log.beforeQuery(commitSql$1);
4414
+ if (log) logData = log.beforeQuery(commitSql$1);
4714
4415
  await adapter.arrays(commitSql$1);
4715
- if (log)
4716
- log.afterQuery(commitSql$1, logData);
4416
+ if (log) log.afterQuery(commitSql$1, logData);
4717
4417
  }
4718
4418
  if (query.patchResult) {
4719
4419
  await query.patchResult(q, queryResult);
@@ -4728,9 +4428,8 @@ const then = async (q, adapter, trx, beforeHooks, afterHooks, afterCommitHooks,
4728
4428
  if (hookSelect) {
4729
4429
  for (const column of hookSelect.keys()) {
4730
4430
  const as = hookSelect.get(column).as;
4731
- if (as)
4732
- (renames != null ? renames : renames = {})[column] = as;
4733
- (_b = tempColumns != null ? tempColumns : tempColumns = /* @__PURE__ */ new Set()) == null ? void 0 : _b.add(as || column);
4431
+ if (as) (renames ?? (renames = {}))[column] = as;
4432
+ (tempColumns ?? (tempColumns = /* @__PURE__ */ new Set()))?.add(as || column);
4734
4433
  }
4735
4434
  if (renames) {
4736
4435
  for (const record of result) {
@@ -4743,8 +4442,7 @@ const then = async (q, adapter, trx, beforeHooks, afterHooks, afterCommitHooks,
4743
4442
  }
4744
4443
  if (query.selectedComputeds) {
4745
4444
  const promise = processComputedResult(query, result);
4746
- if (promise)
4747
- await promise;
4445
+ if (promise) await promise;
4748
4446
  }
4749
4447
  }
4750
4448
  const hasAfterHook = afterHooks || afterCommitHooks || query.after;
@@ -4762,7 +4460,7 @@ const then = async (q, adapter, trx, beforeHooks, afterHooks, afterCommitHooks,
4762
4460
  if (afterCommitHooks) {
4763
4461
  if (trx && // when inside test transactions, push to a transaction only unless it's the outer user transaction.
4764
4462
  (!trx.testTransactionCount || trx.transactionId + 1 > trx.testTransactionCount)) {
4765
- ((_c = trx.afterCommit) != null ? _c : trx.afterCommit = []).push(
4463
+ (trx.afterCommit ?? (trx.afterCommit = [])).push(
4766
4464
  result,
4767
4465
  q,
4768
4466
  afterCommitHooks
@@ -4782,7 +4480,8 @@ const then = async (q, adapter, trx, beforeHooks, afterHooks, afterCommitHooks,
4782
4480
  if (hookResults.some((result2) => result2.status === "rejected")) {
4783
4481
  _afterCommitError(
4784
4482
  result,
4785
- hookResults.map((result2, i) => __spreadProps$6(__spreadValues$f({}, result2), {
4483
+ hookResults.map((result2, i) => ({
4484
+ ...result2,
4786
4485
  name: afterCommitHooks[i].name
4787
4486
  })),
4788
4487
  q.q.catchAfterCommitError
@@ -4816,7 +4515,7 @@ const then = async (q, adapter, trx, beforeHooks, afterHooks, afterCommitHooks,
4816
4515
  if (query.transform) {
4817
4516
  result = applyTransforms(returnType, query.transform, result);
4818
4517
  }
4819
- return resolve == null ? void 0 : resolve(result);
4518
+ return resolve?.(result);
4820
4519
  } catch (err) {
4821
4520
  let error;
4822
4521
  if (err instanceof pg.DatabaseError) {
@@ -4842,7 +4541,7 @@ const then = async (q, adapter, trx, beforeHooks, afterHooks, afterCommitHooks,
4842
4541
  if (log && sql) {
4843
4542
  log.onError(error, sql, logData);
4844
4543
  }
4845
- return reject == null ? void 0 : reject(error);
4544
+ return reject?.(error);
4846
4545
  }
4847
4546
  };
4848
4547
  const assignError = (to, from) => {
@@ -4868,7 +4567,6 @@ const assignError = (to, from) => {
4868
4567
  return to;
4869
4568
  };
4870
4569
  const handleResult = (q, returnType, result, isSubQuery) => {
4871
- var _a, _b;
4872
4570
  const { parsers } = q.q;
4873
4571
  switch (returnType) {
4874
4572
  case "all": {
@@ -4885,20 +4583,16 @@ const handleResult = (q, returnType, result, isSubQuery) => {
4885
4583
  }
4886
4584
  case "one": {
4887
4585
  const { rows } = result;
4888
- if (!rows.length)
4889
- return;
4586
+ if (!rows.length) return;
4890
4587
  const promise = parseBatch(q, result);
4891
- if (parsers)
4892
- parseRecord(parsers, rows[0]);
4588
+ if (parsers) parseRecord(parsers, rows[0]);
4893
4589
  return promise ? promise.then(() => rows[0]) : rows[0];
4894
4590
  }
4895
4591
  case "oneOrThrow": {
4896
4592
  const { rows } = result;
4897
- if (!rows.length)
4898
- throw new NotFoundError(q);
4593
+ if (!rows.length) throw new NotFoundError(q);
4899
4594
  const promise = parseBatch(q, result);
4900
- if (parsers)
4901
- parseRecord(parsers, rows[0]);
4595
+ if (parsers) parseRecord(parsers, rows[0]);
4902
4596
  return promise ? promise.then(() => rows[0]) : rows[0];
4903
4597
  }
4904
4598
  case "rows": {
@@ -4906,8 +4600,7 @@ const handleResult = (q, returnType, result, isSubQuery) => {
4906
4600
  const promise = parseBatch(q, result);
4907
4601
  if (promise) {
4908
4602
  return promise.then(() => {
4909
- if (parsers)
4910
- parseRows(parsers, result.fields, rows);
4603
+ if (parsers) parseRows(parsers, result.fields, rows);
4911
4604
  return rows;
4912
4605
  });
4913
4606
  } else if (parsers) {
@@ -4932,11 +4625,10 @@ const handleResult = (q, returnType, result, isSubQuery) => {
4932
4625
  const promise = parseBatch(q, result);
4933
4626
  if (promise) {
4934
4627
  return promise.then(() => {
4935
- var _a2;
4936
- return ((_a2 = rows[0]) == null ? void 0 : _a2[0]) !== void 0 ? parseValue(rows[0][0], parsers) : q.q.notFoundDefault;
4628
+ return rows[0]?.[0] !== void 0 ? parseValue(rows[0][0], parsers) : q.q.notFoundDefault;
4937
4629
  });
4938
4630
  }
4939
- return ((_a = rows[0]) == null ? void 0 : _a[0]) !== void 0 ? parseValue(rows[0][0], parsers) : q.q.notFoundDefault;
4631
+ return rows[0]?.[0] !== void 0 ? parseValue(rows[0][0], parsers) : q.q.notFoundDefault;
4940
4632
  }
4941
4633
  case "valueOrThrow": {
4942
4634
  if (q.q.returning) {
@@ -4949,14 +4641,11 @@ const handleResult = (q, returnType, result, isSubQuery) => {
4949
4641
  const promise = parseBatch(q, result);
4950
4642
  if (promise) {
4951
4643
  return promise.then(() => {
4952
- var _a2;
4953
- if (((_a2 = rows[0]) == null ? void 0 : _a2[0]) === void 0)
4954
- throw new NotFoundError(q);
4644
+ if (rows[0]?.[0] === void 0) throw new NotFoundError(q);
4955
4645
  return parseValue(rows[0][0], parsers);
4956
4646
  });
4957
4647
  }
4958
- if (((_b = rows[0]) == null ? void 0 : _b[0]) === void 0)
4959
- throw new NotFoundError(q);
4648
+ if (rows[0]?.[0] === void 0) throw new NotFoundError(q);
4960
4649
  return parseValue(rows[0][0], parsers);
4961
4650
  }
4962
4651
  case "void": {
@@ -4969,8 +4658,7 @@ const parseBatch = (q, queryResult) => {
4969
4658
  if (q.q.batchParsers) {
4970
4659
  for (const parser of q.q.batchParsers) {
4971
4660
  const res = parser.fn(parser.path, queryResult);
4972
- if (res)
4973
- (promises != null ? promises : promises = []).push(res);
4661
+ if (res) (promises ?? (promises = [])).push(res);
4974
4662
  }
4975
4663
  }
4976
4664
  return promises && Promise.all(promises);
@@ -4994,7 +4682,7 @@ const parseRows = (parsers, fields, rows) => {
4994
4682
  }
4995
4683
  };
4996
4684
  const parsePluck = (parsers, isSubQuery, rows) => {
4997
- const pluck = parsers == null ? void 0 : parsers.pluck;
4685
+ const pluck = parsers?.pluck;
4998
4686
  if (pluck) {
4999
4687
  for (let i = 0; i < rows.length; i++) {
5000
4688
  rows[i] = pluck(isSubQuery ? rows[i] : rows[i][0]);
@@ -5006,25 +4694,22 @@ const parsePluck = (parsers, isSubQuery, rows) => {
5006
4694
  }
5007
4695
  };
5008
4696
  const parseValue = (value, parsers) => {
5009
- const parser = parsers == null ? void 0 : parsers[getValueKey];
4697
+ const parser = parsers?.[getValueKey];
5010
4698
  return parser ? parser(value) : value;
5011
4699
  };
5012
4700
  const filterResult = (q, returnType, queryResult, result, tempColumns, hasAfterHook) => {
5013
- var _a;
5014
4701
  if (returnType === "all") {
5015
4702
  return filterAllResult(result, tempColumns, hasAfterHook);
5016
4703
  }
5017
4704
  if (returnType === "oneOrThrow" || returnType === "one") {
5018
4705
  let row = result[0];
5019
4706
  if (!row) {
5020
- if (returnType === "oneOrThrow")
5021
- throw new NotFoundError(q);
4707
+ if (returnType === "oneOrThrow") throw new NotFoundError(q);
5022
4708
  return void 0;
5023
- } else if (!(tempColumns == null ? void 0 : tempColumns.size)) {
4709
+ } else if (!tempColumns?.size) {
5024
4710
  return row;
5025
4711
  } else {
5026
- if (hasAfterHook)
5027
- row = __spreadValues$f({}, row);
4712
+ if (hasAfterHook) row = { ...row };
5028
4713
  for (const column of tempColumns) {
5029
4714
  delete row[column];
5030
4715
  }
@@ -5032,15 +4717,14 @@ const filterResult = (q, returnType, queryResult, result, tempColumns, hasAfterH
5032
4717
  }
5033
4718
  }
5034
4719
  if (returnType === "value") {
5035
- return (_a = result[0]) == null ? void 0 : _a[getFirstResultKey(q, queryResult)];
4720
+ return result[0]?.[getFirstResultKey(q, queryResult)];
5036
4721
  }
5037
4722
  if (returnType === "valueOrThrow") {
5038
4723
  if (q.q.returning) {
5039
4724
  return queryResult.rowCount;
5040
4725
  }
5041
4726
  const row = result[0];
5042
- if (!row)
5043
- throw new NotFoundError(q);
4727
+ if (!row) throw new NotFoundError(q);
5044
4728
  return row[getFirstResultKey(q, queryResult)];
5045
4729
  }
5046
4730
  if (returnType === "pluck") {
@@ -5064,10 +4748,10 @@ const getFirstResultKey = (q, queryResult) => {
5064
4748
  return;
5065
4749
  };
5066
4750
  const filterAllResult = (result, tempColumns, hasAfterHook) => {
5067
- if (tempColumns == null ? void 0 : tempColumns.size) {
4751
+ if (tempColumns?.size) {
5068
4752
  if (hasAfterHook) {
5069
4753
  return result.map((data) => {
5070
- const record = __spreadValues$f({}, data);
4754
+ const record = { ...data };
5071
4755
  for (const key of tempColumns) {
5072
4756
  delete record[key];
5073
4757
  }
@@ -5084,38 +4768,18 @@ const filterAllResult = (result, tempColumns, hasAfterHook) => {
5084
4768
  return result;
5085
4769
  };
5086
4770
 
5087
- var __defProp$e = Object.defineProperty;
5088
- var __defProps$5 = Object.defineProperties;
5089
- var __getOwnPropDescs$5 = Object.getOwnPropertyDescriptors;
5090
- var __getOwnPropSymbols$f = Object.getOwnPropertySymbols;
5091
- var __hasOwnProp$f = Object.prototype.hasOwnProperty;
5092
- var __propIsEnum$f = Object.prototype.propertyIsEnumerable;
5093
- var __defNormalProp$e = (obj, key, value) => key in obj ? __defProp$e(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
5094
- var __spreadValues$e = (a, b) => {
5095
- for (var prop in b || (b = {}))
5096
- if (__hasOwnProp$f.call(b, prop))
5097
- __defNormalProp$e(a, prop, b[prop]);
5098
- if (__getOwnPropSymbols$f)
5099
- for (var prop of __getOwnPropSymbols$f(b)) {
5100
- if (__propIsEnum$f.call(b, prop))
5101
- __defNormalProp$e(a, prop, b[prop]);
5102
- }
5103
- return a;
5104
- };
5105
- var __spreadProps$5 = (a, b) => __defProps$5(a, __getOwnPropDescs$5(b));
5106
4771
  const addParserForRawExpression = (q, key, raw) => {
5107
- if (raw.result.value)
5108
- addColumnParserToQuery(q.q, key, raw.result.value);
4772
+ if (raw.result.value) addColumnParserToQuery(q.q, key, raw.result.value);
5109
4773
  };
5110
4774
  const addParsersForSelectJoined = (q, arg, as = arg) => {
5111
- var _a, _b, _c, _d;
5112
- const parsers = (_a = q.q.joinedParsers) == null ? void 0 : _a[arg];
4775
+ var _a;
4776
+ const parsers = q.q.joinedParsers?.[arg];
5113
4777
  if (parsers) {
5114
4778
  setParserToQuery(q.q, as, (row) => parseRecord(parsers, row));
5115
4779
  }
5116
- const batchParsers = (_b = q.q.joinedBatchParsers) == null ? void 0 : _b[arg];
4780
+ const batchParsers = q.q.joinedBatchParsers?.[arg];
5117
4781
  if (batchParsers) {
5118
- ((_d = (_c = q.q).batchParsers) != null ? _d : _c.batchParsers = []).push(
4782
+ ((_a = q.q).batchParsers ?? (_a.batchParsers = [])).push(
5119
4783
  ...batchParsers.map((x) => ({
5120
4784
  path: [as, ...x.path],
5121
4785
  fn: x.fn
@@ -5124,21 +4788,20 @@ const addParsersForSelectJoined = (q, arg, as = arg) => {
5124
4788
  }
5125
4789
  };
5126
4790
  const addParserForSelectItem = (q, as, key, arg, joinQuery) => {
5127
- var _a, _b, _c, _d, _e;
4791
+ var _a, _b;
5128
4792
  if (typeof arg === "object" || typeof arg === "function") {
5129
4793
  const { q: query } = arg;
5130
4794
  if (query.batchParsers) {
5131
- const batchParsers = (_b = (_a = q.q).batchParsers) != null ? _b : _a.batchParsers = [];
4795
+ const batchParsers = (_a = q.q).batchParsers ?? (_a.batchParsers = []);
5132
4796
  for (const bp of query.batchParsers) {
5133
4797
  batchParsers.push({ path: [key, ...bp.path], fn: bp.fn });
5134
4798
  }
5135
4799
  }
5136
4800
  if (query.hookSelect || query.parsers || query.transform) {
5137
- const batchParsers = (_d = (_c = q.q).batchParsers) != null ? _d : _c.batchParsers = [];
4801
+ const batchParsers = (_b = q.q).batchParsers ?? (_b.batchParsers = []);
5138
4802
  batchParsers.push({
5139
4803
  path: [key],
5140
4804
  fn: (path, queryResult) => {
5141
- var _a2, _b2, _c2;
5142
4805
  const { rows } = queryResult;
5143
4806
  const originalReturnType = query.returnType || "all";
5144
4807
  let returnType = originalReturnType;
@@ -5175,20 +4838,17 @@ const addParserForSelectItem = (q, as, key, arg, joinQuery) => {
5175
4838
  if (parsers) {
5176
4839
  if (returnType === "one") {
5177
4840
  for (const { data } of batches) {
5178
- if (data)
5179
- parseRecord(parsers, data);
4841
+ if (data) parseRecord(parsers, data);
5180
4842
  }
5181
4843
  } else {
5182
4844
  for (const { data } of batches) {
5183
- if (!data)
5184
- throw new NotFoundError(arg);
4845
+ if (!data) throw new NotFoundError(arg);
5185
4846
  parseRecord(parsers, data);
5186
4847
  }
5187
4848
  }
5188
4849
  } else if (returnType !== "one") {
5189
4850
  for (const { data } of batches) {
5190
- if (!data)
5191
- throw new NotFoundError(arg);
4851
+ if (!data) throw new NotFoundError(arg);
5192
4852
  }
5193
4853
  }
5194
4854
  if (hookSelect) {
@@ -5199,7 +4859,7 @@ const addParserForSelectItem = (q, as, key, arg, joinQuery) => {
5199
4859
  break;
5200
4860
  }
5201
4861
  case "pluck": {
5202
- const parse = (_a2 = query.parsers) == null ? void 0 : _a2.pluck;
4862
+ const parse = query.parsers?.pluck;
5203
4863
  if (parse) {
5204
4864
  for (const { data } of batches) {
5205
4865
  for (let i = 0; i < data.length; i++) {
@@ -5211,7 +4871,7 @@ const addParserForSelectItem = (q, as, key, arg, joinQuery) => {
5211
4871
  }
5212
4872
  case "value":
5213
4873
  case "valueOrThrow": {
5214
- const parse = (_b2 = query.parsers) == null ? void 0 : _b2[getValueKey];
4874
+ const parse = query.parsers?.[getValueKey];
5215
4875
  if (parse) {
5216
4876
  if (returnType === "value") {
5217
4877
  for (const item of batches) {
@@ -5226,8 +4886,7 @@ const addParserForSelectItem = (q, as, key, arg, joinQuery) => {
5226
4886
  }
5227
4887
  } else if (returnType !== "value") {
5228
4888
  for (const { data } of batches) {
5229
- if (data === void 0)
5230
- throw new NotFoundError(arg);
4889
+ if (data === void 0) throw new NotFoundError(arg);
5231
4890
  }
5232
4891
  }
5233
4892
  if (hookSelect) {
@@ -5243,9 +4902,8 @@ const addParserForSelectItem = (q, as, key, arg, joinQuery) => {
5243
4902
  let renames;
5244
4903
  for (const column of hookSelect.keys()) {
5245
4904
  const as2 = hookSelect.get(column).as;
5246
- if (as2)
5247
- (renames != null ? renames : renames = {})[column] = as2;
5248
- (_c2 = tempColumns != null ? tempColumns : tempColumns = /* @__PURE__ */ new Set()) == null ? void 0 : _c2.add(as2 || column);
4905
+ if (as2) (renames ?? (renames = {}))[column] = as2;
4906
+ (tempColumns ?? (tempColumns = /* @__PURE__ */ new Set()))?.add(as2 || column);
5249
4907
  }
5250
4908
  if (renames) {
5251
4909
  for (const { data } of batches) {
@@ -5270,8 +4928,7 @@ const addParserForSelectItem = (q, as, key, arg, joinQuery) => {
5270
4928
  renames,
5271
4929
  key
5272
4930
  );
5273
- if (maybePromise)
5274
- return maybePromise;
4931
+ if (maybePromise) return maybePromise;
5275
4932
  }
5276
4933
  finalizeNestedHookSelect(
5277
4934
  batches,
@@ -5286,7 +4943,7 @@ const addParserForSelectItem = (q, as, key, arg, joinQuery) => {
5286
4943
  }
5287
4944
  });
5288
4945
  }
5289
- if (!joinQuery && ((_e = arg.q) == null ? void 0 : _e.subQuery) && arg.q.expr) {
4946
+ if (!joinQuery && arg.q?.subQuery && arg.q.expr) {
5290
4947
  arg = arg.q.expr;
5291
4948
  }
5292
4949
  if (isExpression(arg)) {
@@ -5326,7 +4983,6 @@ const collectNestedSelectBatches = (batches, rows, path, last) => {
5326
4983
  };
5327
4984
  const emptyArrSQL = new RawSQL("'[]'");
5328
4985
  const processSelectArg = (q, as, arg, columnAs) => {
5329
- var _a;
5330
4986
  if (typeof arg === "string") {
5331
4987
  return setParserForSelectedString(q, arg, as, columnAs);
5332
4988
  }
@@ -5369,10 +5025,10 @@ const processSelectArg = (q, as, arg, columnAs) => {
5369
5025
  query = value;
5370
5026
  }
5371
5027
  }
5372
- const asOverride = (_a = value.q.aliases[key]) != null ? _a : key;
5028
+ const asOverride = value.q.aliases[key] ?? key;
5373
5029
  value.q.joinedForSelect = asOverride;
5374
5030
  if (asOverride !== key) {
5375
- aliases = __spreadProps$5(__spreadValues$e({}, q.q.aliases), { [key]: asOverride });
5031
+ aliases = { ...q.q.aliases, [key]: asOverride };
5376
5032
  }
5377
5033
  _joinLateral(
5378
5034
  q,
@@ -5383,8 +5039,7 @@ const processSelectArg = (q, as, arg, columnAs) => {
5383
5039
  );
5384
5040
  }
5385
5041
  }
5386
- if (aliases)
5387
- q.q.aliases = aliases;
5042
+ if (aliases) q.q.aliases = aliases;
5388
5043
  selectAs[key] = addParserForSelectItem(
5389
5044
  q,
5390
5045
  as,
@@ -5396,7 +5051,7 @@ const processSelectArg = (q, as, arg, columnAs) => {
5396
5051
  return { selectAs };
5397
5052
  };
5398
5053
  const setParserForSelectedString = (q, arg, as, columnAs) => {
5399
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
5054
+ var _a, _b;
5400
5055
  const index = arg.indexOf(".");
5401
5056
  if (index !== -1) {
5402
5057
  const table = arg.slice(0, index);
@@ -5406,55 +5061,53 @@ const setParserForSelectedString = (q, arg, as, columnAs) => {
5406
5061
  return table === as ? column : arg;
5407
5062
  } else if (table === as) {
5408
5063
  if (columnAs) {
5409
- const parser = (_a = q.q.parsers) == null ? void 0 : _a[column];
5410
- if (parser)
5411
- q.q.parsers[columnAs] = parser;
5064
+ const parser = q.q.parsers?.[column];
5065
+ if (parser) q.q.parsers[columnAs] = parser;
5412
5066
  }
5413
5067
  return handleComputed(q, q.q.computeds, column);
5414
5068
  } else {
5415
- const parser = (_c = (_b = q.q.joinedParsers) == null ? void 0 : _b[table]) == null ? void 0 : _c[column];
5416
- if (parser)
5417
- setParserToQuery(q.q, columnAs || column, parser);
5418
- const batchParsers = (_d = q.q.joinedBatchParsers) == null ? void 0 : _d[table];
5069
+ const parser = q.q.joinedParsers?.[table]?.[column];
5070
+ if (parser) setParserToQuery(q.q, columnAs || column, parser);
5071
+ const batchParsers = q.q.joinedBatchParsers?.[table];
5419
5072
  if (batchParsers) {
5420
5073
  for (const bp of batchParsers) {
5421
5074
  if (bp.path[0] === column) {
5422
- ((_f = (_e = q.q).batchParsers) != null ? _f : _e.batchParsers = []).push(bp);
5075
+ ((_a = q.q).batchParsers ?? (_a.batchParsers = [])).push(bp);
5423
5076
  }
5424
5077
  }
5425
5078
  }
5426
- const computeds = (_g = q.q.joinedComputeds) == null ? void 0 : _g[table];
5427
- if (computeds == null ? void 0 : computeds[column]) {
5079
+ const computeds = q.q.joinedComputeds?.[table];
5080
+ if (computeds?.[column]) {
5428
5081
  const computed = computeds[column];
5429
- const map = (_i = (_h = q.q).hookSelect) != null ? _i : _h.hookSelect = /* @__PURE__ */ new Map();
5082
+ const map = (_b = q.q).hookSelect ?? (_b.hookSelect = /* @__PURE__ */ new Map());
5430
5083
  for (const column2 of computed.deps) {
5431
5084
  map.set(column2, { select: `${table}.${column2}` });
5432
5085
  }
5433
- q.q.selectedComputeds = __spreadProps$5(__spreadValues$e({}, q.q.selectedComputeds), {
5086
+ q.q.selectedComputeds = {
5087
+ ...q.q.selectedComputeds,
5434
5088
  [column]: computed
5435
- });
5089
+ };
5436
5090
  return;
5437
5091
  }
5438
5092
  return arg;
5439
5093
  }
5440
5094
  } else {
5441
5095
  if (columnAs) {
5442
- const parser = (_j = q.q.parsers) == null ? void 0 : _j[arg];
5443
- if (parser)
5444
- q.q.parsers[columnAs] = parser;
5096
+ const parser = q.q.parsers?.[arg];
5097
+ if (parser) q.q.parsers[columnAs] = parser;
5445
5098
  }
5446
5099
  return handleComputed(q, q.q.computeds, arg);
5447
5100
  }
5448
5101
  };
5449
5102
  const handleComputed = (q, computeds, column) => {
5450
- var _a, _b;
5451
- if (computeds == null ? void 0 : computeds[column]) {
5103
+ var _a;
5104
+ if (computeds?.[column]) {
5452
5105
  const computed = computeds[column];
5453
- const map = (_b = (_a = q.q).hookSelect) != null ? _b : _a.hookSelect = /* @__PURE__ */ new Map();
5106
+ const map = (_a = q.q).hookSelect ?? (_a.hookSelect = /* @__PURE__ */ new Map());
5454
5107
  for (const column2 of computed.deps) {
5455
5108
  map.set(column2, { select: column2 });
5456
5109
  }
5457
- q.q.selectedComputeds = __spreadProps$5(__spreadValues$e({}, q.q.selectedComputeds), { [column]: computed });
5110
+ q.q.selectedComputeds = { ...q.q.selectedComputeds, [column]: computed };
5458
5111
  return;
5459
5112
  }
5460
5113
  return column;
@@ -5499,8 +5152,7 @@ const getShapeFromSelect = (q, isSubQuery) => {
5499
5152
  const { returnType } = it.q;
5500
5153
  if (returnType === "value" || returnType === "valueOrThrow") {
5501
5154
  const type = it.q.getColumn;
5502
- if (type)
5503
- result[key] = type;
5155
+ if (type) result[key] = type;
5504
5156
  } else {
5505
5157
  result[key] = new JSONTextColumn(defaultSchemaConfig);
5506
5158
  }
@@ -5512,7 +5164,6 @@ const getShapeFromSelect = (q, isSubQuery) => {
5512
5164
  return result;
5513
5165
  };
5514
5166
  const addColumnToShapeFromSelect = (q, arg, shape, query, result, isSubQuery, key) => {
5515
- var _a, _b;
5516
5167
  const index = arg.indexOf(".");
5517
5168
  if (index !== -1) {
5518
5169
  const table = arg.slice(0, index);
@@ -5520,9 +5171,8 @@ const addColumnToShapeFromSelect = (q, arg, shape, query, result, isSubQuery, ke
5520
5171
  if (table === (q.q.as || q.table)) {
5521
5172
  result[key || column] = shape[column];
5522
5173
  } else {
5523
- const it = (_b = (_a = query.joinedShapes) == null ? void 0 : _a[table]) == null ? void 0 : _b[column];
5524
- if (it)
5525
- result[key || column] = maybeUnNameColumn(it, isSubQuery);
5174
+ const it = query.joinedShapes?.[table]?.[column];
5175
+ if (it) result[key || column] = maybeUnNameColumn(it, isSubQuery);
5526
5176
  }
5527
5177
  } else if (arg === "*") {
5528
5178
  for (const key2 in shape) {
@@ -5533,10 +5183,10 @@ const addColumnToShapeFromSelect = (q, arg, shape, query, result, isSubQuery, ke
5533
5183
  }
5534
5184
  };
5535
5185
  const maybeUnNameColumn = (column, isSubQuery) => {
5536
- return isSubQuery && (column == null ? void 0 : column.data.name) ? setColumnData(column, "name", void 0) : column;
5186
+ return isSubQuery && column?.data.name ? setColumnData(column, "name", void 0) : column;
5537
5187
  };
5538
5188
  function _querySelect(q, args) {
5539
- var _a, _b;
5189
+ var _a;
5540
5190
  if (q.q.returning) {
5541
5191
  q.q.select = q.q.returning = void 0;
5542
5192
  }
@@ -5548,17 +5198,15 @@ function _querySelect(q, args) {
5548
5198
  }
5549
5199
  const len = args.length;
5550
5200
  if (!len) {
5551
- (_b = (_a = q.q).select) != null ? _b : _a.select = [];
5201
+ (_a = q.q).select ?? (_a.select = []);
5552
5202
  return q;
5553
5203
  }
5554
5204
  const as = q.q.as || q.table;
5555
5205
  const selectArgs = [];
5556
5206
  for (const arg of args) {
5557
5207
  const item = processSelectArg(q, as, arg);
5558
- if (item)
5559
- selectArgs.push(item);
5560
- else if (item === false)
5561
- return _queryNone(q);
5208
+ if (item) selectArgs.push(item);
5209
+ else if (item === false) return _queryNone(q);
5562
5210
  }
5563
5211
  return pushQueryArray(q, "select", selectArgs);
5564
5212
  }
@@ -5601,8 +5249,7 @@ class SelectItemExpression extends Expression {
5601
5249
  this.item = item;
5602
5250
  this.result = { value };
5603
5251
  this.q = query.q;
5604
- if (value)
5605
- Object.assign(this, value.operators);
5252
+ if (value) Object.assign(this, value.operators);
5606
5253
  }
5607
5254
  // `makeSQL` acts similarly to how select args are handled
5608
5255
  makeSQL(ctx, quotedAs) {
@@ -5611,7 +5258,6 @@ class SelectItemExpression extends Expression {
5611
5258
  }
5612
5259
 
5613
5260
  const _getSelectableColumn = (q, arg) => {
5614
- var _a, _b;
5615
5261
  let type = q.q.shape[arg];
5616
5262
  if (!type) {
5617
5263
  const index = arg.indexOf(".");
@@ -5621,7 +5267,7 @@ const _getSelectableColumn = (q, arg) => {
5621
5267
  if (table === (q.q.as || q.table)) {
5622
5268
  type = q.shape[column];
5623
5269
  } else {
5624
- type = (_b = (_a = q.q.joinedShapes) == null ? void 0 : _a[table]) == null ? void 0 : _b[column];
5270
+ type = q.q.joinedShapes?.[table]?.[column];
5625
5271
  }
5626
5272
  }
5627
5273
  }
@@ -5629,8 +5275,7 @@ const _getSelectableColumn = (q, arg) => {
5629
5275
  };
5630
5276
  const _get = (query, returnType, arg) => {
5631
5277
  const q = query.q;
5632
- if (q.returning)
5633
- q.returning = void 0;
5278
+ if (q.returning) q.returning = void 0;
5634
5279
  q.returnType = returnType;
5635
5280
  let type;
5636
5281
  if (typeof arg === "string") {
@@ -5651,7 +5296,7 @@ const _get = (query, returnType, arg) => {
5651
5296
  }
5652
5297
  return setQueryOperators(
5653
5298
  query,
5654
- (type == null ? void 0 : type.operators) || Operators.any
5299
+ type?.operators || Operators.any
5655
5300
  );
5656
5301
  };
5657
5302
  function _queryGet(self, arg) {
@@ -5661,36 +5306,17 @@ function _queryGetOptional(self, arg) {
5661
5306
  return _get(self, "value", arg);
5662
5307
  }
5663
5308
 
5664
- var __defProp$d = Object.defineProperty;
5665
- var __defProps$4 = Object.defineProperties;
5666
- var __getOwnPropDescs$4 = Object.getOwnPropertyDescriptors;
5667
- var __getOwnPropSymbols$e = Object.getOwnPropertySymbols;
5668
- var __hasOwnProp$e = Object.prototype.hasOwnProperty;
5669
- var __propIsEnum$e = Object.prototype.propertyIsEnumerable;
5670
- var __defNormalProp$d = (obj, key, value) => key in obj ? __defProp$d(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
5671
- var __spreadValues$d = (a, b) => {
5672
- for (var prop in b || (b = {}))
5673
- if (__hasOwnProp$e.call(b, prop))
5674
- __defNormalProp$d(a, prop, b[prop]);
5675
- if (__getOwnPropSymbols$e)
5676
- for (var prop of __getOwnPropSymbols$e(b)) {
5677
- if (__propIsEnum$e.call(b, prop))
5678
- __defNormalProp$d(a, prop, b[prop]);
5679
- }
5680
- return a;
5681
- };
5682
- var __spreadProps$4 = (a, b) => __defProps$4(a, __getOwnPropDescs$4(b));
5683
5309
  const _queryAs = (self, as) => {
5684
5310
  const { q } = self;
5685
5311
  q.as = as;
5686
- q.aliases = __spreadProps$4(__spreadValues$d({}, q.aliases), {
5312
+ q.aliases = {
5313
+ ...q.aliases,
5687
5314
  [as]: q.aliases ? _queryResolveAlias(q.aliases, as) : as
5688
- });
5315
+ };
5689
5316
  return self;
5690
5317
  };
5691
5318
  const _queryResolveAlias = (aliases, as) => {
5692
- if (!aliases[as])
5693
- return as;
5319
+ if (!aliases[as]) return as;
5694
5320
  let suffix = 2;
5695
5321
  let privateAs;
5696
5322
  while (aliases[privateAs = as + suffix]) {
@@ -5716,30 +5342,13 @@ class AsMethods {
5716
5342
  }
5717
5343
  }
5718
5344
 
5719
- var __defProp$c = Object.defineProperty;
5720
- var __getOwnPropSymbols$d = Object.getOwnPropertySymbols;
5721
- var __hasOwnProp$d = Object.prototype.hasOwnProperty;
5722
- var __propIsEnum$d = Object.prototype.propertyIsEnumerable;
5723
- var __defNormalProp$c = (obj, key, value) => key in obj ? __defProp$c(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
5724
- var __spreadValues$c = (a, b) => {
5725
- for (var prop in b || (b = {}))
5726
- if (__hasOwnProp$d.call(b, prop))
5727
- __defNormalProp$c(a, prop, b[prop]);
5728
- if (__getOwnPropSymbols$d)
5729
- for (var prop of __getOwnPropSymbols$d(b)) {
5730
- if (__propIsEnum$d.call(b, prop))
5731
- __defNormalProp$c(a, prop, b[prop]);
5732
- }
5733
- return a;
5734
- };
5735
5345
  function queryFrom(self, arg) {
5736
- var _a, _b, _c;
5737
5346
  const data = self.q;
5738
5347
  if (typeof arg === "string") {
5739
5348
  data.as || (data.as = arg);
5740
- const w = (_a = data.withShapes) == null ? void 0 : _a[arg];
5741
- data.shape = (_b = w == null ? void 0 : w.shape) != null ? _b : emptyObject;
5742
- data.computeds = w == null ? void 0 : w.computeds;
5349
+ const w = data.withShapes?.[arg];
5350
+ data.shape = w?.shape ?? emptyObject;
5351
+ data.computeds = w?.computeds;
5743
5352
  } else if (isExpression(arg)) {
5744
5353
  data.as || (data.as = "t");
5745
5354
  } else if (Array.isArray(arg)) {
@@ -5748,8 +5357,7 @@ function queryFrom(self, arg) {
5748
5357
  if (typeof item === "string") {
5749
5358
  const w = data.withShapes[item];
5750
5359
  Object.assign(shape, w.shape);
5751
- if (w.computeds)
5752
- data.computeds = __spreadValues$c(__spreadValues$c({}, data.computeds), w.computeds);
5360
+ if (w.computeds) data.computeds = { ...data.computeds, ...w.computeds };
5753
5361
  for (const key in w.shape) {
5754
5362
  addColumnParserToQuery(
5755
5363
  self,
@@ -5759,7 +5367,7 @@ function queryFrom(self, arg) {
5759
5367
  }
5760
5368
  } else if (!isExpression(item)) {
5761
5369
  Object.assign(shape, getShapeFromSelect(item, true));
5762
- Object.assign((_c = data.parsers) != null ? _c : data.parsers = {}, item.q.parsers);
5370
+ Object.assign(data.parsers ?? (data.parsers = {}), item.q.parsers);
5763
5371
  }
5764
5372
  }
5765
5373
  } else {
@@ -5875,11 +5483,9 @@ function queryJson(self, coalesce) {
5875
5483
 
5876
5484
  const pushSelectSql = (ctx, table, query, quotedAs) => {
5877
5485
  const sql = selectToSql(ctx, table, query, quotedAs);
5878
- if (sql)
5879
- ctx.sql.push(sql);
5486
+ if (sql) ctx.sql.push(sql);
5880
5487
  };
5881
5488
  const selectToSql = (ctx, table, query, quotedAs, hookSelect = query.hookSelect) => {
5882
- var _a, _b;
5883
5489
  let selected;
5884
5490
  const list = [];
5885
5491
  if (query.select) {
@@ -5888,7 +5494,7 @@ const selectToSql = (ctx, table, query, quotedAs, hookSelect = query.hookSelect)
5888
5494
  let sql;
5889
5495
  if (item === "*") {
5890
5496
  if (hookSelect) {
5891
- selected != null ? selected : selected = {};
5497
+ selected ?? (selected = {});
5892
5498
  for (const key in query.selectAllKeys || query.shape) {
5893
5499
  selected[key] = quotedAs;
5894
5500
  }
@@ -5899,8 +5505,7 @@ const selectToSql = (ctx, table, query, quotedAs, hookSelect = query.hookSelect)
5899
5505
  if (index !== -1) {
5900
5506
  const tableName = item.slice(0, index);
5901
5507
  const key = item.slice(index + 1);
5902
- if (hookSelect == null ? void 0 : hookSelect.get(key))
5903
- (selected != null ? selected : selected = {})[key] = `"${tableName}"`;
5508
+ if (hookSelect?.get(key)) (selected ?? (selected = {}))[key] = `"${tableName}"`;
5904
5509
  sql = tableColumnToSqlWithAs(
5905
5510
  ctx,
5906
5511
  table.q,
@@ -5908,12 +5513,9 @@ const selectToSql = (ctx, table, query, quotedAs, hookSelect = query.hookSelect)
5908
5513
  tableName,
5909
5514
  key,
5910
5515
  key === "*" ? tableName : key,
5911
- quotedAs,
5912
- true
5913
- );
5516
+ quotedAs);
5914
5517
  } else {
5915
- if (hookSelect == null ? void 0 : hookSelect.get(item))
5916
- (selected != null ? selected : selected = {})[item] = quotedAs;
5518
+ if (hookSelect?.get(item)) (selected ?? (selected = {}))[item] = quotedAs;
5917
5519
  sql = ownColumnToSqlWithAs(
5918
5520
  ctx,
5919
5521
  table.q,
@@ -5929,8 +5531,7 @@ const selectToSql = (ctx, table, query, quotedAs, hookSelect = query.hookSelect)
5929
5531
  if ("selectAs" in item) {
5930
5532
  const obj = item.selectAs;
5931
5533
  for (const as in obj) {
5932
- if (hookSelect)
5933
- (selected != null ? selected : selected = {})[as] = true;
5534
+ if (hookSelect) (selected ?? (selected = {}))[as] = true;
5934
5535
  const value = obj[as];
5935
5536
  if (typeof value === "object") {
5936
5537
  if (isExpression(value)) {
@@ -5970,26 +5571,25 @@ const selectToSql = (ctx, table, query, quotedAs, hookSelect = query.hookSelect)
5970
5571
  const tableName = select.slice(0, index);
5971
5572
  quotedTable = `"${tableName}"`;
5972
5573
  columnName = select.slice(index + 1);
5973
- col = (_b = (_a = table.q.joinedShapes) == null ? void 0 : _a[tableName]) == null ? void 0 : _b[columnName];
5974
- sql = (col == null ? void 0 : col.data.computed) ? col.data.computed.toSQL(ctx, `"${tableName}"`) : `"${tableName}"."${(col == null ? void 0 : col.data.name) || columnName}"`;
5574
+ col = table.q.joinedShapes?.[tableName]?.[columnName];
5575
+ sql = col?.data.computed ? col.data.computed.toSQL(ctx, `"${tableName}"`) : `"${tableName}"."${col?.data.name || columnName}"`;
5975
5576
  } else {
5976
5577
  quotedTable = quotedAs;
5977
5578
  columnName = select;
5978
5579
  col = query.shape[select];
5979
5580
  sql = simpleColumnToSQL(ctx, query, select, col, quotedAs);
5980
5581
  }
5981
- if (selected == null ? void 0 : selected[columnName]) {
5982
- if ((selected == null ? void 0 : selected[columnName]) === quotedTable) {
5582
+ if (selected?.[columnName]) {
5583
+ if (selected?.[columnName] === quotedTable) {
5983
5584
  hookSelect.delete(column);
5984
5585
  continue;
5985
5586
  }
5986
5587
  let i = 2;
5987
5588
  let name;
5988
- while (selected[name = `${column}${i}`])
5989
- i++;
5589
+ while (selected[name = `${column}${i}`]) i++;
5990
5590
  item.as = name;
5991
5591
  sql += ` "${name}"`;
5992
- } else if (col == null ? void 0 : col.data.name) {
5592
+ } else if (col?.data.name) {
5993
5593
  sql += ` "${columnName}"`;
5994
5594
  }
5995
5595
  list.push(sql);
@@ -6002,11 +5602,9 @@ function selectedObjectToSQL(ctx, quotedAs, item) {
6002
5602
  return ctx.aliasValue ? `${sql} r` : sql;
6003
5603
  }
6004
5604
  const selectAllSql = (query, quotedAs) => {
6005
- var _a, _b, _c;
6006
- return ((_a = query.join) == null ? void 0 : _a.length) ? ((_b = query.selectAllColumns) == null ? void 0 : _b.map((item) => `${quotedAs}.${item}`).join(", ")) || `${quotedAs}.*` : ((_c = query.selectAllColumns) == null ? void 0 : _c.join(", ")) || "*";
5605
+ return query.join?.length ? query.selectAllColumns?.map((item) => `${quotedAs}.${item}`).join(", ") || `${quotedAs}.*` : query.selectAllColumns?.join(", ") || "*";
6007
5606
  };
6008
5607
  const pushSubQuerySql = (ctx, query, as, list, quotedAs) => {
6009
- var _a, _b, _c;
6010
5608
  const { returnType = "all" } = query.q;
6011
5609
  if (isQueryNone(query)) {
6012
5610
  let sql;
@@ -6017,7 +5615,7 @@ const pushSubQuerySql = (ctx, query, as, list, quotedAs) => {
6017
5615
  return;
6018
5616
  case "value":
6019
5617
  case "valueOrThrow":
6020
- if (query.q.returning || ((_a = query.q.expr) == null ? void 0 : _a.result.value) instanceof IntegerBaseColumn) {
5618
+ if (query.q.returning || query.q.expr?.result.value instanceof IntegerBaseColumn) {
6021
5619
  sql = "0";
6022
5620
  } else {
6023
5621
  return;
@@ -6048,8 +5646,7 @@ const pushSubQuerySql = (ctx, query, as, list, quotedAs) => {
6048
5646
  sql = `"${query.q.joinedForSelect}".r`;
6049
5647
  break;
6050
5648
  case "valueOrThrow":
6051
- if (query.q.returning)
6052
- return;
5649
+ if (query.q.returning) return;
6053
5650
  sql = `"${query.q.joinedForSelect}".r`;
6054
5651
  break;
6055
5652
  case "void":
@@ -6057,8 +5654,7 @@ const pushSubQuerySql = (ctx, query, as, list, quotedAs) => {
6057
5654
  default:
6058
5655
  throw new UnhandledTypeError(query, returnType);
6059
5656
  }
6060
- if (sql)
6061
- list.push(`${coalesce(ctx, query, sql, quotedAs)} "${as}"`);
5657
+ if (sql) list.push(`${coalesce(ctx, query, sql, quotedAs)} "${as}"`);
6062
5658
  return;
6063
5659
  }
6064
5660
  switch (returnType) {
@@ -6069,8 +5665,8 @@ const pushSubQuerySql = (ctx, query, as, list, quotedAs) => {
6069
5665
  break;
6070
5666
  case "pluck": {
6071
5667
  const { select } = query.q;
6072
- const first = select == null ? void 0 : select[0];
6073
- if (!first && ((_b = query.q.computeds) == null ? void 0 : _b[as])) {
5668
+ const first = select?.[0];
5669
+ if (!first && query.q.computeds?.[as]) {
6074
5670
  query = queryJson(query);
6075
5671
  } else if (!first) {
6076
5672
  throw new OrchidOrmInternalError(
@@ -6087,7 +5683,7 @@ const pushSubQuerySql = (ctx, query, as, list, quotedAs) => {
6087
5683
  }
6088
5684
  case "value":
6089
5685
  case "valueOrThrow":
6090
- if (!query.q.returning && ((_c = query.q.computeds) == null ? void 0 : _c[as])) {
5686
+ if (!query.q.returning && query.q.computeds?.[as]) {
6091
5687
  query = queryJson(query);
6092
5688
  }
6093
5689
  break;
@@ -6135,8 +5731,7 @@ const orderByToSql = (ctx, data, order, quotedAs) => {
6135
5731
  return sql.join(", ");
6136
5732
  };
6137
5733
  const addOrder = (ctx, data, column, quotedAs, dir) => {
6138
- var _a;
6139
- if ((_a = data.sources) == null ? void 0 : _a[column]) {
5734
+ if (data.sources?.[column]) {
6140
5735
  const search = data.sources[column];
6141
5736
  const order = dir || (!search.order || search.order === true ? emptyObject : search.order);
6142
5737
  return `${order.coverDensity ? "ts_rank_cd" : "ts_rank"}(${order.weights ? `${addValue(ctx.values, `{${order.weights}}`)}, ` : ""}${search.vectorSQL}, "${column}"${order.normalization !== void 0 ? `, ${addValue(ctx.values, order.normalization)}` : ""}) ${order.dir || "DESC"}`;
@@ -6145,10 +5740,8 @@ const addOrder = (ctx, data, column, quotedAs, dir) => {
6145
5740
  };
6146
5741
 
6147
5742
  const windowToSql = (ctx, data, window, quotedAs) => {
6148
- if (typeof window === "string")
6149
- return `"${window}"`;
6150
- if (isExpression(window))
6151
- return `(${window.toSQL(ctx, quotedAs)})`;
5743
+ if (typeof window === "string") return `"${window}"`;
5744
+ if (isExpression(window)) return `(${window.toSQL(ctx, quotedAs)})`;
6152
5745
  const sql = [];
6153
5746
  if (window.partitionBy) {
6154
5747
  sql.push(
@@ -6165,38 +5758,33 @@ const windowToSql = (ctx, data, window, quotedAs) => {
6165
5758
 
6166
5759
  const pushHavingSql = (ctx, query, quotedAs) => {
6167
5760
  const conditions = havingToSql(ctx, query, quotedAs);
6168
- if (conditions == null ? void 0 : conditions.length)
6169
- ctx.sql.push("HAVING", conditions);
5761
+ if (conditions?.length) ctx.sql.push("HAVING", conditions);
6170
5762
  };
6171
5763
  const havingToSql = (ctx, query, quotedAs) => {
6172
- var _a;
6173
- return (_a = query.having) == null ? void 0 : _a.map(
5764
+ return query.having?.map(
6174
5765
  (it) => "raw" in it[0] ? templateLiteralToSQL(it, ctx, quotedAs) : it.map((item) => item.toSQL(ctx, quotedAs)).join(" AND ")
6175
5766
  ).join(" AND ");
6176
5767
  };
6177
5768
 
6178
5769
  const pushWithSql = (ctx, items) => {
6179
- if (!items.length)
6180
- return;
5770
+ if (!items.length) return;
6181
5771
  ctx.sql.push(
6182
5772
  "WITH",
6183
5773
  items.map((item) => {
6184
- var _a;
6185
5774
  let inner;
6186
5775
  if (item.q) {
6187
5776
  inner = getSqlText(makeSQL(item.q, ctx));
6188
5777
  } else {
6189
5778
  inner = item.s.toSQL(ctx, `"${item.n}"`);
6190
5779
  }
6191
- const o = (_a = item.o) != null ? _a : emptyObject;
5780
+ const o = item.o ?? emptyObject;
6192
5781
  return `${o.recursive ? "RECURSIVE " : ""}"${item.n}"${o.columns ? `(${o.columns.map((x) => `"${x}"`).join(", ")})` : ""} AS ${o.materialized ? "MATERIALIZED " : o.notMaterialized ? "NOT MATERIALIZED " : ""}(${inner})`;
6193
5782
  }).join(", ")
6194
5783
  );
6195
5784
  };
6196
5785
 
6197
5786
  const checkIfASimpleQuery = (q) => {
6198
- var _a, _b;
6199
- if (q.q.returnType && q.q.returnType !== "all" || q.q.selectAllColumns || ((_a = q.q.and) == null ? void 0 : _a.length) || ((_b = q.q.or) == null ? void 0 : _b.length) || q.q.scopes)
5787
+ if (q.q.returnType && q.q.returnType !== "all" || q.q.selectAllColumns || q.q.and?.length || q.q.or?.length || q.q.scopes)
6200
5788
  return false;
6201
5789
  const keys = Object.keys(q.q);
6202
5790
  return !keys.some((key) => queryKeysOfNotSimpleQuery.includes(key));
@@ -6265,8 +5853,7 @@ const getFrom = (ctx, table, data, quotedAs) => {
6265
5853
  return fromToSql(ctx, data, from, quotedAs);
6266
5854
  }
6267
5855
  let sql = quoteSchemaAndTable(data.schema, table.table);
6268
- if (data.only)
6269
- sql = `ONLY ${sql}`;
5856
+ if (data.only) sql = `ONLY ${sql}`;
6270
5857
  return sql;
6271
5858
  };
6272
5859
  const fromToSql = (ctx, data, from, quotedAs) => {
@@ -6291,13 +5878,11 @@ const fromToSql = (ctx, data, from, quotedAs) => {
6291
5878
  return (only === void 0 ? data.only : only) ? `ONLY ${sql}` : sql;
6292
5879
  };
6293
5880
  const getSearchLang = (ctx, data, source, quotedAs) => {
6294
- var _a;
6295
- return (_a = source.langSQL) != null ? _a : source.langSQL = "languageColumn" in source ? columnToSql(ctx, data, data.shape, source.languageColumn, quotedAs) : isRawSQL(source.language) ? source.language.toSQL(ctx) : addValue(ctx.values, source.language || data.language || "english");
5881
+ return source.langSQL ?? (source.langSQL = "languageColumn" in source ? columnToSql(ctx, data, data.shape, source.languageColumn, quotedAs) : isRawSQL(source.language) ? source.language.toSQL(ctx) : addValue(ctx.values, source.language || data.language || "english"));
6296
5882
  };
6297
5883
  const getSearchText = (ctx, data, source, quotedAs, forHeadline) => {
6298
5884
  let sql = source.textSQL;
6299
- if (sql)
6300
- return sql;
5885
+ if (sql) return sql;
6301
5886
  if ("in" in source) {
6302
5887
  if (typeof source.in === "string") {
6303
5888
  sql = columnToSql(ctx, data, data.shape, source.in, quotedAs);
@@ -6352,11 +5937,10 @@ const MAX_BINDING_PARAMS = 65536;
6352
5937
 
6353
5938
  const quotedColumns = [];
6354
5939
  const makeInsertSql = (ctx, q, query, quotedAs) => {
6355
- var _a, _b, _c, _d;
6356
5940
  const { columns, shape } = query;
6357
5941
  quotedColumns.length = columns.length;
6358
5942
  for (let i = 0, len = columns.length; i < len; i++) {
6359
- quotedColumns[i] = `"${((_a = shape[columns[i]]) == null ? void 0 : _a.data.name) || columns[i]}"`;
5943
+ quotedColumns[i] = `"${shape[columns[i]]?.data.name || columns[i]}"`;
6360
5944
  }
6361
5945
  let runtimeDefaults;
6362
5946
  if (q.internal.runtimeDefaultColumns) {
@@ -6373,7 +5957,7 @@ const makeInsertSql = (ctx, q, query, quotedAs) => {
6373
5957
  if (quotedColumns.length === 0) {
6374
5958
  const key = Object.keys(q.shape)[0];
6375
5959
  const column = q.shape[key];
6376
- quotedColumns[0] = `"${(column == null ? void 0 : column.data.name) || key}"`;
5960
+ quotedColumns[0] = `"${column?.data.name || key}"`;
6377
5961
  if (Array.isArray(values) && Array.isArray(values[0])) {
6378
5962
  values = values.map(() => [void 0]);
6379
5963
  }
@@ -6388,14 +5972,11 @@ const makeInsertSql = (ctx, q, query, quotedAs) => {
6388
5972
  const { target } = query.onConflict;
6389
5973
  if (target) {
6390
5974
  if (typeof target === "string") {
6391
- ctx.sql.push(`("${((_b = shape[target]) == null ? void 0 : _b.data.name) || target}")`);
5975
+ ctx.sql.push(`("${shape[target]?.data.name || target}")`);
6392
5976
  } else if (Array.isArray(target)) {
6393
5977
  ctx.sql.push(
6394
5978
  `(${target.reduce(
6395
- (sql, item, i) => {
6396
- var _a2;
6397
- return sql + (i ? ", " : "") + `"${((_a2 = shape[item]) == null ? void 0 : _a2.data.name) || item}"`;
6398
- },
5979
+ (sql, item, i) => sql + (i ? ", " : "") + `"${shape[item]?.data.name || item}"`,
6399
5980
  ""
6400
5981
  )})`
6401
5982
  );
@@ -6410,14 +5991,13 @@ const makeInsertSql = (ctx, q, query, quotedAs) => {
6410
5991
  const { merge } = query.onConflict;
6411
5992
  if (merge) {
6412
5993
  if (typeof merge === "string") {
6413
- const name = ((_c = shape[merge]) == null ? void 0 : _c.data.name) || merge;
5994
+ const name = shape[merge]?.data.name || merge;
6414
5995
  sql = `DO UPDATE SET "${name}" = excluded."${name}"`;
6415
5996
  } else if ("except" in merge) {
6416
5997
  sql = mergeColumnsSql(columns, quotedColumns, target, merge.except);
6417
5998
  } else {
6418
5999
  sql = `DO UPDATE SET ${merge.reduce((sql2, item, i) => {
6419
- var _a2;
6420
- const name = ((_a2 = shape[item]) == null ? void 0 : _a2.data.name) || item;
6000
+ const name = shape[item]?.data.name || item;
6421
6001
  return sql2 + (i ? ", " : "") + `"${name}" = excluded."${name}"`;
6422
6002
  }, "")}`;
6423
6003
  }
@@ -6434,7 +6014,7 @@ const makeInsertSql = (ctx, q, query, quotedAs) => {
6434
6014
  const arr = [];
6435
6015
  for (const key in set) {
6436
6016
  arr.push(
6437
- `"${((_d = shape[key]) == null ? void 0 : _d.data.name) || key}" = ${addValue(
6017
+ `"${shape[key]?.data.name || key}" = ${addValue(
6438
6018
  ctx.values,
6439
6019
  set[key]
6440
6020
  )}`
@@ -6591,8 +6171,7 @@ const encodeRow = (ctx, values, q, QueryClass, row, runtimeDefaults, quotedAs) =
6591
6171
  };
6592
6172
  const pushReturningSql = (ctx, q, data, quotedAs, hookSelect, keyword = "RETURNING") => {
6593
6173
  const { select } = data;
6594
- if (!(hookSelect == null ? void 0 : hookSelect.size) && !select)
6595
- return hookSelect && /* @__PURE__ */ new Map();
6174
+ if (!hookSelect?.size && !select) return hookSelect && /* @__PURE__ */ new Map();
6596
6175
  ctx.sql.push(keyword);
6597
6176
  if (q.q.hookSelect || hookSelect) {
6598
6177
  const tempSelect = new Map(q.q.hookSelect);
@@ -6645,16 +6224,14 @@ const processData = (ctx, table, set, data, quotedAs) => {
6645
6224
  for (const item of data) {
6646
6225
  if (typeof item === "function") {
6647
6226
  const result = item(data);
6648
- if (result)
6649
- append = pushOrNewArray(append, result);
6227
+ if (result) append = pushOrNewArray(append, result);
6650
6228
  } else if (isExpression(item)) {
6651
6229
  set.push(item.toSQL(ctx, quotedAs));
6652
6230
  } else {
6653
6231
  const shape = table.q.shape;
6654
6232
  for (const key in item) {
6655
6233
  const value = item[key];
6656
- if (value === void 0)
6657
- continue;
6234
+ if (value === void 0) continue;
6658
6235
  set.push(
6659
6236
  `"${shape[key].data.name || key}" = ${processValue(
6660
6237
  ctx,
@@ -6668,8 +6245,7 @@ const processData = (ctx, table, set, data, quotedAs) => {
6668
6245
  }
6669
6246
  }
6670
6247
  }
6671
- if (append)
6672
- processData(ctx, table, set, append, quotedAs);
6248
+ if (append) processData(ctx, table, set, append, quotedAs);
6673
6249
  };
6674
6250
  const processValue = (ctx, table, QueryClass, key, value, quotedAs) => {
6675
6251
  if (value && typeof value === "object") {
@@ -6690,14 +6266,13 @@ const processValue = (ctx, table, QueryClass, key, value, quotedAs) => {
6690
6266
  };
6691
6267
 
6692
6268
  const pushDeleteSql = (ctx, table, query, quotedAs) => {
6693
- var _a, _b, _c;
6694
6269
  const from = `"${table.table}"`;
6695
6270
  ctx.sql.push(`DELETE FROM ${from}`);
6696
6271
  if (from !== quotedAs) {
6697
6272
  ctx.sql.push(`AS ${quotedAs}`);
6698
6273
  }
6699
6274
  let conditions;
6700
- if ((_a = query.join) == null ? void 0 : _a.length) {
6275
+ if (query.join?.length) {
6701
6276
  const targets = [];
6702
6277
  const ons = [];
6703
6278
  const joinSet = query.join.length > 1 ? /* @__PURE__ */ new Set() : null;
@@ -6705,13 +6280,11 @@ const pushDeleteSql = (ctx, table, query, quotedAs) => {
6705
6280
  const join = processJoinItem(ctx, table, query, item.args, quotedAs);
6706
6281
  const key = `${join.target}${join.on}`;
6707
6282
  if (joinSet) {
6708
- if (joinSet.has(key))
6709
- continue;
6283
+ if (joinSet.has(key)) continue;
6710
6284
  joinSet.add(key);
6711
6285
  }
6712
6286
  targets.push(join.target);
6713
- if (join.on)
6714
- ons.push(join.on);
6287
+ if (join.on) ons.push(join.on);
6715
6288
  }
6716
6289
  if (targets.length) {
6717
6290
  ctx.sql.push(`USING ${targets.join(", ")}`);
@@ -6720,7 +6293,7 @@ const pushDeleteSql = (ctx, table, query, quotedAs) => {
6720
6293
  }
6721
6294
  pushWhereStatementSql(ctx, table, query, quotedAs);
6722
6295
  if (conditions) {
6723
- if (((_b = query.and) == null ? void 0 : _b.length) || ((_c = query.or) == null ? void 0 : _c.length) || query.scopes) {
6296
+ if (query.and?.length || query.or?.length || query.scopes) {
6724
6297
  ctx.sql.push("AND", conditions);
6725
6298
  } else {
6726
6299
  ctx.sql.push("WHERE", conditions);
@@ -6731,14 +6304,11 @@ const pushDeleteSql = (ctx, table, query, quotedAs) => {
6731
6304
 
6732
6305
  const pushTruncateSql = (ctx, table, query) => {
6733
6306
  ctx.sql.push("TRUNCATE", quoteSchemaAndTable(query.schema, table));
6734
- if (query.restartIdentity)
6735
- ctx.sql.push("RESTART IDENTITY");
6736
- if (query.cascade)
6737
- ctx.sql.push("CASCADE");
6307
+ if (query.restartIdentity) ctx.sql.push("RESTART IDENTITY");
6308
+ if (query.cascade) ctx.sql.push("CASCADE");
6738
6309
  };
6739
6310
 
6740
6311
  const pushColumnInfoSql = (ctx, table, query) => {
6741
- var _a;
6742
6312
  ctx.sql.push(
6743
6313
  `SELECT * FROM information_schema.columns WHERE table_name = ${addValue(
6744
6314
  ctx.values,
@@ -6749,7 +6319,7 @@ const pushColumnInfoSql = (ctx, table, query) => {
6749
6319
  ctx.sql.push(
6750
6320
  `AND column_name = ${addValue(
6751
6321
  ctx.values,
6752
- ((_a = table.q.shape[query.column]) == null ? void 0 : _a.data.name) || query.column
6322
+ table.q.shape[query.column]?.data.name || query.column
6753
6323
  )}`
6754
6324
  );
6755
6325
  }
@@ -6758,30 +6328,21 @@ const pushColumnInfoSql = (ctx, table, query) => {
6758
6328
  const pushCopySql = (ctx, table, query, quotedAs) => {
6759
6329
  const { sql } = ctx;
6760
6330
  const { copy } = query;
6761
- const columns = copy.columns ? `(${copy.columns.map((item) => {
6762
- var _a;
6763
- return `"${((_a = query.shape[item]) == null ? void 0 : _a.data.name) || item}"`;
6764
- }).join(", ")})` : "";
6331
+ const columns = copy.columns ? `(${copy.columns.map((item) => `"${query.shape[item]?.data.name || item}"`).join(", ")})` : "";
6765
6332
  const target = "from" in copy ? copy.from : copy.to;
6766
6333
  sql.push(
6767
6334
  `COPY "${table.table}"${columns} ${"from" in copy ? "FROM" : "TO"} ${typeof target === "string" ? escapeString(target) : `PROGRAM ${escapeString(target.program)}`}`
6768
6335
  );
6769
6336
  if (Object.keys(copy).length > (copy.columns ? 2 : 1)) {
6770
6337
  const options = [];
6771
- if (copy.format)
6772
- options.push(`FORMAT ${copy.format}`);
6773
- if (copy.freeze)
6774
- options.push(`FREEZE ${copy.freeze}`);
6338
+ if (copy.format) options.push(`FORMAT ${copy.format}`);
6339
+ if (copy.freeze) options.push(`FREEZE ${copy.freeze}`);
6775
6340
  if (copy.delimiter)
6776
6341
  options.push(`DELIMITER ${escapeString(copy.delimiter)}`);
6777
- if (copy.null)
6778
- options.push(`NULL ${escapeString(copy.null)}`);
6779
- if (copy.header)
6780
- options.push(`HEADER ${copy.header}`);
6781
- if (copy.quote)
6782
- options.push(`QUOTE ${escapeString(copy.quote)}`);
6783
- if (copy.escape)
6784
- options.push(`ESCAPE ${escapeString(copy.escape)}`);
6342
+ if (copy.null) options.push(`NULL ${escapeString(copy.null)}`);
6343
+ if (copy.header) options.push(`HEADER ${copy.header}`);
6344
+ if (copy.quote) options.push(`QUOTE ${escapeString(copy.quote)}`);
6345
+ if (copy.escape) options.push(`ESCAPE ${escapeString(copy.escape)}`);
6785
6346
  if (copy.forceQuote)
6786
6347
  options.push(
6787
6348
  `FORCE_QUOTE ${copy.forceQuote === "*" ? "*" : `(${copy.forceQuote.map((x) => `"${x}"`).join(", ")})`}`
@@ -6794,8 +6355,7 @@ const pushCopySql = (ctx, table, query, quotedAs) => {
6794
6355
  options.push(
6795
6356
  `FORCE_NULL (${copy.forceNull.map((x) => `"${x}"`).join(", ")})`
6796
6357
  );
6797
- if (copy.encoding)
6798
- options.push(`ENCODING ${escapeString(copy.encoding)}`);
6358
+ if (copy.encoding) options.push(`ENCODING ${escapeString(copy.encoding)}`);
6799
6359
  sql.push(`WITH (${options.join(", ")})`);
6800
6360
  }
6801
6361
  pushWhereStatementSql(ctx, table, query, quotedAs);
@@ -6803,26 +6363,24 @@ const pushCopySql = (ctx, table, query, quotedAs) => {
6803
6363
 
6804
6364
  const toSQLCacheKey = Symbol("toSQLCache");
6805
6365
  const toSQL = (table, options) => {
6806
- return !(options == null ? void 0 : options.clearCache) && table.q[toSQLCacheKey] || (table.q[toSQLCacheKey] = makeSQL(table, options));
6366
+ return !options?.clearCache && table.q[toSQLCacheKey] || (table.q[toSQLCacheKey] = makeSQL(table, options));
6807
6367
  };
6808
6368
  const makeSQL = (table, options) => {
6809
- var _a;
6810
6369
  const query = table.q;
6811
6370
  const sql = [];
6812
- const values = (options == null ? void 0 : options.values) || [];
6371
+ const values = options?.values || [];
6813
6372
  const ctx = {
6814
6373
  queryBuilder: table.queryBuilder,
6815
6374
  sql,
6816
6375
  values,
6817
- aliasValue: options == null ? void 0 : options.aliasValue
6376
+ aliasValue: options?.aliasValue
6818
6377
  };
6819
6378
  if (query.with) {
6820
6379
  pushWithSql(ctx, query.with);
6821
6380
  }
6822
6381
  if (query.type) {
6823
- const tableName = (_a = table.table) != null ? _a : query.as;
6824
- if (!tableName)
6825
- throw new Error(`Table is missing for ${query.type}`);
6382
+ const tableName = table.table ?? query.as;
6383
+ if (!tableName) throw new Error(`Table is missing for ${query.type}`);
6826
6384
  if (query.type === "truncate") {
6827
6385
  pushTruncateSql(ctx, tableName, query);
6828
6386
  return { text: sql.join(" "), values };
@@ -6887,8 +6445,7 @@ const makeSQL = (table, options) => {
6887
6445
  );
6888
6446
  sql.push(`GROUP BY ${group.join(", ")}`);
6889
6447
  }
6890
- if (query.having)
6891
- pushHavingSql(ctx, query, quotedAs);
6448
+ if (query.having) pushHavingSql(ctx, query, quotedAs);
6892
6449
  if (query.window) {
6893
6450
  const window = [];
6894
6451
  query.window.forEach((item) => {
@@ -6917,8 +6474,7 @@ const makeSQL = (table, options) => {
6917
6474
  isExpression(tableNames) ? tableNames.toSQL(ctx, quotedAs) : tableNames.map((x) => `"${x}"`).join(", ")
6918
6475
  );
6919
6476
  }
6920
- if (query.for.mode)
6921
- sql.push(query.for.mode);
6477
+ if (query.for.mode) sql.push(query.for.mode);
6922
6478
  }
6923
6479
  return { text: sql.join(" "), values, hookSelect: query.hookSelect };
6924
6480
  };
@@ -6932,78 +6488,39 @@ function pushLimitSQL(sql, values, q) {
6932
6488
  }
6933
6489
  }
6934
6490
 
6935
- var __defProp$b = Object.defineProperty;
6936
- var __getOwnPropSymbols$c = Object.getOwnPropertySymbols;
6937
- var __hasOwnProp$c = Object.prototype.hasOwnProperty;
6938
- var __propIsEnum$c = Object.prototype.propertyIsEnumerable;
6939
- var __defNormalProp$b = (obj, key, value) => key in obj ? __defProp$b(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6940
- var __spreadValues$b = (a, b) => {
6941
- for (var prop in b || (b = {}))
6942
- if (__hasOwnProp$c.call(b, prop))
6943
- __defNormalProp$b(a, prop, b[prop]);
6944
- if (__getOwnPropSymbols$c)
6945
- for (var prop of __getOwnPropSymbols$c(b)) {
6946
- if (__propIsEnum$c.call(b, prop))
6947
- __defNormalProp$b(a, prop, b[prop]);
6948
- }
6949
- return a;
6950
- };
6951
6491
  const cloneQuery = (q) => {
6952
- if (q.with)
6953
- q.with = q.with.slice(0);
6954
- if (q.select)
6955
- q.select = q.select.slice(0);
6956
- if (q.hookSelect)
6957
- q.hookSelect = new Map(q.hookSelect);
6958
- if (q.and)
6959
- q.and = q.and.slice(0);
6960
- if (q.or)
6961
- q.or = q.or.slice(0);
6962
- if (q.before)
6963
- q.before = q.before.slice(0);
6964
- if (q.after)
6965
- q.after = q.after.slice(0);
6966
- if (q.joinedShapes)
6967
- q.joinedShapes = __spreadValues$b({}, q.joinedShapes);
6968
- if (q.joinedComputeds)
6969
- q.joinedComputeds = __spreadValues$b({}, q.joinedComputeds);
6970
- if (q.batchParsers)
6971
- q.batchParsers = [...q.batchParsers];
6972
- if (q.joinedBatchParsers)
6973
- q.joinedBatchParsers = __spreadValues$b({}, q.joinedBatchParsers);
6974
- if (q.scopes)
6975
- q.scopes = __spreadValues$b({}, q.scopes);
6976
- if (q.parsers)
6977
- q.parsers = __spreadValues$b({}, q.parsers);
6492
+ if (q.with) q.with = q.with.slice(0);
6493
+ if (q.select) q.select = q.select.slice(0);
6494
+ if (q.hookSelect) q.hookSelect = new Map(q.hookSelect);
6495
+ if (q.and) q.and = q.and.slice(0);
6496
+ if (q.or) q.or = q.or.slice(0);
6497
+ if (q.before) q.before = q.before.slice(0);
6498
+ if (q.after) q.after = q.after.slice(0);
6499
+ if (q.joinedShapes) q.joinedShapes = { ...q.joinedShapes };
6500
+ if (q.joinedComputeds) q.joinedComputeds = { ...q.joinedComputeds };
6501
+ if (q.batchParsers) q.batchParsers = [...q.batchParsers];
6502
+ if (q.joinedBatchParsers) q.joinedBatchParsers = { ...q.joinedBatchParsers };
6503
+ if (q.scopes) q.scopes = { ...q.scopes };
6504
+ if (q.parsers) q.parsers = { ...q.parsers };
6978
6505
  if (q.updateData) {
6979
6506
  q.updateData = q.updateData.slice(
6980
6507
  0
6981
6508
  );
6982
6509
  }
6983
6510
  if (q.type === void 0) {
6984
- if (q.distinct)
6985
- q.distinct = q.distinct.slice(0);
6986
- if (q.join)
6987
- q.join = q.join.slice(0);
6988
- if (q.group)
6989
- q.group = q.group.slice(0);
6990
- if (q.having)
6991
- q.having = q.having.slice(0);
6992
- if (q.window)
6993
- q.window = q.window.slice(0);
6994
- if (q.union)
6995
- q.union = { b: q.union.b, u: q.union.u.slice(0) };
6996
- if (q.order)
6997
- q.order = q.order.slice(0);
6511
+ if (q.distinct) q.distinct = q.distinct.slice(0);
6512
+ if (q.join) q.join = q.join.slice(0);
6513
+ if (q.group) q.group = q.group.slice(0);
6514
+ if (q.having) q.having = q.having.slice(0);
6515
+ if (q.window) q.window = q.window.slice(0);
6516
+ if (q.union) q.union = { b: q.union.b, u: q.union.u.slice(0) };
6517
+ if (q.order) q.order = q.order.slice(0);
6998
6518
  } else if (q.type === "insert") {
6999
6519
  q.columns = q.columns.slice(0);
7000
6520
  q.values = Array.isArray(q.values) ? q.values.slice(0) : q.values;
7001
- if (q.using)
7002
- q.using = q.using.slice(0);
7003
- if (q.join)
7004
- q.join = q.join.slice(0);
7005
- if (q.beforeCreate)
7006
- q.beforeCreate = q.beforeCreate.slice(0);
6521
+ if (q.using) q.using = q.using.slice(0);
6522
+ if (q.join) q.join = q.join.slice(0);
6523
+ if (q.beforeCreate) q.beforeCreate = q.beforeCreate.slice(0);
7007
6524
  if (q.afterCreate) {
7008
6525
  q.afterCreate = q.afterCreate.slice(0);
7009
6526
  if (q.afterCreateSelect) {
@@ -7011,8 +6528,7 @@ const cloneQuery = (q) => {
7011
6528
  }
7012
6529
  }
7013
6530
  } else if (q.type === "update") {
7014
- if (q.beforeUpdate)
7015
- q.beforeUpdate = q.beforeUpdate.slice(0);
6531
+ if (q.beforeUpdate) q.beforeUpdate = q.beforeUpdate.slice(0);
7016
6532
  if (q.afterUpdate) {
7017
6533
  q.afterUpdate = q.afterUpdate.slice(0);
7018
6534
  if (q.afterUpdateSelect) {
@@ -7020,8 +6536,7 @@ const cloneQuery = (q) => {
7020
6536
  }
7021
6537
  }
7022
6538
  } else if (q.type === "delete") {
7023
- if (q.beforeDelete)
7024
- q.beforeDelete = q.beforeDelete.slice(0);
6539
+ if (q.beforeDelete) q.beforeDelete = q.beforeDelete.slice(0);
7025
6540
  if (q.afterDelete) {
7026
6541
  q.afterDelete = q.afterDelete.slice(0);
7027
6542
  if (q.afterDeleteSelect) {
@@ -7031,27 +6546,7 @@ const cloneQuery = (q) => {
7031
6546
  }
7032
6547
  };
7033
6548
 
7034
- var __defProp$a = Object.defineProperty;
7035
- var __defProps$3 = Object.defineProperties;
7036
- var __getOwnPropDescs$3 = Object.getOwnPropertyDescriptors;
7037
- var __getOwnPropSymbols$b = Object.getOwnPropertySymbols;
7038
- var __hasOwnProp$b = Object.prototype.hasOwnProperty;
7039
- var __propIsEnum$b = Object.prototype.propertyIsEnumerable;
7040
- var __defNormalProp$a = (obj, key, value) => key in obj ? __defProp$a(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
7041
- var __spreadValues$a = (a, b) => {
7042
- for (var prop in b || (b = {}))
7043
- if (__hasOwnProp$b.call(b, prop))
7044
- __defNormalProp$a(a, prop, b[prop]);
7045
- if (__getOwnPropSymbols$b)
7046
- for (var prop of __getOwnPropSymbols$b(b)) {
7047
- if (__propIsEnum$b.call(b, prop))
7048
- __defNormalProp$a(a, prop, b[prop]);
7049
- }
7050
- return a;
7051
- };
7052
- var __spreadProps$3 = (a, b) => __defProps$3(a, __getOwnPropDescs$3(b));
7053
6549
  const _chain = (fromQuery, toQuery, rel) => {
7054
- var _a, _b;
7055
6550
  const self = fromQuery;
7056
6551
  const toTable = toQuery;
7057
6552
  let query;
@@ -7071,38 +6566,23 @@ const _chain = (fromQuery, toQuery, rel) => {
7071
6566
  } else {
7072
6567
  query.q.relChain = [self];
7073
6568
  }
7074
- const aliases = self.q.as ? __spreadValues$a({}, self.q.aliases) : __spreadProps$3(__spreadValues$a({}, self.q.aliases), { [self.table]: self.table });
6569
+ const aliases = self.q.as ? { ...self.q.aliases } : { ...self.q.aliases, [self.table]: self.table };
7075
6570
  const relAliases = query.q.aliases;
7076
6571
  for (const as in relAliases) {
7077
6572
  aliases[as] = _queryResolveAlias(aliases, as);
7078
6573
  }
7079
6574
  query.q.as = aliases[query.q.as];
7080
6575
  query.q.aliases = aliases;
7081
- query.q.joinedShapes = __spreadValues$a({
7082
- [getQueryAs(self)]: self.q.shape
7083
- }, self.q.joinedShapes);
7084
- (_b = (_a = rel.modifyRelatedQuery) == null ? void 0 : _a.call(rel, query)) == null ? void 0 : _b(self);
6576
+ query.q.joinedShapes = {
6577
+ [getQueryAs(self)]: self.q.shape,
6578
+ ...self.q.joinedShapes
6579
+ };
6580
+ rel.modifyRelatedQuery?.(query)?.(self);
7085
6581
  return query;
7086
6582
  };
7087
6583
 
7088
- var __defProp$9 = Object.defineProperty;
7089
- var __getOwnPropSymbols$a = Object.getOwnPropertySymbols;
7090
- var __hasOwnProp$a = Object.prototype.hasOwnProperty;
7091
- var __propIsEnum$a = Object.prototype.propertyIsEnumerable;
7092
- var __defNormalProp$9 = (obj, key, value) => key in obj ? __defProp$9(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
7093
- var __spreadValues$9 = (a, b) => {
7094
- for (var prop in b || (b = {}))
7095
- if (__hasOwnProp$a.call(b, prop))
7096
- __defNormalProp$9(a, prop, b[prop]);
7097
- if (__getOwnPropSymbols$a)
7098
- for (var prop of __getOwnPropSymbols$a(b)) {
7099
- if (__propIsEnum$a.call(b, prop))
7100
- __defNormalProp$9(a, prop, b[prop]);
7101
- }
7102
- return a;
7103
- };
7104
6584
  const getClonedQueryData = (query) => {
7105
- const cloned = __spreadValues$9({}, query);
6585
+ const cloned = { ...query };
7106
6586
  delete cloned[toSQLCacheKey];
7107
6587
  cloneQuery(cloned);
7108
6588
  return cloned;
@@ -7146,8 +6626,7 @@ const resolveSubQueryCallback = (q, cb) => {
7146
6626
  return result;
7147
6627
  };
7148
6628
  const joinSubQuery = (q, sub) => {
7149
- if (!("relationConfig" in sub))
7150
- return sub;
6629
+ if (!("relationConfig" in sub)) return sub;
7151
6630
  return sub.relationConfig.joinQuery(
7152
6631
  sub,
7153
6632
  q
@@ -7264,10 +6743,8 @@ const typmodType = (typmod) => {
7264
6743
  } else {
7265
6744
  s += lwtypeName(type);
7266
6745
  }
7267
- if (typmod >= 0 && typmodGetZ(typmod))
7268
- s += "Z";
7269
- if (typmod >= 0 && typmodGetM(typmod))
7270
- s += "M";
6746
+ if (typmod >= 0 && typmodGetZ(typmod)) s += "Z";
6747
+ if (typmod >= 0 && typmodGetM(typmod)) s += "M";
7271
6748
  return s;
7272
6749
  };
7273
6750
  const typmodSrid = (typmod) => {
@@ -7287,36 +6764,17 @@ function uint8ArrToHex(arr) {
7287
6764
  }
7288
6765
  }
7289
6766
  const hexOctets = [];
7290
- for (let i = 0; i < arr.length; ++i)
7291
- hexOctets.push(byteToHex[arr[i]]);
6767
+ for (let i = 0; i < arr.length; ++i) hexOctets.push(byteToHex[arr[i]]);
7292
6768
  return hexOctets.join("");
7293
6769
  }
7294
6770
 
7295
- var __defProp$8 = Object.defineProperty;
7296
- var __getOwnPropSymbols$9 = Object.getOwnPropertySymbols;
7297
- var __hasOwnProp$9 = Object.prototype.hasOwnProperty;
7298
- var __propIsEnum$9 = Object.prototype.propertyIsEnumerable;
7299
- var __defNormalProp$8 = (obj, key, value) => key in obj ? __defProp$8(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
7300
- var __spreadValues$8 = (a, b) => {
7301
- for (var prop in b || (b = {}))
7302
- if (__hasOwnProp$9.call(b, prop))
7303
- __defNormalProp$8(a, prop, b[prop]);
7304
- if (__getOwnPropSymbols$9)
7305
- for (var prop of __getOwnPropSymbols$9(b)) {
7306
- if (__propIsEnum$9.call(b, prop))
7307
- __defNormalProp$8(a, prop, b[prop]);
7308
- }
7309
- return a;
7310
- };
7311
6771
  const getColumnTypes = (types, fn, nowSQL, language) => {
7312
- if (nowSQL)
7313
- setDefaultNowFn(nowSQL);
7314
- if (language)
7315
- setDefaultLanguage(language);
6772
+ if (nowSQL) setDefaultNowFn(nowSQL);
6773
+ if (language) setDefaultLanguage(language);
7316
6774
  return fn(types);
7317
6775
  };
7318
6776
  const makeColumnTypes = (schema) => {
7319
- return __spreadValues$8({
6777
+ return {
7320
6778
  schema,
7321
6779
  enum: schema.enum,
7322
6780
  array: schema.array,
@@ -7425,8 +6883,9 @@ const makeColumnTypes = (schema) => {
7425
6883
  point() {
7426
6884
  return new PostgisGeographyPointColumn(schema);
7427
6885
  }
7428
- }
7429
- }, makeTimestampsHelpers(makeRegexToFindInSql));
6886
+ },
6887
+ ...makeTimestampsHelpers(makeRegexToFindInSql)
6888
+ };
7430
6889
  };
7431
6890
  RawSQL.prototype.columnTypes = makeColumnTypes;
7432
6891
 
@@ -7441,13 +6900,13 @@ class VirtualColumn extends ColumnType {
7441
6900
  }
7442
6901
  }
7443
6902
 
7444
- const _UnknownColumn = class extends VirtualColumn {
6903
+ const _UnknownColumn = class _UnknownColumn extends VirtualColumn {
7445
6904
  constructor(schema) {
7446
6905
  super(schema, schema.unknown());
7447
6906
  }
7448
6907
  };
6908
+ _UnknownColumn.instance = new _UnknownColumn(defaultSchemaConfig);
7449
6909
  let UnknownColumn = _UnknownColumn;
7450
- UnknownColumn.instance = new _UnknownColumn(defaultSchemaConfig);
7451
6910
  RawSQL.prototype.result = { value: UnknownColumn.instance };
7452
6911
 
7453
6912
  const makeColumnsByType = (schema) => {
@@ -7511,21 +6970,6 @@ const makeColumnsByType = (schema) => {
7511
6970
  };
7512
6971
  };
7513
6972
 
7514
- var __getOwnPropSymbols$8 = Object.getOwnPropertySymbols;
7515
- var __hasOwnProp$8 = Object.prototype.hasOwnProperty;
7516
- var __propIsEnum$8 = Object.prototype.propertyIsEnumerable;
7517
- var __objRest$1 = (source, exclude) => {
7518
- var target = {};
7519
- for (var prop in source)
7520
- if (__hasOwnProp$8.call(source, prop) && exclude.indexOf(prop) < 0)
7521
- target[prop] = source[prop];
7522
- if (source != null && __getOwnPropSymbols$8)
7523
- for (var prop of __getOwnPropSymbols$8(source)) {
7524
- if (exclude.indexOf(prop) < 0 && __propIsEnum$8.call(source, prop))
7525
- target[prop] = source[prop];
7526
- }
7527
- return target;
7528
- };
7529
6973
  const { types } = pg;
7530
6974
  const defaultTypeParsers = {};
7531
6975
  for (const key in types.builtins) {
@@ -7545,8 +6989,7 @@ const returnArg = (arg) => arg;
7545
6989
  const rollbackSql = { text: "ROLLBACK" };
7546
6990
  const commitSql = { text: "COMMIT" };
7547
6991
  class Adapter {
7548
- constructor(_a) {
7549
- var _b = _a, { types: types2 = defaultTypeParsers } = _b, config = __objRest$1(_b, ["types"]);
6992
+ constructor({ types: types2 = defaultTypeParsers, ...config }) {
7550
6993
  this.types = types2;
7551
6994
  let schema = config.schema;
7552
6995
  if (config.databaseURL) {
@@ -7563,8 +7006,7 @@ class Adapter {
7563
7006
  config.databaseURL = url.toString();
7564
7007
  config.connectionString = config.databaseURL;
7565
7008
  }
7566
- if (schema)
7567
- this.schema = schema === "public" ? void 0 : schema;
7009
+ if (schema) this.schema = schema === "public" ? void 0 : schema;
7568
7010
  this.config = config;
7569
7011
  this.pool = new pg.Pool(config);
7570
7012
  if (config.connectRetry) {
@@ -7671,25 +7113,6 @@ class TransactionAdapter {
7671
7113
  }
7672
7114
  }
7673
7115
 
7674
- var __defProp$7 = Object.defineProperty;
7675
- var __defProps$2 = Object.defineProperties;
7676
- var __getOwnPropDescs$2 = Object.getOwnPropertyDescriptors;
7677
- var __getOwnPropSymbols$7 = Object.getOwnPropertySymbols;
7678
- var __hasOwnProp$7 = Object.prototype.hasOwnProperty;
7679
- var __propIsEnum$7 = Object.prototype.propertyIsEnumerable;
7680
- var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
7681
- var __spreadValues$7 = (a, b) => {
7682
- for (var prop in b || (b = {}))
7683
- if (__hasOwnProp$7.call(b, prop))
7684
- __defNormalProp$7(a, prop, b[prop]);
7685
- if (__getOwnPropSymbols$7)
7686
- for (var prop of __getOwnPropSymbols$7(b)) {
7687
- if (__propIsEnum$7.call(b, prop))
7688
- __defNormalProp$7(a, prop, b[prop]);
7689
- }
7690
- return a;
7691
- };
7692
- var __spreadProps$2 = (a, b) => __defProps$2(a, __getOwnPropDescs$2(b));
7693
7116
  class FnExpression extends Expression {
7694
7117
  /**
7695
7118
  * @param query - query object.
@@ -7715,12 +7138,10 @@ class FnExpression extends Expression {
7715
7138
  }
7716
7139
  // Builds function SQL.
7717
7140
  makeSQL(ctx, quotedAs) {
7718
- var _a;
7719
7141
  const sql = [`${this.fn}(`];
7720
7142
  const { values } = ctx;
7721
7143
  const { options } = this;
7722
- if (options.distinct && !options.withinGroup)
7723
- sql.push("DISTINCT ");
7144
+ if (options.distinct && !options.withinGroup) sql.push("DISTINCT ");
7724
7145
  sql.push(
7725
7146
  this.args.map((arg) => {
7726
7147
  if (typeof arg === "string") {
@@ -7747,13 +7168,11 @@ class FnExpression extends Expression {
7747
7168
  }
7748
7169
  }).join(", ")
7749
7170
  );
7750
- if (options.withinGroup)
7751
- sql.push(") WITHIN GROUP (");
7752
- else if (options.order)
7753
- sql.push(" ");
7171
+ if (options.withinGroup) sql.push(") WITHIN GROUP (");
7172
+ else if (options.order) sql.push(" ");
7754
7173
  if (options.order) {
7755
7174
  pushOrderBySql(
7756
- __spreadProps$2(__spreadValues$7({}, ctx), { sql }),
7175
+ { ...ctx, sql },
7757
7176
  this.q,
7758
7177
  quotedAs,
7759
7178
  toArray(options.order)
@@ -7766,7 +7185,7 @@ class FnExpression extends Expression {
7766
7185
  this.query,
7767
7186
  {
7768
7187
  and: options.filter ? [options.filter] : void 0,
7769
- or: (_a = options.filterOr) == null ? void 0 : _a.map((item) => [item]),
7188
+ or: options.filterOr?.map((item) => [item]),
7770
7189
  shape: this.q.shape,
7771
7190
  joinedShapes: this.q.joinedShapes
7772
7191
  },
@@ -8399,22 +7818,6 @@ class Clear {
8399
7818
  }
8400
7819
  }
8401
7820
 
8402
- var __defProp$6 = Object.defineProperty;
8403
- var __getOwnPropSymbols$6 = Object.getOwnPropertySymbols;
8404
- var __hasOwnProp$6 = Object.prototype.hasOwnProperty;
8405
- var __propIsEnum$6 = Object.prototype.propertyIsEnumerable;
8406
- var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8407
- var __spreadValues$6 = (a, b) => {
8408
- for (var prop in b || (b = {}))
8409
- if (__hasOwnProp$6.call(b, prop))
8410
- __defNormalProp$6(a, prop, b[prop]);
8411
- if (__getOwnPropSymbols$6)
8412
- for (var prop of __getOwnPropSymbols$6(b)) {
8413
- if (__propIsEnum$6.call(b, prop))
8414
- __defNormalProp$6(a, prop, b[prop]);
8415
- }
8416
- return a;
8417
- };
8418
7821
  const createSelect = (q) => {
8419
7822
  if (q.q.returnType === "void" || isSelectingCount(q)) {
8420
7823
  q.q.select = void 0;
@@ -8424,12 +7827,10 @@ const createSelect = (q) => {
8424
7827
  }
8425
7828
  };
8426
7829
  const processCreateItem = (q, item, rowIndex, ctx, encoders) => {
8427
- var _a, _b, _c;
8428
7830
  const { shape } = q.q;
8429
7831
  for (const key in item) {
8430
7832
  if (shape[key] instanceof VirtualColumn) {
8431
- (_b = (_a = shape[key]).create) == null ? void 0 : _b.call(
8432
- _a,
7833
+ shape[key].create?.(
8433
7834
  q,
8434
7835
  ctx,
8435
7836
  item,
@@ -8444,7 +7845,7 @@ const processCreateItem = (q, item, rowIndex, ctx, encoders) => {
8444
7845
  }
8445
7846
  if (!ctx.columns.has(key) && (shape[key] && !shape[key].data.computed || shape === anyShape) && item[key] !== void 0) {
8446
7847
  ctx.columns.set(key, ctx.columns.size);
8447
- encoders[key] = (_c = shape[key]) == null ? void 0 : _c.data.encode;
7848
+ encoders[key] = shape[key]?.data.encode;
8448
7849
  }
8449
7850
  }
8450
7851
  }
@@ -8457,7 +7858,7 @@ const handleOneData = (q, data, ctx) => {
8457
7858
  const encoders = {};
8458
7859
  const defaults = q.q.defaults;
8459
7860
  if (defaults) {
8460
- data = __spreadValues$6(__spreadValues$6({}, defaults), data);
7861
+ data = { ...defaults, ...data };
8461
7862
  }
8462
7863
  processCreateItem(q, data, 0, ctx, encoders);
8463
7864
  const columns = Array.from(ctx.columns.keys());
@@ -8475,7 +7876,7 @@ const handleManyData = (q, data, ctx) => {
8475
7876
  const encoders = {};
8476
7877
  const defaults = q.q.defaults;
8477
7878
  if (defaults) {
8478
- data = data.map((item) => __spreadValues$6(__spreadValues$6({}, defaults), item));
7879
+ data = data.map((item) => ({ ...defaults, ...item }));
8479
7880
  }
8480
7881
  data.forEach((item, i) => {
8481
7882
  processCreateItem(q, item, i, ctx, encoders);
@@ -8493,9 +7894,8 @@ const insert = (self, {
8493
7894
  columns,
8494
7895
  values
8495
7896
  }, kind, many) => {
8496
- var _a;
8497
7897
  const { q } = self;
8498
- if (!((_a = q.select) == null ? void 0 : _a.length)) {
7898
+ if (!q.select?.length) {
8499
7899
  q.returning = true;
8500
7900
  }
8501
7901
  delete q.and;
@@ -8504,14 +7904,12 @@ const insert = (self, {
8504
7904
  q.type = "insert";
8505
7905
  q.columns = columns;
8506
7906
  q.values = values;
8507
- if (!q.kind)
8508
- q.kind = kind;
7907
+ if (!q.kind) q.kind = kind;
8509
7908
  const { select, returnType } = q;
8510
7909
  if (!select) {
8511
7910
  if (returnType !== "void") {
8512
7911
  q.returnType = "valueOrThrow";
8513
- if (many)
8514
- q.returningMany = true;
7912
+ if (many) q.returningMany = true;
8515
7913
  }
8516
7914
  } else if (many) {
8517
7915
  if (returnType === "one" || returnType === "oneOrThrow") {
@@ -8527,14 +7925,13 @@ const insert = (self, {
8527
7925
  return self;
8528
7926
  };
8529
7927
  const getFromSelectColumns = (from, obj, many) => {
8530
- var _a;
8531
7928
  if (!many && !queryTypeWithLimitOne[from.q.returnType]) {
8532
7929
  throw new Error(
8533
7930
  "Cannot create based on a query which returns multiple records"
8534
7931
  );
8535
7932
  }
8536
7933
  const queryColumns = [];
8537
- (_a = from.q.select) == null ? void 0 : _a.forEach((item) => {
7934
+ from.q.select?.forEach((item) => {
8538
7935
  if (typeof item === "string") {
8539
7936
  const index = item.indexOf(".");
8540
7937
  queryColumns.push(index === -1 ? item : item.slice(index + 1));
@@ -8542,7 +7939,7 @@ const getFromSelectColumns = (from, obj, many) => {
8542
7939
  queryColumns.push(...Object.keys(item.selectAs));
8543
7940
  }
8544
7941
  });
8545
- if (obj == null ? void 0 : obj.columns) {
7942
+ if (obj?.columns) {
8546
7943
  queryColumns.push(...obj.columns);
8547
7944
  }
8548
7945
  return queryColumns;
@@ -8555,7 +7952,7 @@ const insertFromQuery = (q, from, many, data) => {
8555
7952
  q,
8556
7953
  {
8557
7954
  columns,
8558
- values: { from, values: obj == null ? void 0 : obj.values }
7955
+ values: { from, values: obj?.values }
8559
7956
  },
8560
7957
  "from",
8561
7958
  many
@@ -8583,8 +7980,7 @@ const _queryCreateMany = (q, data) => {
8583
7980
  const _queryInsertMany = (q, data) => {
8584
7981
  const ctx = createCtx();
8585
7982
  let result = insert(q, handleManyData(q, data, ctx), "object", true);
8586
- if (!data.length)
8587
- result = result.none();
7983
+ if (!data.length) result = result.none();
8588
7984
  return result;
8589
7985
  };
8590
7986
  const _queryCreateRaw = (q, args) => {
@@ -9222,15 +8618,13 @@ const forMethods = {
9222
8618
  noWait() {
9223
8619
  const q = _clone(this);
9224
8620
  const data = q.q;
9225
- if (data == null ? void 0 : data.for)
9226
- data.for.mode = "NO WAIT";
8621
+ if (data?.for) data.for.mode = "NO WAIT";
9227
8622
  return q;
9228
8623
  },
9229
8624
  skipLocked() {
9230
8625
  const q = _clone(this);
9231
8626
  const data = q.q;
9232
- if (data == null ? void 0 : data.for)
9233
- data.for.mode = "SKIP LOCKED";
8627
+ if (data?.for) data.for.mode = "SKIP LOCKED";
9234
8628
  return q;
9235
8629
  }
9236
8630
  };
@@ -9372,9 +8766,9 @@ class Having {
9372
8766
 
9373
8767
  const before = (q, key, cb) => pushQueryValue(q, `before${key}`, cb);
9374
8768
  const after = (q, key, select, cb, commit) => {
9375
- var _a, _b, _c;
8769
+ var _a, _b;
9376
8770
  pushQueryValue(q, `after${key}${commit ? "Commit" : ""}`, cb);
9377
- const set = (_c = (_a = q.q)[_b = `after${key}Select`]) != null ? _c : _a[_b] = /* @__PURE__ */ new Set();
8771
+ const set = (_a = q.q)[_b = `after${key}Select`] ?? (_a[_b] = /* @__PURE__ */ new Set());
9378
8772
  for (const column of select) {
9379
8773
  set.add(column);
9380
8774
  }
@@ -10354,22 +9748,6 @@ class JsonMethods {
10354
9748
  }
10355
9749
  }
10356
9750
 
10357
- var __defProp$5 = Object.defineProperty;
10358
- var __getOwnPropSymbols$5 = Object.getOwnPropertySymbols;
10359
- var __hasOwnProp$5 = Object.prototype.hasOwnProperty;
10360
- var __propIsEnum$5 = Object.prototype.propertyIsEnumerable;
10361
- var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
10362
- var __spreadValues$5 = (a, b) => {
10363
- for (var prop in b || (b = {}))
10364
- if (__hasOwnProp$5.call(b, prop))
10365
- __defNormalProp$5(a, prop, b[prop]);
10366
- if (__getOwnPropSymbols$5)
10367
- for (var prop of __getOwnPropSymbols$5(b)) {
10368
- if (__propIsEnum$5.call(b, prop))
10369
- __defNormalProp$5(a, prop, b[prop]);
10370
- }
10371
- return a;
10372
- };
10373
9751
  const mergableObjects = /* @__PURE__ */ new Set([
10374
9752
  "shape",
10375
9753
  "withShapes",
@@ -10400,7 +9778,7 @@ class MergeQueryMethods {
10400
9778
  a[key] = a[key] ? [...a[key], ...value] : value;
10401
9779
  }
10402
9780
  } else if (mergableObjects.has(key)) {
10403
- a[key] = a[key] ? __spreadValues$5(__spreadValues$5({}, a[key]), value) : value;
9781
+ a[key] = a[key] ? { ...a[key], ...value } : value;
10404
9782
  } else if (key === "union") {
10405
9783
  a[key] = a[key] ? {
10406
9784
  b: a[key].b,
@@ -10414,8 +9792,7 @@ class MergeQueryMethods {
10414
9792
  break;
10415
9793
  }
10416
9794
  }
10417
- if (b.returnType)
10418
- a.returnType = b.returnType;
9795
+ if (b.returnType) a.returnType = b.returnType;
10419
9796
  return query;
10420
9797
  }
10421
9798
  }
@@ -10565,25 +9942,6 @@ class Union {
10565
9942
  }
10566
9943
  }
10567
9944
 
10568
- var __defProp$4 = Object.defineProperty;
10569
- var __defProps$1 = Object.defineProperties;
10570
- var __getOwnPropDescs$1 = Object.getOwnPropertyDescriptors;
10571
- var __getOwnPropSymbols$4 = Object.getOwnPropertySymbols;
10572
- var __hasOwnProp$4 = Object.prototype.hasOwnProperty;
10573
- var __propIsEnum$4 = Object.prototype.propertyIsEnumerable;
10574
- var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
10575
- var __spreadValues$4 = (a, b) => {
10576
- for (var prop in b || (b = {}))
10577
- if (__hasOwnProp$4.call(b, prop))
10578
- __defNormalProp$4(a, prop, b[prop]);
10579
- if (__getOwnPropSymbols$4)
10580
- for (var prop of __getOwnPropSymbols$4(b)) {
10581
- if (__propIsEnum$4.call(b, prop))
10582
- __defNormalProp$4(a, prop, b[prop]);
10583
- }
10584
- return a;
10585
- };
10586
- var __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b));
10587
9945
  class WithMethods {
10588
9946
  with(name, second, third) {
10589
9947
  const q = _clone(this);
@@ -10596,10 +9954,11 @@ class WithMethods {
10596
9954
  } else {
10597
9955
  query = queryArg;
10598
9956
  }
10599
- if ((options == null ? void 0 : options.columns) === true) {
10600
- options = __spreadProps$1(__spreadValues$4({}, options), {
9957
+ if (options?.columns === true) {
9958
+ options = {
9959
+ ...options,
10601
9960
  columns: Object.keys(query.shape)
10602
- });
9961
+ };
10603
9962
  }
10604
9963
  pushQueryValue(q, "with", { n: name, o: options, q: query });
10605
9964
  const shape = getShapeFromSelect(query, true);
@@ -10609,7 +9968,7 @@ class WithMethods {
10609
9968
  });
10610
9969
  }
10611
9970
  withRecursive(name, ...args) {
10612
- var _a, _b, _c;
9971
+ var _a;
10613
9972
  const q = _clone(this);
10614
9973
  let [options, baseFn, recursiveFn] = args.length === 2 ? [{}, args[0], args[1]] : args;
10615
9974
  const arg = q.queryBuilder.clone();
@@ -10617,14 +9976,15 @@ class WithMethods {
10617
9976
  let query = typeof baseFn === "function" ? baseFn(arg) : baseFn;
10618
9977
  const shape = getShapeFromSelect(query, true);
10619
9978
  const withConfig = { shape, computeds: query.q.computeds };
10620
- ((_b = (_a = arg.q).withShapes) != null ? _b : _a.withShapes = {})[name] = withConfig;
9979
+ ((_a = arg.q).withShapes ?? (_a.withShapes = {}))[name] = withConfig;
10621
9980
  const recursive = recursiveFn(arg);
10622
- query = _queryUnion(query, [recursive], (_c = options.union) != null ? _c : "UNION ALL");
9981
+ query = _queryUnion(query, [recursive], options.union ?? "UNION ALL");
10623
9982
  options.recursive = true;
10624
9983
  if (options.columns === true) {
10625
- options = __spreadProps$1(__spreadValues$4({}, options), {
9984
+ options = {
9985
+ ...options,
10626
9986
  columns: Object.keys(shape)
10627
- });
9987
+ };
10628
9988
  }
10629
9989
  pushQueryValue(q, "with", { n: name, o: options, q: query });
10630
9990
  return setQueryObjectValue(q, "withShapes", name, withConfig);
@@ -10644,22 +10004,6 @@ class WithMethods {
10644
10004
  }
10645
10005
  }
10646
10006
 
10647
- var __defProp$3 = Object.defineProperty;
10648
- var __getOwnPropSymbols$3 = Object.getOwnPropertySymbols;
10649
- var __hasOwnProp$3 = Object.prototype.hasOwnProperty;
10650
- var __propIsEnum$3 = Object.prototype.propertyIsEnumerable;
10651
- var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
10652
- var __spreadValues$3 = (a, b) => {
10653
- for (var prop in b || (b = {}))
10654
- if (__hasOwnProp$3.call(b, prop))
10655
- __defNormalProp$3(a, prop, b[prop]);
10656
- if (__getOwnPropSymbols$3)
10657
- for (var prop of __getOwnPropSymbols$3(b)) {
10658
- if (__propIsEnum$3.call(b, prop))
10659
- __defNormalProp$3(a, prop, b[prop]);
10660
- }
10661
- return a;
10662
- };
10663
10007
  const _queryChangeCounter = (self, op, data) => {
10664
10008
  const q = self.q;
10665
10009
  q.type = "update";
@@ -10696,7 +10040,7 @@ const update = (self) => {
10696
10040
  };
10697
10041
  const _queryUpdate = (query, arg) => {
10698
10042
  const { q } = query;
10699
- const set = __spreadValues$3({}, arg);
10043
+ const set = { ...arg };
10700
10044
  pushQueryValue(query, "updateData", set);
10701
10045
  const { shape } = q;
10702
10046
  const ctx = {};
@@ -10738,8 +10082,7 @@ const _queryUpdate = (query, arg) => {
10738
10082
  }
10739
10083
  } else {
10740
10084
  const encode = shape[key].data.encode;
10741
- if (encode)
10742
- set[key] = encode(value);
10085
+ if (encode) set[key] = encode(value);
10743
10086
  }
10744
10087
  }
10745
10088
  }
@@ -11098,25 +10441,6 @@ class Update {
11098
10441
  }
11099
10442
  }
11100
10443
 
11101
- var __defProp$2 = Object.defineProperty;
11102
- var __defProps = Object.defineProperties;
11103
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
11104
- var __getOwnPropSymbols$2 = Object.getOwnPropertySymbols;
11105
- var __hasOwnProp$2 = Object.prototype.hasOwnProperty;
11106
- var __propIsEnum$2 = Object.prototype.propertyIsEnumerable;
11107
- var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
11108
- var __spreadValues$2 = (a, b) => {
11109
- for (var prop in b || (b = {}))
11110
- if (__hasOwnProp$2.call(b, prop))
11111
- __defNormalProp$2(a, prop, b[prop]);
11112
- if (__getOwnPropSymbols$2)
11113
- for (var prop of __getOwnPropSymbols$2(b)) {
11114
- if (__propIsEnum$2.call(b, prop))
11115
- __defNormalProp$2(a, prop, b[prop]);
11116
- }
11117
- return a;
11118
- };
11119
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
11120
10444
  class Headline extends Expression {
11121
10445
  constructor(q, source, params) {
11122
10446
  super();
@@ -11129,16 +10453,15 @@ class Headline extends Expression {
11129
10453
  makeSQL(ctx, quotedAs) {
11130
10454
  const { q, source, params } = this;
11131
10455
  const lang = getSearchLang(ctx, q, source, quotedAs);
11132
- const text = (params == null ? void 0 : params.text) ? params.text instanceof Expression ? params.text.toSQL(ctx, quotedAs) : columnToSql(ctx, q, q.shape, params.text, quotedAs) : getSearchText(ctx, q, source, quotedAs, true);
11133
- const options = (params == null ? void 0 : params.options) ? `, ${params.options instanceof Expression ? params.options.toSQL(ctx, quotedAs) : addValue(ctx.values, params.options)}` : "";
10456
+ const text = params?.text ? params.text instanceof Expression ? params.text.toSQL(ctx, quotedAs) : columnToSql(ctx, q, q.shape, params.text, quotedAs) : getSearchText(ctx, q, source, quotedAs, true);
10457
+ const options = params?.options ? `, ${params.options instanceof Expression ? params.options.toSQL(ctx, quotedAs) : addValue(ctx.values, params.options)}` : "";
11134
10458
  return `ts_headline(${lang}, ${text}, "${source.as}"${options})`;
11135
10459
  }
11136
10460
  }
11137
10461
  Object.assign(Headline, Operators.text);
11138
10462
  AggregateMethods.prototype.headline = function(search, params) {
11139
- var _a;
11140
10463
  const q = this;
11141
- const source = (_a = q.q.sources) == null ? void 0 : _a[search];
10464
+ const source = q.q.sources?.[search];
11142
10465
  if (!source)
11143
10466
  throw new OrchidOrmInternalError(q, `Search \`${search}\` is not defined`);
11144
10467
  return new Headline(
@@ -11340,9 +10663,10 @@ class SearchMethods {
11340
10663
  const q = _clone(this);
11341
10664
  if (!arg.as) {
11342
10665
  const as = saveSearchAlias(q, "@q", "joinedShapes");
11343
- arg = __spreadProps(__spreadValues$2({}, arg), {
10666
+ arg = {
10667
+ ...arg,
11344
10668
  as
11345
- });
10669
+ };
11346
10670
  }
11347
10671
  setQueryObjectValue(q, "sources", arg.as, arg);
11348
10672
  if (arg.order) {
@@ -11352,22 +10676,6 @@ class SearchMethods {
11352
10676
  }
11353
10677
  }
11354
10678
 
11355
- var __defProp$1 = Object.defineProperty;
11356
- var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
11357
- var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
11358
- var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
11359
- var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
11360
- var __spreadValues$1 = (a, b) => {
11361
- for (var prop in b || (b = {}))
11362
- if (__hasOwnProp$1.call(b, prop))
11363
- __defNormalProp$1(a, prop, b[prop]);
11364
- if (__getOwnPropSymbols$1)
11365
- for (var prop of __getOwnPropSymbols$1(b)) {
11366
- if (__propIsEnum$1.call(b, prop))
11367
- __defNormalProp$1(a, prop, b[prop]);
11368
- }
11369
- return a;
11370
- };
11371
10679
  function orCreate(query, data, updateData, mergeData) {
11372
10680
  const { q } = query;
11373
10681
  q.returnType = "one";
@@ -11383,12 +10691,11 @@ function orCreate(query, data, updateData, mergeData) {
11383
10691
  if (typeof data === "function") {
11384
10692
  data = data(updateData);
11385
10693
  }
11386
- if (mergeData)
11387
- data = __spreadValues$1(__spreadValues$1({}, mergeData), data);
10694
+ if (mergeData) data = { ...mergeData, ...data };
11388
10695
  const inner = q2.create(data);
11389
10696
  inner.q.handleResult = (q3, t, r, s) => {
11390
10697
  result = handleResult(q3, t, r, s);
11391
- return inner.q.hookSelect ? result.map((row) => __spreadValues$1({}, row)) : result;
10698
+ return inner.q.hookSelect ? result.map((row) => ({ ...row })) : result;
11392
10699
  };
11393
10700
  await inner;
11394
10701
  created = true;
@@ -11678,12 +10985,10 @@ class ScopeMethods {
11678
10985
  * @param scope - name of the scope to apply
11679
10986
  */
11680
10987
  scope(scope) {
11681
- var _a;
11682
10988
  const q = _clone(this);
11683
- if (!((_a = q.q.scopes) == null ? void 0 : _a[scope])) {
10989
+ if (!q.q.scopes?.[scope]) {
11684
10990
  const s = q.internal.scopes[scope];
11685
- if (!s)
11686
- throw new Error(`Scope ${scope} is not defined`);
10991
+ if (!s) throw new Error(`Scope ${scope} is not defined`);
11687
10992
  setQueryObjectValue(q, "scopes", scope, s);
11688
10993
  }
11689
10994
  return q;
@@ -11714,7 +11019,7 @@ class ScopeMethods {
11714
11019
  }
11715
11020
 
11716
11021
  function enableSoftDelete(q, table, shape, softDelete, scopes) {
11717
- var _a, _b;
11022
+ var _a;
11718
11023
  const column = softDelete === true ? "deletedAt" : softDelete;
11719
11024
  if (!shape[column]) {
11720
11025
  throw new Error(
@@ -11725,7 +11030,7 @@ function enableSoftDelete(q, table, shape, softDelete, scopes) {
11725
11030
  and: [{ [column]: null }]
11726
11031
  };
11727
11032
  scopes.deleted = scope;
11728
- ((_b = (_a = q.q).scopes) != null ? _b : _a.scopes = {}).nonDeleted = scope;
11033
+ ((_a = q.q).scopes ?? (_a.scopes = {})).nonDeleted = scope;
11729
11034
  const _del = _softDelete(
11730
11035
  column,
11731
11036
  q.internal.nowSQL
@@ -11808,8 +11113,7 @@ class OrExpression extends Expression {
11808
11113
  if (arg) {
11809
11114
  if (isExpression(arg)) {
11810
11115
  const sql = arg.toSQL(ctx, quotedAs);
11811
- if (sql)
11812
- res.push(sql);
11116
+ if (sql) res.push(sql);
11813
11117
  } else {
11814
11118
  res.push(`(${getSqlText(arg.toSQL(ctx))})`);
11815
11119
  }
@@ -12389,10 +11693,10 @@ class QueryMethods {
12389
11693
  const query = _clone(this);
12390
11694
  const q = query.q;
12391
11695
  q.type = "truncate";
12392
- if (options == null ? void 0 : options.restartIdentity) {
11696
+ if (options?.restartIdentity) {
12393
11697
  q.restartIdentity = true;
12394
11698
  }
12395
- if (options == null ? void 0 : options.cascade) {
11699
+ if (options?.cascade) {
12396
11700
  q.cascade = true;
12397
11701
  }
12398
11702
  return _queryExec(query);
@@ -12642,12 +11946,12 @@ applyMixins(QueryMethods, [
12642
11946
 
12643
11947
  const makeIndex = (columns, first, second) => {
12644
11948
  if (typeof first === "string") {
12645
- const options = second != null ? second : {};
11949
+ const options = second ?? {};
12646
11950
  return {
12647
11951
  index: { columns, options, name: first }
12648
11952
  };
12649
11953
  } else {
12650
- const options = first != null ? first : {};
11954
+ const options = first ?? {};
12651
11955
  return {
12652
11956
  index: { columns, options }
12653
11957
  };
@@ -12664,16 +11968,16 @@ const tableDataMethods = {
12664
11968
  },
12665
11969
  index: makeIndex,
12666
11970
  searchIndex(columns, ...[first, second]) {
12667
- var _a, _b;
11971
+ var _a;
12668
11972
  const input = makeIndex(columns, first, second);
12669
- (_b = (_a = input.index.options).using) != null ? _b : _a.using = "gin";
11973
+ (_a = input.index.options).using ?? (_a.using = "gin");
12670
11974
  input.index.options.tsVector = true;
12671
11975
  return input;
12672
11976
  },
12673
11977
  foreignKey(columns, fnOrTable, foreignColumns, options) {
12674
11978
  return {
12675
11979
  constraint: {
12676
- name: options == null ? void 0 : options.name,
11980
+ name: options?.name,
12677
11981
  references: { columns, fnOrTable, foreignColumns, options }
12678
11982
  }
12679
11983
  };
@@ -12698,7 +12002,6 @@ const parseTableData = (dataFn) => {
12698
12002
  return tableData;
12699
12003
  };
12700
12004
  const parseTableDataInput = (tableData, item) => {
12701
- var _a, _b, _c, _d;
12702
12005
  if (item.primaryKey) {
12703
12006
  tableData.primaryKey = item.primaryKey;
12704
12007
  } else if (item.index) {
@@ -12710,47 +12013,18 @@ const parseTableDataInput = (tableData, item) => {
12710
12013
  };
12711
12014
  }
12712
12015
  }
12713
- ((_a = tableData.indexes) != null ? _a : tableData.indexes = []).push(item.index);
12016
+ (tableData.indexes ?? (tableData.indexes = [])).push(item.index);
12714
12017
  } else if (item.constraint) {
12715
- ((_b = tableData.constraints) != null ? _b : tableData.constraints = []).push(item.constraint);
12716
- if ((_d = (_c = item.constraint.references) == null ? void 0 : _c.options) == null ? void 0 : _d.dropMode) {
12018
+ (tableData.constraints ?? (tableData.constraints = [])).push(item.constraint);
12019
+ if (item.constraint.references?.options?.dropMode) {
12717
12020
  item.constraint.dropMode = item.constraint.references.options.dropMode;
12718
12021
  }
12719
12022
  }
12720
12023
  };
12721
12024
 
12722
- var __defProp = Object.defineProperty;
12723
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
12724
- var __hasOwnProp = Object.prototype.hasOwnProperty;
12725
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
12726
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
12727
- var __spreadValues = (a, b) => {
12728
- for (var prop in b || (b = {}))
12729
- if (__hasOwnProp.call(b, prop))
12730
- __defNormalProp(a, prop, b[prop]);
12731
- if (__getOwnPropSymbols)
12732
- for (var prop of __getOwnPropSymbols(b)) {
12733
- if (__propIsEnum.call(b, prop))
12734
- __defNormalProp(a, prop, b[prop]);
12735
- }
12736
- return a;
12737
- };
12738
- var __objRest = (source, exclude) => {
12739
- var target = {};
12740
- for (var prop in source)
12741
- if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
12742
- target[prop] = source[prop];
12743
- if (source != null && __getOwnPropSymbols)
12744
- for (var prop of __getOwnPropSymbols(source)) {
12745
- if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
12746
- target[prop] = source[prop];
12747
- }
12748
- return target;
12749
- };
12750
12025
  const anyShape = {};
12751
12026
  class Db extends QueryMethods {
12752
12027
  constructor(adapter, queryBuilder, table = void 0, shape = anyShape, columnTypes, transactionStorage, options, tableData = emptyObject) {
12753
- var _a;
12754
12028
  super();
12755
12029
  this.adapter = adapter;
12756
12030
  this.queryBuilder = queryBuilder;
@@ -12802,10 +12076,8 @@ class Db extends QueryMethods {
12802
12076
  }
12803
12077
  if (typeof column.data.default === "function") {
12804
12078
  const arr = this.internal.runtimeDefaultColumns;
12805
- if (!arr)
12806
- this.internal.runtimeDefaultColumns = [key];
12807
- else
12808
- arr.push(key);
12079
+ if (!arr) this.internal.runtimeDefaultColumns = [key];
12080
+ else arr.push(key);
12809
12081
  if (!column.data.runtimeDefault) {
12810
12082
  const {
12811
12083
  data: { default: def, encode }
@@ -12820,10 +12092,10 @@ class Db extends QueryMethods {
12820
12092
  handleResult,
12821
12093
  logger,
12822
12094
  log: logParamToLogObject(logger, options.log),
12823
- autoPreparedStatements: (_a = options.autoPreparedStatements) != null ? _a : false,
12095
+ autoPreparedStatements: options.autoPreparedStatements ?? false,
12824
12096
  parsers: hasParsers ? parsers : void 0,
12825
12097
  language: options.language,
12826
- schema: options == null ? void 0 : options.schema
12098
+ schema: options?.schema
12827
12099
  };
12828
12100
  let shapeHasPrimaryKey;
12829
12101
  for (const key in shape) {
@@ -12838,17 +12110,14 @@ class Db extends QueryMethods {
12838
12110
  }
12839
12111
  if (!shapeHasPrimaryKey && !tableData.primaryKey && shape !== anyShape && options.noPrimaryKey !== "ignore") {
12840
12112
  const message = `Table ${table} has no primary key`;
12841
- if (options.noPrimaryKey === "error")
12842
- throw new Error(message);
12843
- else
12844
- logger.warn(message);
12113
+ if (options.noPrimaryKey === "error") throw new Error(message);
12114
+ else logger.warn(message);
12845
12115
  }
12846
12116
  const columns = Object.keys(
12847
12117
  shape
12848
12118
  );
12849
12119
  this.columns = columns;
12850
- if (options.computed)
12851
- applyComputedColumns(this, options.computed);
12120
+ if (options.computed) applyComputedColumns(this, options.computed);
12852
12121
  if (prepareSelectAll) {
12853
12122
  const list = [];
12854
12123
  const keys = {};
@@ -12960,21 +12229,19 @@ class Db extends QueryMethods {
12960
12229
  * use this method to exchange a db column name to its runtime key.
12961
12230
  */
12962
12231
  columnNameToKey(name) {
12963
- var _a;
12964
12232
  let map = this.internal.columnNameToKeyMap;
12965
12233
  if (!map) {
12966
12234
  this.internal.columnNameToKeyMap = map = /* @__PURE__ */ new Map();
12967
12235
  const { shape } = this;
12968
12236
  for (const key in this.shape) {
12969
12237
  const column = shape[key];
12970
- map.set((_a = column.data.name) != null ? _a : key, key);
12238
+ map.set(column.data.name ?? key, key);
12971
12239
  }
12972
12240
  }
12973
12241
  return map.get(name);
12974
12242
  }
12975
12243
  }
12976
12244
  const performQuery = async (q, args, method) => {
12977
- var _a;
12978
12245
  const trx = q.internal.transactionStorage.getStore();
12979
12246
  let sql;
12980
12247
  if (isRawSQL(args[0])) {
@@ -12994,16 +12261,14 @@ const performQuery = async (q, args, method) => {
12994
12261
  values
12995
12262
  };
12996
12263
  }
12997
- const log = (_a = trx == null ? void 0 : trx.log) != null ? _a : q.q.log;
12264
+ const log = trx?.log ?? q.q.log;
12998
12265
  let logData;
12999
- if (log)
13000
- logData = log.beforeQuery(sql);
12266
+ if (log) logData = log.beforeQuery(sql);
13001
12267
  try {
13002
- const result = await ((trx == null ? void 0 : trx.adapter) || q.adapter)[method](
12268
+ const result = await (trx?.adapter || q.adapter)[method](
13003
12269
  sql
13004
12270
  );
13005
- if (log)
13006
- log.afterQuery(sql, logData);
12271
+ if (log) log.afterQuery(sql, logData);
13007
12272
  return result;
13008
12273
  } catch (err) {
13009
12274
  if (log) {
@@ -13014,27 +12279,20 @@ const performQuery = async (q, args, method) => {
13014
12279
  };
13015
12280
  applyMixins(Db, [QueryMethods]);
13016
12281
  Db.prototype.constructor = Db;
13017
- const createDb = (_a) => {
13018
- var _b = _a, {
13019
- log,
13020
- logger,
13021
- snakeCase,
13022
- schemaConfig = defaultSchemaConfig,
13023
- columnTypes: ctOrFn = makeColumnTypes(schemaConfig)
13024
- } = _b, options = __objRest(_b, [
13025
- "log",
13026
- "logger",
13027
- "snakeCase",
13028
- "schemaConfig",
13029
- "columnTypes"
13030
- ]);
13031
- var _a2, _b2;
12282
+ const createDb = ({
12283
+ log,
12284
+ logger,
12285
+ snakeCase,
12286
+ schemaConfig = defaultSchemaConfig,
12287
+ columnTypes: ctOrFn = makeColumnTypes(schemaConfig),
12288
+ ...options
12289
+ }) => {
13032
12290
  const adapter = "adapter" in options ? options.adapter : new Adapter(options);
13033
12291
  const commonOptions = {
13034
12292
  log,
13035
12293
  logger,
13036
- autoPreparedStatements: (_a2 = options.autoPreparedStatements) != null ? _a2 : false,
13037
- noPrimaryKey: (_b2 = options.noPrimaryKey) != null ? _b2 : "error",
12294
+ autoPreparedStatements: options.autoPreparedStatements ?? false,
12295
+ noPrimaryKey: options.noPrimaryKey ?? "error",
13038
12296
  nowSQL: options.nowSQL,
13039
12297
  snakeCase
13040
12298
  };
@@ -13056,10 +12314,10 @@ const createDb = (_a) => {
13056
12314
  adapter,
13057
12315
  qb,
13058
12316
  table,
13059
- typeof shape === "function" ? getColumnTypes(ct, shape, nowSQL, options2 == null ? void 0 : options2.language) : shape,
12317
+ typeof shape === "function" ? getColumnTypes(ct, shape, nowSQL, options2?.language) : shape,
13060
12318
  ct,
13061
12319
  transactionStorage,
13062
- __spreadValues(__spreadValues({}, commonOptions), options2),
12320
+ { ...commonOptions, ...options2 },
13063
12321
  parseTableData(dataFn)
13064
12322
  );
13065
12323
  };
@@ -13117,7 +12375,7 @@ const testTransaction = {
13117
12375
  * @param arg - ORM instance or a queryable instance (such as db.someTable).
13118
12376
  */
13119
12377
  start(arg) {
13120
- var _a, _b;
12378
+ var _a;
13121
12379
  const db = argToDb(arg);
13122
12380
  const { transactionStorage } = db.internal;
13123
12381
  const { getStore } = transactionStorage;
@@ -13129,7 +12387,7 @@ const testTransaction = {
13129
12387
  transaction: adapter.transaction
13130
12388
  }
13131
12389
  };
13132
- ((_b = (_a = db.internal)[trxForTest]) != null ? _b : _a[trxForTest] = []).push(data);
12390
+ ((_a = db.internal)[trxForTest] ?? (_a[trxForTest] = [])).push(data);
13133
12391
  return new Promise((resolve) => {
13134
12392
  data.promise = db.transaction(() => {
13135
12393
  resolve();
@@ -13151,7 +12409,7 @@ const testTransaction = {
13151
12409
  }
13152
12410
  }).finally(() => {
13153
12411
  const trx = db.internal.transactionStorage.getStore();
13154
- if (trx == null ? void 0 : trx.testTransactionCount) {
12412
+ if (trx?.testTransactionCount) {
13155
12413
  trx.testTransactionCount--;
13156
12414
  }
13157
12415
  db.internal.transactionStorage.getStore = getStore;
@@ -13164,16 +12422,14 @@ const testTransaction = {
13164
12422
  * @param arg - the same ORM or query argument passed into the `testTransaction.start`.
13165
12423
  */
13166
12424
  rollback(arg) {
13167
- var _a;
13168
12425
  const db = argToDb(arg);
13169
12426
  const data = db.internal[trxForTest];
13170
- const last = data == null ? void 0 : data.pop();
13171
- if (!last)
13172
- return;
13173
- if ((data == null ? void 0 : data.length) === 1) {
12427
+ const last = data?.pop();
12428
+ if (!last) return;
12429
+ if (data?.length === 1) {
13174
12430
  Object.assign(db.baseQuery.q.adapter, data[0].adapter);
13175
12431
  }
13176
- (_a = last.reject) == null ? void 0 : _a.call(last, new Rollback());
12432
+ last.reject?.(new Rollback());
13177
12433
  return last.promise;
13178
12434
  },
13179
12435
  /**
@@ -13183,10 +12439,9 @@ const testTransaction = {
13183
12439
  * @param arg - the same ORM or query argument passed into the `testTransaction.start`.
13184
12440
  */
13185
12441
  async close(arg) {
13186
- var _a;
13187
12442
  const db = argToDb(arg);
13188
12443
  await this.rollback(db);
13189
- if (((_a = db.internal[trxForTest]) == null ? void 0 : _a.length) === 0) {
12444
+ if (db.internal[trxForTest]?.length === 0) {
13190
12445
  return db.q.adapter.close();
13191
12446
  }
13192
12447
  }