pqb 0.42.4 → 0.42.6

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.js CHANGED
@@ -56,8 +56,7 @@ class RawSQL extends orchidCore.RawSQLBase {
56
56
  used.length = 0;
57
57
  for (let i = 0; i < len; i += 2) {
58
58
  arr[i] = arr[i].replace(/\$\$?(\w+)/g, (match, key, i2) => {
59
- if (isTemplate && literalValues.includes(i2))
60
- return match;
59
+ if (isTemplate && literalValues.includes(i2)) return match;
61
60
  const value = data[key];
62
61
  if (value === void 0) {
63
62
  throw new Error(`Query variable \`${key}\` is not provided`);
@@ -119,25 +118,6 @@ const sqlFn = (...args) => {
119
118
  return (...args2) => new RawSQL(args2, arg);
120
119
  };
121
120
 
122
- var __defProp$p = Object.defineProperty;
123
- var __defProps$f = Object.defineProperties;
124
- var __getOwnPropDescs$f = Object.getOwnPropertyDescriptors;
125
- var __getOwnPropSymbols$q = Object.getOwnPropertySymbols;
126
- var __hasOwnProp$q = Object.prototype.hasOwnProperty;
127
- var __propIsEnum$q = Object.prototype.propertyIsEnumerable;
128
- var __defNormalProp$p = (obj, key, value) => key in obj ? __defProp$p(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
129
- var __spreadValues$p = (a, b) => {
130
- for (var prop in b || (b = {}))
131
- if (__hasOwnProp$q.call(b, prop))
132
- __defNormalProp$p(a, prop, b[prop]);
133
- if (__getOwnPropSymbols$q)
134
- for (var prop of __getOwnPropSymbols$q(b)) {
135
- if (__propIsEnum$q.call(b, prop))
136
- __defNormalProp$p(a, prop, b[prop]);
137
- }
138
- return a;
139
- };
140
- var __spreadProps$f = (a, b) => __defProps$f(a, __getOwnPropDescs$f(b));
141
121
  class ColumnType extends orchidCore.ColumnTypeBase {
142
122
  /**
143
123
  * Mark the column as a primary key.
@@ -164,7 +144,7 @@ class ColumnType extends orchidCore.ColumnTypeBase {
164
144
  * @param name - to specify a constraint name
165
145
  */
166
146
  primaryKey(name) {
167
- return orchidCore.setColumnData(this, "primaryKey", name != null ? name : true);
147
+ return orchidCore.setColumnData(this, "primaryKey", name ?? true);
168
148
  }
169
149
  foreignKey(fnOrTable, column, options = orchidCore.emptyObject) {
170
150
  return orchidCore.pushColumnData(this, "foreignKeys", {
@@ -226,9 +206,8 @@ class ColumnType extends orchidCore.ColumnTypeBase {
226
206
  * @param args
227
207
  */
228
208
  index(...args) {
229
- var _a;
230
209
  return orchidCore.pushColumnData(this, "indexes", {
231
- options: (_a = typeof args[0] === "string" ? args[1] : args[0]) != null ? _a : orchidCore.emptyObject,
210
+ options: (typeof args[0] === "string" ? args[1] : args[0]) ?? orchidCore.emptyObject,
232
211
  name: typeof args[0] === "string" ? args[0] : void 0
233
212
  });
234
213
  }
@@ -336,15 +315,19 @@ class ColumnType extends orchidCore.ColumnTypeBase {
336
315
  */
337
316
  searchIndex(...args) {
338
317
  return orchidCore.pushColumnData(this, "indexes", {
339
- options: __spreadValues$p(__spreadValues$p({}, typeof args[0] === "string" ? args[1] : args[0]), this.dataType === "tsvector" ? { using: "GIN" } : { tsVector: true }),
318
+ options: {
319
+ ...typeof args[0] === "string" ? args[1] : args[0],
320
+ ...this.dataType === "tsvector" ? { using: "GIN" } : { tsVector: true }
321
+ },
340
322
  name: typeof args[0] === "string" ? args[0] : void 0
341
323
  });
342
324
  }
343
325
  unique(...args) {
344
326
  return orchidCore.pushColumnData(this, "indexes", {
345
- options: __spreadProps$f(__spreadValues$p({}, typeof args[0] === "string" ? args[1] : args[0]), {
327
+ options: {
328
+ ...typeof args[0] === "string" ? args[1] : args[0],
346
329
  unique: true
347
- }),
330
+ },
348
331
  name: typeof args[0] === "string" ? args[0] : void 0
349
332
  });
350
333
  }
@@ -385,25 +368,6 @@ class ColumnType extends orchidCore.ColumnTypeBase {
385
368
  }
386
369
  }
387
370
 
388
- var __defProp$o = Object.defineProperty;
389
- var __defProps$e = Object.defineProperties;
390
- var __getOwnPropDescs$e = Object.getOwnPropertyDescriptors;
391
- var __getOwnPropSymbols$p = Object.getOwnPropertySymbols;
392
- var __hasOwnProp$p = Object.prototype.hasOwnProperty;
393
- var __propIsEnum$p = Object.prototype.propertyIsEnumerable;
394
- var __defNormalProp$o = (obj, key, value) => key in obj ? __defProp$o(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
395
- var __spreadValues$o = (a, b) => {
396
- for (var prop in b || (b = {}))
397
- if (__hasOwnProp$p.call(b, prop))
398
- __defNormalProp$o(a, prop, b[prop]);
399
- if (__getOwnPropSymbols$p)
400
- for (var prop of __getOwnPropSymbols$p(b)) {
401
- if (__propIsEnum$p.call(b, prop))
402
- __defNormalProp$o(a, prop, b[prop]);
403
- }
404
- return a;
405
- };
406
- var __spreadProps$e = (a, b) => __defProps$e(a, __getOwnPropDescs$e(b));
407
371
  const knownDefaults = {
408
372
  current_timestamp: "now()",
409
373
  "transaction_timestamp()": "now()"
@@ -419,28 +383,26 @@ const simplifyColumnDefault = (value) => {
419
383
  const instantiateColumn = (typeFn, params) => {
420
384
  const column = typeFn();
421
385
  const { dateTimePrecision } = params;
422
- Object.assign(column.data, __spreadProps$e(__spreadValues$o({}, params), {
386
+ Object.assign(column.data, {
387
+ ...params,
423
388
  dateTimePrecision: (
424
389
  // 0 is default for date, 6 is default for timestamp
425
390
  dateTimePrecision && dateTimePrecision !== 6 ? dateTimePrecision : void 0
426
391
  ),
427
392
  collate: params.collate,
428
393
  default: simplifyColumnDefault(params.default)
429
- }));
394
+ });
430
395
  return column;
431
396
  };
432
397
 
433
398
  const isDefaultTimeStamp = (item) => {
434
- if (item.dataType !== "timestamptz")
435
- return false;
399
+ if (item.dataType !== "timestamptz") return false;
436
400
  const def = item.data.default;
437
- if (!(def instanceof orchidCore.RawSQLBase))
438
- return false;
401
+ if (!(def instanceof orchidCore.RawSQLBase)) return false;
439
402
  return typeof def._sql === "string" && def._sql.startsWith("now()");
440
403
  };
441
404
  const combineCodeElements = (input) => {
442
- if (typeof input === "string")
443
- return input;
405
+ if (typeof input === "string") return input;
444
406
  const output = [];
445
407
  let i = -1;
446
408
  for (const item of input) {
@@ -460,12 +422,10 @@ const columnsShapeToCode = (ctx, shape) => {
460
422
  const hasTimestamps = "createdAt" in shape && isDefaultTimeStamp(shape.createdAt) && "updatedAt" in shape && isDefaultTimeStamp(shape.updatedAt);
461
423
  const code = [];
462
424
  for (const key in shape) {
463
- if (hasTimestamps && (key === "createdAt" || key === "updatedAt"))
464
- continue;
425
+ if (hasTimestamps && (key === "createdAt" || key === "updatedAt")) continue;
465
426
  const column = shape[key];
466
427
  const name = column.data.name;
467
- if (name === key)
468
- column.data.name = void 0;
428
+ if (name === key) column.data.name = void 0;
469
429
  code.push(
470
430
  ...combineCodeElements([
471
431
  `${orchidCore.quoteObjectKey(key)}: `,
@@ -473,8 +433,7 @@ const columnsShapeToCode = (ctx, shape) => {
473
433
  ","
474
434
  ])
475
435
  );
476
- if (name === key)
477
- column.data.name = name;
436
+ if (name === key) column.data.name = name;
478
437
  }
479
438
  if (hasTimestamps) {
480
439
  code.push(`...${ctx.t}.timestamps(),`);
@@ -511,11 +470,9 @@ const primaryKeyInnerToCode = (primaryKey, t) => {
511
470
  };
512
471
  const indexToCode = (index, t, prefix) => {
513
472
  const code = indexInnerToCode(index, t);
514
- if (prefix)
515
- code[0] = prefix + code[0];
473
+ if (prefix) code[0] = prefix + code[0];
516
474
  const last = code[code.length - 1];
517
- if (typeof last === "string" && !last.endsWith(","))
518
- orchidCore.addCode(code, ",");
475
+ if (typeof last === "string" && !last.endsWith(",")) orchidCore.addCode(code, ",");
519
476
  return code;
520
477
  };
521
478
  const indexInnerToCode = (index, t) => {
@@ -592,11 +549,9 @@ const indexInnerToCode = (index, t) => {
592
549
  }
593
550
  const options = [];
594
551
  for (const key of indexOptionsKeys) {
595
- if (!key)
596
- continue;
552
+ if (!key) continue;
597
553
  const value = index.options[key];
598
- if (value === null || value === void 0)
599
- continue;
554
+ if (value === null || value === void 0) continue;
600
555
  options.push(
601
556
  `${key}: ${Array.isArray(value) ? orchidCore.singleQuoteArray(value) : typeof value === "string" ? orchidCore.singleQuote(value) : value},`
602
557
  );
@@ -617,8 +572,7 @@ const indexInnerToCode = (index, t) => {
617
572
  };
618
573
  const constraintToCode = (item, t, m, prefix) => {
619
574
  const code = constraintInnerToCode(item, t, m);
620
- if (prefix)
621
- code[0] = prefix + code[0];
575
+ if (prefix) code[0] = prefix + code[0];
622
576
  const last = code[code.length - 1];
623
577
  if (typeof last === "string" && !last.endsWith(","))
624
578
  code[code.length - 1] += ",";
@@ -641,7 +595,7 @@ const referencesArgsToCode = ({
641
595
  fnOrTable,
642
596
  foreignColumns,
643
597
  options
644
- }, name = (options == null ? void 0 : options.name) || false, m) => {
598
+ }, name = options?.name || false, m) => {
645
599
  const args = [];
646
600
  args.push(`${orchidCore.singleQuoteArray(columns)},`);
647
601
  if (m && typeof fnOrTable !== "string") {
@@ -654,14 +608,11 @@ const referencesArgsToCode = ({
654
608
  args.push(`${orchidCore.singleQuoteArray(foreignColumns)},`);
655
609
  if (orchidCore.objectHasValues(options) || name) {
656
610
  const lines = [];
657
- if (name)
658
- lines.push(`name: ${orchidCore.singleQuote(name)},`);
611
+ if (name) lines.push(`name: ${orchidCore.singleQuote(name)},`);
659
612
  for (const key in options) {
660
- if (key === "name")
661
- continue;
613
+ if (key === "name") continue;
662
614
  const value = options[key];
663
- if (value)
664
- lines.push(`${key}: ${orchidCore.singleQuote(value)},`);
615
+ if (value) lines.push(`${key}: ${orchidCore.singleQuote(value)},`);
665
616
  }
666
617
  args.push("{", lines, "},");
667
618
  }
@@ -695,10 +646,8 @@ const foreignKeyArgumentToCode = ({
695
646
  const hasOptions = options.name || options.match || options.onUpdate || options.onDelete;
696
647
  if (hasOptions) {
697
648
  const arr = [];
698
- if (options.name)
699
- arr.push(`name: ${orchidCore.singleQuote(options.name)},`);
700
- if (options.match)
701
- arr.push(`match: ${orchidCore.singleQuote(options.match)},`);
649
+ if (options.name) arr.push(`name: ${orchidCore.singleQuote(options.name)},`);
650
+ if (options.match) arr.push(`match: ${orchidCore.singleQuote(options.match)},`);
702
651
  if (options.onUpdate)
703
652
  arr.push(`onUpdate: ${orchidCore.singleQuote(options.onUpdate)},`);
704
653
  if (options.onDelete)
@@ -714,28 +663,20 @@ const columnIndexesToCode = (indexes) => {
714
663
  for (const { options, name } of indexes) {
715
664
  orchidCore.addCode(code, `.${options.unique ? "unique" : "index"}(`);
716
665
  const arr = [];
717
- if (options.collate)
718
- arr.push(`collate: ${orchidCore.singleQuote(options.collate)},`);
719
- if (options.opclass)
720
- arr.push(`opclass: ${orchidCore.singleQuote(options.opclass)},`);
721
- if (options.order)
722
- arr.push(`order: ${orchidCore.singleQuote(options.order)},`);
723
- if (name)
724
- arr.push(`name: ${orchidCore.singleQuote(name)},`);
725
- if (options.using)
726
- arr.push(`using: ${orchidCore.singleQuote(options.using)},`);
666
+ if (options.collate) arr.push(`collate: ${orchidCore.singleQuote(options.collate)},`);
667
+ if (options.opclass) arr.push(`opclass: ${orchidCore.singleQuote(options.opclass)},`);
668
+ if (options.order) arr.push(`order: ${orchidCore.singleQuote(options.order)},`);
669
+ if (name) arr.push(`name: ${orchidCore.singleQuote(name)},`);
670
+ if (options.using) arr.push(`using: ${orchidCore.singleQuote(options.using)},`);
727
671
  if (options.include)
728
672
  arr.push(
729
673
  `include: ${typeof options.include === "string" ? orchidCore.singleQuote(options.include) : `[${options.include.map(orchidCore.singleQuote).join(", ")}]`},`
730
674
  );
731
- if (options.nullsNotDistinct)
732
- arr.push(`nullsNotDistinct: true,`);
733
- if (options.with)
734
- arr.push(`with: ${orchidCore.singleQuote(options.with)},`);
675
+ if (options.nullsNotDistinct) arr.push(`nullsNotDistinct: true,`);
676
+ if (options.with) arr.push(`with: ${orchidCore.singleQuote(options.with)},`);
735
677
  if (options.tablespace)
736
678
  arr.push(`tablespace: ${orchidCore.singleQuote(options.tablespace)},`);
737
- if (options.where)
738
- arr.push(`where: ${orchidCore.singleQuote(options.where)},`);
679
+ if (options.where) arr.push(`where: ${orchidCore.singleQuote(options.where)},`);
739
680
  if (arr.length) {
740
681
  orchidCore.addCode(code, "{");
741
682
  orchidCore.addCode(code, arr);
@@ -756,20 +697,16 @@ const identityToCode = (identity, dataType) => {
756
697
  code.push(`${dataType}().identity(`);
757
698
  }
758
699
  const props = [];
759
- if (identity.always)
760
- props.push(`always: true,`);
700
+ if (identity.always) props.push(`always: true,`);
761
701
  if (identity.increment && identity.increment !== 1)
762
702
  props.push(`increment: ${identity.increment},`);
763
703
  if (identity.start && identity.start !== 1)
764
704
  props.push(`start: ${identity.start},`);
765
- if (identity.min)
766
- props.push(`min: ${identity.min},`);
767
- if (identity.max)
768
- props.push(`max: ${identity.max},`);
705
+ if (identity.min) props.push(`min: ${identity.min},`);
706
+ if (identity.max) props.push(`max: ${identity.max},`);
769
707
  if (identity.cache && identity.cache !== 1)
770
708
  props.push(`cache: ${identity.cache},`);
771
- if (identity.cycle)
772
- props.push(`cycle: true,`);
709
+ if (identity.cycle) props.push(`cycle: true,`);
773
710
  if (props.length) {
774
711
  orchidCore.addCode(code, "{");
775
712
  code.push(props, "}");
@@ -778,12 +715,11 @@ const identityToCode = (identity, dataType) => {
778
715
  return code;
779
716
  };
780
717
  const columnCode = (type, ctx, key, code) => {
781
- var _a;
782
718
  const { data } = type;
783
719
  code = orchidCore.toArray(code);
784
720
  let prepend = `${ctx.t}.`;
785
721
  const keyName = ctx.snakeCase ? orchidCore.toSnakeCase(key) : key;
786
- const name = (_a = data.name) != null ? _a : keyName;
722
+ const name = data.name ?? keyName;
787
723
  if (name !== keyName) {
788
724
  prepend += `name(${orchidCore.singleQuote(name)}).`;
789
725
  }
@@ -806,18 +742,15 @@ const columnCode = (type, ctx, key, code) => {
806
742
  orchidCore.addCode(code, part);
807
743
  }
808
744
  }
809
- if (data.explicitSelect)
810
- orchidCore.addCode(code, ".select(false)");
811
- if (data.isNullable)
812
- orchidCore.addCode(code, ".nullable()");
745
+ if (data.explicitSelect) orchidCore.addCode(code, ".select(false)");
746
+ if (data.isNullable) orchidCore.addCode(code, ".nullable()");
813
747
  if (data.encode && data.encode !== data.defaultEncode)
814
748
  orchidCore.addCode(code, `.encode(${data.encode.toString()})`);
815
749
  if (data.parse && data.parse !== data.defaultParse)
816
750
  orchidCore.addCode(code, `.parse(${data.parse.toString()})`);
817
751
  if (type.data.parseNull)
818
752
  orchidCore.addCode(code, `.parseNull(${type.data.parseNull.toString()})`);
819
- if (data.as)
820
- orchidCore.addCode(code, `.as(${data.as.toCode(ctx, key)})`);
753
+ if (data.as) orchidCore.addCode(code, `.as(${data.as.toCode(ctx, key)})`);
821
754
  if (data.default !== void 0 && data.default !== data.defaultDefault && (!ctx.migration || typeof data.default !== "function")) {
822
755
  orchidCore.addCode(
823
756
  code,
@@ -829,8 +762,7 @@ const columnCode = (type, ctx, key, code) => {
829
762
  orchidCore.addCode(code, part);
830
763
  }
831
764
  }
832
- if (data.comment)
833
- orchidCore.addCode(code, `.comment(${orchidCore.singleQuote(data.comment)})`);
765
+ if (data.comment) orchidCore.addCode(code, `.comment(${orchidCore.singleQuote(data.comment)})`);
834
766
  if (data.check) {
835
767
  orchidCore.addCode(code, columnCheckToCode(ctx, data.check, name));
836
768
  }
@@ -848,42 +780,20 @@ const columnCode = (type, ctx, key, code) => {
848
780
  }
849
781
  if (data.compression)
850
782
  orchidCore.addCode(code, `.compression(${orchidCore.singleQuote(data.compression)})`);
851
- if (data.collate)
852
- orchidCore.addCode(code, `.collate(${orchidCore.singleQuote(data.collate)})`);
783
+ if (data.collate) orchidCore.addCode(code, `.collate(${orchidCore.singleQuote(data.collate)})`);
853
784
  if (data.modifyQuery)
854
785
  orchidCore.addCode(code, `.modifyQuery(${data.modifyQuery.toString()})`);
855
786
  return code.length === 1 && typeof code[0] === "string" ? code[0] : code;
856
787
  };
857
788
 
858
789
  const getSqlText = (sql) => {
859
- if ("text" in sql)
860
- return sql.text;
790
+ if ("text" in sql) return sql.text;
861
791
  throw new Error(`Batch SQL is not supported in this query`);
862
792
  };
863
793
 
864
- var __defProp$n = Object.defineProperty;
865
- var __defProps$d = Object.defineProperties;
866
- var __getOwnPropDescs$d = Object.getOwnPropertyDescriptors;
867
- var __getOwnPropSymbols$o = Object.getOwnPropertySymbols;
868
- var __hasOwnProp$o = Object.prototype.hasOwnProperty;
869
- var __propIsEnum$o = Object.prototype.propertyIsEnumerable;
870
- var __defNormalProp$n = (obj, key, value) => key in obj ? __defProp$n(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
871
- var __spreadValues$n = (a, b) => {
872
- for (var prop in b || (b = {}))
873
- if (__hasOwnProp$o.call(b, prop))
874
- __defNormalProp$n(a, prop, b[prop]);
875
- if (__getOwnPropSymbols$o)
876
- for (var prop of __getOwnPropSymbols$o(b)) {
877
- if (__propIsEnum$o.call(b, prop))
878
- __defNormalProp$n(a, prop, b[prop]);
879
- }
880
- return a;
881
- };
882
- var __spreadProps$d = (a, b) => __defProps$d(a, __getOwnPropDescs$d(b));
883
794
  const addColumnParserToQuery = (q, key, column) => {
884
- var _a;
885
795
  if (column._parse) {
886
- ((_a = q.parsers) != null ? _a : q.parsers = {})[key] = column._parse;
796
+ (q.parsers ?? (q.parsers = {}))[key] = column._parse;
887
797
  }
888
798
  };
889
799
  const setColumnDefaultParse = (column, parse) => {
@@ -893,7 +803,7 @@ const setColumnDefaultParse = (column, parse) => {
893
803
  const setColumnParse = (column, fn, outputSchema) => {
894
804
  const c = Object.create(column);
895
805
  c.outputSchema = outputSchema;
896
- c.data = __spreadProps$d(__spreadValues$n({}, column.data), { parse: fn });
806
+ c.data = { ...column.data, parse: fn };
897
807
  const { parseNull } = column.data;
898
808
  c._parse = parseNull ? (input) => input === null ? parseNull() : fn(input) : (input) => input === null ? null : fn(input);
899
809
  return c;
@@ -901,7 +811,7 @@ const setColumnParse = (column, fn, outputSchema) => {
901
811
  const setColumnParseNull = (column, fn, nullSchema) => {
902
812
  const c = Object.create(column);
903
813
  c.nullSchema = nullSchema;
904
- c.data = __spreadProps$d(__spreadValues$n({}, column.data), { parseNull: fn });
814
+ c.data = { ...column.data, parseNull: fn };
905
815
  const { parse } = column.data;
906
816
  c._parse = parse ? (input) => input === null ? fn() : parse(input) : (input) => input === null ? fn() : input;
907
817
  return c;
@@ -909,29 +819,10 @@ const setColumnParseNull = (column, fn, nullSchema) => {
909
819
  const setColumnEncode = (column, fn, inputSchema) => {
910
820
  const c = Object.create(column);
911
821
  c.inputSchema = inputSchema;
912
- c.data = __spreadProps$d(__spreadValues$n({}, column.data), { encode: fn });
822
+ c.data = { ...column.data, encode: fn };
913
823
  return c;
914
824
  };
915
825
 
916
- var __defProp$m = Object.defineProperty;
917
- var __defProps$c = Object.defineProperties;
918
- var __getOwnPropDescs$c = Object.getOwnPropertyDescriptors;
919
- var __getOwnPropSymbols$n = Object.getOwnPropertySymbols;
920
- var __hasOwnProp$n = Object.prototype.hasOwnProperty;
921
- var __propIsEnum$n = Object.prototype.propertyIsEnumerable;
922
- var __defNormalProp$m = (obj, key, value) => key in obj ? __defProp$m(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
923
- var __spreadValues$m = (a, b) => {
924
- for (var prop in b || (b = {}))
925
- if (__hasOwnProp$n.call(b, prop))
926
- __defNormalProp$m(a, prop, b[prop]);
927
- if (__getOwnPropSymbols$n)
928
- for (var prop of __getOwnPropSymbols$n(b)) {
929
- if (__propIsEnum$n.call(b, prop))
930
- __defNormalProp$m(a, prop, b[prop]);
931
- }
932
- return a;
933
- };
934
- var __spreadProps$c = (a, b) => __defProps$c(a, __getOwnPropDescs$c(b));
935
826
  function setQueryOperators(query, operators) {
936
827
  const q = query.q;
937
828
  if (q.operators !== operators) {
@@ -944,9 +835,9 @@ const make = (_op) => {
944
835
  return Object.assign(
945
836
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
946
837
  function(value) {
947
- var _a, _b, _c;
948
- ((_b = (_a = this.q).chain) != null ? _b : _a.chain = []).push(_op, value);
949
- if ((_c = this.q.parsers) == null ? void 0 : _c[orchidCore.getValueKey]) {
838
+ var _a;
839
+ ((_a = this.q).chain ?? (_a.chain = [])).push(_op, value);
840
+ if (this.q.parsers?.[orchidCore.getValueKey]) {
950
841
  this.q.parsers[orchidCore.getValueKey] = void 0;
951
842
  }
952
843
  return setQueryOperators(this, boolean);
@@ -962,9 +853,9 @@ const makeVarArg = (_op) => {
962
853
  return Object.assign(
963
854
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
964
855
  function(...args) {
965
- var _a, _b, _c;
966
- ((_b = (_a = this.q).chain) != null ? _b : _a.chain = []).push(_op, args);
967
- if ((_c = this.q.parsers) == null ? void 0 : _c[orchidCore.getValueKey]) {
856
+ var _a;
857
+ ((_a = this.q).chain ?? (_a.chain = [])).push(_op, args);
858
+ if (this.q.parsers?.[orchidCore.getValueKey]) {
968
859
  this.q.parsers[orchidCore.getValueKey] = void 0;
969
860
  }
970
861
  return setQueryOperators(this, boolean);
@@ -992,7 +883,7 @@ const quoteValue = (arg, ctx, quotedAs, jsonArray) => {
992
883
  };
993
884
  const quoteLikeValue = (arg, ctx, quotedAs, jsonArray) => {
994
885
  if (arg && typeof arg === "object") {
995
- if (!jsonArray && Array.isArray(arg)) {
886
+ if (Array.isArray(arg)) {
996
887
  return `(${arg.map((value) => orchidCore.addValue(ctx.values, value)).join(", ")})`;
997
888
  }
998
889
  if (orchidCore.isExpression(arg)) {
@@ -1020,15 +911,17 @@ const base = {
1020
911
  (key, value, ctx, quotedAs) => `NOT ${key} IN ${quoteValue(value, ctx, quotedAs)}`
1021
912
  )
1022
913
  };
1023
- const boolean = __spreadProps$c(__spreadValues$m({}, base), {
914
+ const boolean = {
915
+ ...base,
1024
916
  and: make(
1025
917
  (key, value, ctx, quotedAs) => `${key} AND ${value.q.expr.toSQL(ctx, quotedAs)}`
1026
918
  ),
1027
919
  or: make(
1028
920
  (key, value, ctx, quotedAs) => `(${key}) OR (${value.q.expr.toSQL(ctx, quotedAs)})`
1029
921
  )
1030
- });
1031
- const numeric = __spreadProps$c(__spreadValues$m({}, base), {
922
+ };
923
+ const numeric = {
924
+ ...base,
1032
925
  lt: make(
1033
926
  (key, value, ctx, quotedAs) => `${key} < ${quoteValue(value, ctx, quotedAs)}`
1034
927
  ),
@@ -1048,8 +941,9 @@ const numeric = __spreadProps$c(__spreadValues$m({}, base), {
1048
941
  quotedAs
1049
942
  )}`
1050
943
  )
1051
- });
1052
- const text = __spreadProps$c(__spreadValues$m({}, base), {
944
+ };
945
+ const text = {
946
+ ...base,
1053
947
  contains: make(
1054
948
  (key, value, ctx, quotedAs) => `${key} ILIKE '%' || ${quoteLikeValue(value, ctx, quotedAs)} || '%'`
1055
949
  ),
@@ -1068,20 +962,20 @@ const text = __spreadProps$c(__spreadValues$m({}, base), {
1068
962
  endsWithSensitive: make(
1069
963
  (key, value, ctx, quotedAs) => `${key} LIKE '%' || ${quoteLikeValue(value, ctx, quotedAs)}`
1070
964
  )
1071
- });
965
+ };
1072
966
  const encodeJsonPath = (ctx, path) => orchidCore.addValue(ctx.values, `{${Array.isArray(path) ? path.join(", ") : path}}`);
1073
- const jsonPathQueryOp = (key, [path, options], ctx) => `jsonb_path_query_first(${key}, ${orchidCore.addValue(ctx.values, path)}${(options == null ? void 0 : options.vars) ? `, ${orchidCore.addValue(ctx.values, JSON.stringify(options.vars))}${options.silent ? ", true" : ""}` : (options == null ? void 0 : options.silent) ? ", NULL, true" : ""})`;
1074
- const json = __spreadProps$c(__spreadValues$m({}, base), {
967
+ const jsonPathQueryOp = (key, [path, options], ctx) => `jsonb_path_query_first(${key}, ${orchidCore.addValue(ctx.values, path)}${options?.vars ? `, ${orchidCore.addValue(ctx.values, JSON.stringify(options.vars))}${options.silent ? ", true" : ""}` : options?.silent ? ", NULL, true" : ""})`;
968
+ const json = {
969
+ ...base,
1075
970
  jsonPathQueryFirst: Object.assign(
1076
971
  function(path, options) {
1077
- var _a, _b;
1078
972
  const { q, columnTypes } = this;
1079
- const chain = (_a = q.chain) != null ? _a : q.chain = [];
973
+ const chain = q.chain ?? (q.chain = []);
1080
974
  chain.push(jsonPathQueryOp, [path, options]);
1081
- if ((_b = q.parsers) == null ? void 0 : _b[orchidCore.getValueKey]) {
975
+ if (q.parsers?.[orchidCore.getValueKey]) {
1082
976
  q.parsers[orchidCore.getValueKey] = void 0;
1083
977
  }
1084
- if (options == null ? void 0 : options.type) {
978
+ if (options?.type) {
1085
979
  const type = options.type(columnTypes);
1086
980
  addColumnParserToQuery(q, orchidCore.getValueKey, type);
1087
981
  chain.push = (...args) => {
@@ -1117,12 +1011,12 @@ const json = __spreadProps$c(__spreadValues$m({}, base), {
1117
1011
  (key, [path, value, options], ctx) => `jsonb_insert(${key}, ${encodeJsonPath(ctx, path)}, ${orchidCore.addValue(
1118
1012
  ctx.values,
1119
1013
  JSON.stringify(value)
1120
- )}${(options == null ? void 0 : options.after) ? ", true" : ""})`
1014
+ )}${options?.after ? ", true" : ""})`
1121
1015
  ),
1122
1016
  jsonRemove: makeVarArg(
1123
1017
  (key, [path], ctx) => `(${key} #- ${encodeJsonPath(ctx, path)})`
1124
1018
  )
1125
- });
1019
+ };
1126
1020
  const Operators = {
1127
1021
  any: base,
1128
1022
  boolean,
@@ -1134,22 +1028,6 @@ const Operators = {
1134
1028
  array: base
1135
1029
  };
1136
1030
 
1137
- var __defProp$l = Object.defineProperty;
1138
- var __getOwnPropSymbols$m = Object.getOwnPropertySymbols;
1139
- var __hasOwnProp$m = Object.prototype.hasOwnProperty;
1140
- var __propIsEnum$m = Object.prototype.propertyIsEnumerable;
1141
- var __defNormalProp$l = (obj, key, value) => key in obj ? __defProp$l(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1142
- var __spreadValues$l = (a, b) => {
1143
- for (var prop in b || (b = {}))
1144
- if (__hasOwnProp$m.call(b, prop))
1145
- __defNormalProp$l(a, prop, b[prop]);
1146
- if (__getOwnPropSymbols$m)
1147
- for (var prop of __getOwnPropSymbols$m(b)) {
1148
- if (__propIsEnum$m.call(b, prop))
1149
- __defNormalProp$l(a, prop, b[prop]);
1150
- }
1151
- return a;
1152
- };
1153
1031
  class TextBaseColumn extends ColumnType {
1154
1032
  constructor(schema, schemaType = schema.stringSchema()) {
1155
1033
  super(schema, schemaType);
@@ -1182,7 +1060,7 @@ class VarCharColumn extends LimitedTextBaseColumn {
1182
1060
  this,
1183
1061
  ctx,
1184
1062
  key,
1185
- `varchar(${maxChars != null ? maxChars : ""})${orchidCore.stringDataToCode(this.data, ctx.migration)}`
1063
+ `varchar(${maxChars ?? ""})${orchidCore.stringDataToCode(this.data, ctx.migration)}`
1186
1064
  );
1187
1065
  }
1188
1066
  }
@@ -1192,18 +1070,17 @@ class StringColumn extends VarCharColumn {
1192
1070
  }
1193
1071
  toCode(ctx, key) {
1194
1072
  let max = this.data.maxChars;
1195
- if (max === 255)
1196
- max = void 0;
1073
+ if (max === 255) max = void 0;
1197
1074
  return columnCode(
1198
1075
  this,
1199
1076
  ctx,
1200
1077
  key,
1201
- `string(${max != null ? max : ""})${orchidCore.stringDataToCode(this.data, ctx.migration)}`
1078
+ `string(${max ?? ""})${orchidCore.stringDataToCode(this.data, ctx.migration)}`
1202
1079
  );
1203
1080
  }
1204
1081
  }
1205
1082
  const textColumnToCode = (column, ctx, key) => {
1206
- const data = __spreadValues$l({}, column.data);
1083
+ const data = { ...column.data };
1207
1084
  let args = "";
1208
1085
  const hasMax = data.maxArg !== void 0 && data.max === data.maxArg;
1209
1086
  if (data.minArg !== void 0 && data.min === data.minArg || hasMax) {
@@ -1401,7 +1278,7 @@ class BitVaryingColumn extends ColumnType {
1401
1278
  }
1402
1279
  toCode(ctx, key) {
1403
1280
  const { length } = this.data;
1404
- return columnCode(this, ctx, key, `bitVarying(${length != null ? length : ""})`);
1281
+ return columnCode(this, ctx, key, `bitVarying(${length ?? ""})`);
1405
1282
  }
1406
1283
  toSQL() {
1407
1284
  return orchidCore.joinTruthy(
@@ -1498,8 +1375,7 @@ class UUIDColumn extends ColumnType {
1498
1375
  */
1499
1376
  primaryKey(name) {
1500
1377
  const column = super.primaryKey(name);
1501
- if (!column.data.default)
1502
- column.data.default = uuidDefault;
1378
+ if (!column.data.default) column.data.default = uuidDefault;
1503
1379
  return column;
1504
1380
  }
1505
1381
  toCode(ctx, key) {
@@ -1722,8 +1598,7 @@ const applySqlComputed = (ctx, q, computed, as, quotedAs) => {
1722
1598
  return computed.toSQL(ctx, quotedAs);
1723
1599
  };
1724
1600
  function simpleColumnToSQL(ctx, q, key, column, quotedAs) {
1725
- if (!column)
1726
- return `"${key}"`;
1601
+ if (!column) return `"${key}"`;
1727
1602
  const { data } = column;
1728
1603
  return data.computed ? applySqlComputed(ctx, q, data.computed, key, quotedAs) : `${quotedAs ? `${quotedAs}.` : ""}"${data.name || key}"`;
1729
1604
  }
@@ -1732,7 +1607,6 @@ function simpleExistingColumnToSQL(ctx, q, key, column, quotedAs) {
1732
1607
  return data.computed ? applySqlComputed(ctx, q, data.computed, key, quotedAs) : `${quotedAs ? `${quotedAs}.` : ""}"${data.name || key}"`;
1733
1608
  }
1734
1609
  const columnToSql = (ctx, data, shape, column, quotedAs, select) => {
1735
- var _a;
1736
1610
  const index = column.indexOf(".");
1737
1611
  if (index !== -1) {
1738
1612
  return columnWithDotToSql(
@@ -1745,18 +1619,17 @@ const columnToSql = (ctx, data, shape, column, quotedAs, select) => {
1745
1619
  select
1746
1620
  );
1747
1621
  }
1748
- if (!select && ((_a = data.joinedShapes) == null ? void 0 : _a[column])) {
1622
+ if (!select && data.joinedShapes?.[column]) {
1749
1623
  return `"${column}".r`;
1750
1624
  }
1751
1625
  return simpleColumnToSQL(ctx, data, column, shape[column], quotedAs);
1752
1626
  };
1753
1627
  const maybeSelectedColumnToSql = (ctx, data, column, quotedAs) => {
1754
- var _a;
1755
1628
  const index = column.indexOf(".");
1756
1629
  if (index !== -1) {
1757
1630
  return columnWithDotToSql(ctx, data, data.shape, column, index, quotedAs);
1758
1631
  } else {
1759
- if ((_a = data.joinedShapes) == null ? void 0 : _a[column]) {
1632
+ if (data.joinedShapes?.[column]) {
1760
1633
  return `"${column}".r`;
1761
1634
  }
1762
1635
  if (data.select) {
@@ -1772,15 +1645,14 @@ const maybeSelectedColumnToSql = (ctx, data, column, quotedAs) => {
1772
1645
  }
1773
1646
  };
1774
1647
  const columnWithDotToSql = (ctx, data, shape, column, index, quotedAs, select) => {
1775
- var _a, _b, _c, _d;
1776
1648
  const table = column.slice(0, index);
1777
1649
  const key = column.slice(index + 1);
1778
1650
  if (key === "*") {
1779
- return ((_a = data.joinedShapes) == null ? void 0 : _a[table]) ? select ? `row_to_json("${table}".*)` : `"${table}".*` : column;
1651
+ return data.joinedShapes?.[table] ? select ? `row_to_json("${table}".*)` : `"${table}".*` : column;
1780
1652
  }
1781
- const tableName = ((_b = data.aliases) == null ? void 0 : _b[table]) || table;
1653
+ const tableName = data.aliases?.[table] || table;
1782
1654
  const quoted = `"${table}"`;
1783
- const col = quoted === quotedAs ? shape[key] : (_d = (_c = data.joinedShapes) == null ? void 0 : _c[tableName]) == null ? void 0 : _d[key];
1655
+ const col = quoted === quotedAs ? shape[key] : data.joinedShapes?.[tableName]?.[key];
1784
1656
  if (col) {
1785
1657
  if (col.data.name) {
1786
1658
  return `"${tableName}"."${col.data.name}"`;
@@ -1801,16 +1673,13 @@ const columnToSqlWithAs = (ctx, data, column, as, quotedAs, select) => {
1801
1673
  column.slice(0, index),
1802
1674
  column.slice(index + 1),
1803
1675
  as,
1804
- quotedAs,
1805
- select
1806
- ) : ownColumnToSqlWithAs(ctx, data, column, as, quotedAs, select);
1676
+ quotedAs) : ownColumnToSqlWithAs(ctx, data, column, as, quotedAs, select);
1807
1677
  };
1808
1678
  const tableColumnToSqlWithAs = (ctx, data, column, table, key, as, quotedAs, select) => {
1809
- var _a, _b, _c;
1810
1679
  if (key === "*") {
1811
- const shape = (_a = data.joinedShapes) == null ? void 0 : _a[table];
1680
+ const shape = data.joinedShapes?.[table];
1812
1681
  if (shape) {
1813
- if (select) {
1682
+ {
1814
1683
  let isSimple = true;
1815
1684
  const list = [];
1816
1685
  for (const key2 in shape) {
@@ -1825,13 +1694,12 @@ const tableColumnToSqlWithAs = (ctx, data, column, table, key, as, quotedAs, sel
1825
1694
  }
1826
1695
  return (isSimple ? `row_to_json("${table}".*)` : "json_build_object(" + list.join(", ") + ")") + ` "${as}"`;
1827
1696
  }
1828
- return `"${table}".r "${as}"`;
1829
1697
  }
1830
1698
  return column;
1831
1699
  }
1832
- const tableName = ((_b = data.aliases) == null ? void 0 : _b[table]) || table;
1700
+ const tableName = data.aliases?.[table] || table;
1833
1701
  const quoted = `"${table}"`;
1834
- const col = quoted === quotedAs ? data.shape[key] : (_c = data.joinedShapes) == null ? void 0 : _c[tableName][key];
1702
+ const col = quoted === quotedAs ? data.shape[key] : data.joinedShapes?.[tableName][key];
1835
1703
  if (col) {
1836
1704
  if (col.data.name && col.data.name !== key) {
1837
1705
  return `"${tableName}"."${col.data.name}" "${as}"`;
@@ -1849,8 +1717,7 @@ const tableColumnToSqlWithAs = (ctx, data, column, table, key, as, quotedAs, sel
1849
1717
  return `"${tableName}"."${key}"${key === as ? "" : ` "${as}"`}`;
1850
1718
  };
1851
1719
  const ownColumnToSqlWithAs = (ctx, data, column, as, quotedAs, select) => {
1852
- var _a;
1853
- if (!select && ((_a = data.joinedShapes) == null ? void 0 : _a[column])) {
1720
+ if (!select && data.joinedShapes?.[column]) {
1854
1721
  return select ? `row_to_json("${column}".*) "${as}"` : `"${column}".r "${as}"`;
1855
1722
  }
1856
1723
  const col = data.shape[column];
@@ -1880,31 +1747,20 @@ const quoteSchemaAndTable = (schema, table) => {
1880
1747
  const pushDistinctSql = (ctx, table, distinct, quotedAs) => {
1881
1748
  ctx.sql.push("DISTINCT");
1882
1749
  if (distinct.length) {
1883
- const columns = distinct == null ? void 0 : distinct.map(
1750
+ const columns = distinct?.map(
1884
1751
  (item) => rawOrColumnToSql(ctx, table.q, item, quotedAs)
1885
1752
  );
1886
- ctx.sql.push(`ON (${(columns == null ? void 0 : columns.join(", ")) || ""})`);
1753
+ ctx.sql.push(`ON (${columns?.join(", ") || ""})`);
1887
1754
  }
1888
1755
  };
1889
1756
 
1890
- var __accessCheck = (obj, member, msg) => {
1891
- if (!member.has(obj))
1892
- throw TypeError("Cannot " + msg);
1893
- };
1894
- var __privateGet = (obj, member, getter) => {
1895
- __accessCheck(obj, member, "read from private field");
1896
- return getter ? getter.call(obj) : member.get(obj);
1897
- };
1898
- var __privateAdd = (obj, member, value) => {
1899
- if (member.has(obj))
1900
- throw TypeError("Cannot add the same private member more than once");
1901
- member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
1902
- };
1903
- var __privateSet = (obj, member, value, setter) => {
1904
- __accessCheck(obj, member, "write to private field");
1905
- setter ? setter.call(obj, value) : member.set(obj, value);
1906
- return value;
1757
+ var __typeError = (msg) => {
1758
+ throw TypeError(msg);
1907
1759
  };
1760
+ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
1761
+ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
1762
+ 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);
1763
+ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), member.set(obj, value), value);
1908
1764
  var _query, _query2;
1909
1765
  class OrchidOrmError extends Error {
1910
1766
  }
@@ -1912,7 +1768,7 @@ class NotFoundError extends OrchidOrmError {
1912
1768
  constructor(query, message = "Record is not found") {
1913
1769
  super(message);
1914
1770
  // `#query` is private to prevent it from serializing to not cause problems to test runner reports
1915
- __privateAdd(this, _query, void 0);
1771
+ __privateAdd(this, _query);
1916
1772
  __privateSet(this, _query, query);
1917
1773
  }
1918
1774
  get query() {
@@ -1924,7 +1780,7 @@ class OrchidOrmInternalError extends Error {
1924
1780
  constructor(query, message) {
1925
1781
  super(message);
1926
1782
  // `#query` is private to prevent it from serializing to not cause problems to test runner reports
1927
- __privateAdd(this, _query2, void 0);
1783
+ __privateAdd(this, _query2);
1928
1784
  __privateSet(this, _query2, query);
1929
1785
  }
1930
1786
  get query() {
@@ -1937,17 +1793,14 @@ class QueryError extends OrchidOrmInternalError {
1937
1793
  return this.code === "23505";
1938
1794
  }
1939
1795
  get columns() {
1940
- var _a;
1941
- if (this.columnsCache)
1942
- return this.columnsCache;
1796
+ if (this.columnsCache) return this.columnsCache;
1943
1797
  const columns = {};
1944
1798
  if (this.detail) {
1945
- const list = (_a = this.detail.match(/\((.*)\)=/)) == null ? void 0 : _a[1];
1799
+ const list = this.detail.match(/\((.*)\)=/)?.[1];
1946
1800
  if (list) {
1947
1801
  list.split(", ").forEach((item) => {
1948
- var _a2;
1949
1802
  const column = item.startsWith('"') ? item.slice(1, -1) : item;
1950
- const key = (_a2 = this.query.columnNameToKey(column)) != null ? _a2 : column;
1803
+ const key = this.query.columnNameToKey(column) ?? column;
1951
1804
  columns[key] = true;
1952
1805
  });
1953
1806
  }
@@ -1987,18 +1840,16 @@ const whereToSql = (ctx, table, query, quotedAs, parens) => {
1987
1840
  data.and = scope.and;
1988
1841
  data.or = scope.or;
1989
1842
  const scopeSql = andOrToSql(ctx, table, data, quotedAs, true);
1990
- if (scopeSql)
1991
- sql = sql ? sql + " AND " + scopeSql : scopeSql;
1843
+ if (scopeSql) sql = sql ? sql + " AND " + scopeSql : scopeSql;
1992
1844
  }
1993
1845
  return sql;
1994
1846
  }
1995
1847
  return andOrToSql(ctx, table, query, quotedAs, parens);
1996
1848
  };
1997
1849
  const andOrToSql = (ctx, table, query, quotedAs, parens) => {
1998
- var _a;
1999
1850
  let sql;
2000
1851
  if (query.or) {
2001
- const ors = ((_a = query.and) == null ? void 0 : _a.length) ? [query.and, ...query.or] : query.or;
1852
+ const ors = query.and?.length ? [query.and, ...query.or] : query.or;
2002
1853
  sql = ors.map((and) => processAnds(and, ctx, table, query, quotedAs)).join(" OR ");
2003
1854
  } else if (query.and) {
2004
1855
  sql = processAnds(query.and, ctx, table, query, quotedAs);
@@ -2016,7 +1867,6 @@ const processAnds = (and, ctx, table, query, quotedAs, parens) => {
2016
1867
  return parens && ands.length > 1 ? `(${sql})` : sql;
2017
1868
  };
2018
1869
  const processWhere = (ands, ctx, table, query, data, quotedAs) => {
2019
- var _a, _b, _c, _d;
2020
1870
  if ("prototype" in data || "baseQuery" in data) {
2021
1871
  const query2 = data;
2022
1872
  if (query2.q.expr) {
@@ -2045,8 +1895,7 @@ const processWhere = (ands, ctx, table, query, data, quotedAs) => {
2045
1895
  }
2046
1896
  for (const key in data) {
2047
1897
  const value = data[key];
2048
- if (value === void 0)
2049
- continue;
1898
+ if (value === void 0) continue;
2050
1899
  if (key === "AND") {
2051
1900
  const arr = orchidCore.toArray(value);
2052
1901
  ands.push(processAnds(arr, ctx, table, query, quotedAs));
@@ -2116,8 +1965,7 @@ const processWhere = (ands, ctx, table, query, data, quotedAs) => {
2116
1965
  );
2117
1966
  const sql = `EXISTS (SELECT 1 FROM ${target}${on ? ` WHERE ${on}` : ""})`;
2118
1967
  if (joinSet) {
2119
- if (joinSet.has(sql))
2120
- continue;
1968
+ if (joinSet.has(sql)) continue;
2121
1969
  joinSet.add(sql);
2122
1970
  }
2123
1971
  ands.push(sql);
@@ -2153,10 +2001,10 @@ const processWhere = (ands, ctx, table, query, data, quotedAs) => {
2153
2001
  const table2 = key.slice(0, index);
2154
2002
  const quoted = `"${table2}"`;
2155
2003
  const name = key.slice(index + 1);
2156
- column = quotedAs === quoted ? query.shape[name] : (_b = (_a = query.joinedShapes) == null ? void 0 : _a[table2]) == null ? void 0 : _b[name];
2004
+ column = quotedAs === quoted ? query.shape[name] : query.joinedShapes?.[table2]?.[name];
2157
2005
  quotedColumn = simpleColumnToSQL(ctx, query, name, column, quoted);
2158
2006
  } else {
2159
- column = (_d = (_c = query.joinedShapes) == null ? void 0 : _c[key]) == null ? void 0 : _d.value;
2007
+ column = query.joinedShapes?.[key]?.value;
2160
2008
  quotedColumn = `"${key}".r`;
2161
2009
  }
2162
2010
  if (!column || !quotedColumn) {
@@ -2173,8 +2021,7 @@ const processWhere = (ands, ctx, table, query, data, quotedAs) => {
2173
2021
  if (!operator) {
2174
2022
  throw new Error(`Unknown operator ${op} provided to condition`);
2175
2023
  }
2176
- if (value[op] === void 0)
2177
- continue;
2024
+ if (value[op] === void 0) continue;
2178
2025
  ands.push(
2179
2026
  `${operator._op(
2180
2027
  quotedColumn,
@@ -2220,25 +2067,6 @@ const pushIn = (ctx, query, ands, quotedAs, arg) => {
2220
2067
  ands.push(`${multiple ? `(${columnsSql})` : columnsSql} IN ${value}`);
2221
2068
  };
2222
2069
 
2223
- var __defProp$k = Object.defineProperty;
2224
- var __defProps$b = Object.defineProperties;
2225
- var __getOwnPropDescs$b = Object.getOwnPropertyDescriptors;
2226
- var __getOwnPropSymbols$l = Object.getOwnPropertySymbols;
2227
- var __hasOwnProp$l = Object.prototype.hasOwnProperty;
2228
- var __propIsEnum$l = Object.prototype.propertyIsEnumerable;
2229
- var __defNormalProp$k = (obj, key, value) => key in obj ? __defProp$k(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2230
- var __spreadValues$k = (a, b) => {
2231
- for (var prop in b || (b = {}))
2232
- if (__hasOwnProp$l.call(b, prop))
2233
- __defNormalProp$k(a, prop, b[prop]);
2234
- if (__getOwnPropSymbols$l)
2235
- for (var prop of __getOwnPropSymbols$l(b)) {
2236
- if (__propIsEnum$l.call(b, prop))
2237
- __defNormalProp$k(a, prop, b[prop]);
2238
- }
2239
- return a;
2240
- };
2241
- var __spreadProps$b = (a, b) => __defProps$b(a, __getOwnPropDescs$b(b));
2242
2070
  const processJoinItem = (ctx, table, query, args, quotedAs) => {
2243
2071
  let target;
2244
2072
  let on;
@@ -2300,18 +2128,19 @@ const processJoinItem = (ctx, table, query, args, quotedAs) => {
2300
2128
  const whereSql = whereToSql(
2301
2129
  ctx,
2302
2130
  q,
2303
- __spreadProps$b(__spreadValues$k({}, q.q), {
2304
- joinedShapes: __spreadProps$b(__spreadValues$k(__spreadValues$k({}, query.joinedShapes), q.q.joinedShapes), {
2131
+ {
2132
+ ...q.q,
2133
+ joinedShapes: {
2134
+ ...query.joinedShapes,
2135
+ ...q.q.joinedShapes,
2305
2136
  [table.q.as || table.table]: table.q.shape
2306
- })
2307
- }),
2137
+ }
2138
+ },
2308
2139
  joinAs
2309
2140
  );
2310
2141
  if (whereSql) {
2311
- if (on)
2312
- on += ` AND ${whereSql}`;
2313
- else
2314
- on = whereSql;
2142
+ if (on) on += ` AND ${whereSql}`;
2143
+ else on = whereSql;
2315
2144
  }
2316
2145
  }
2317
2146
  }
@@ -2339,8 +2168,7 @@ const getArgQueryTarget = (ctx, first, joinSubQuery, cloned) => {
2339
2168
  };
2340
2169
  const subJoinToSql = (ctx, jq, innerAs, outerAs, cloned) => {
2341
2170
  if (!jq.q.select && jq.q.selectAllColumns) {
2342
- if (!cloned)
2343
- jq = jq.clone();
2171
+ if (!cloned) jq = jq.clone();
2344
2172
  jq.q.select = [new RawSQL(`${innerAs}.*`)];
2345
2173
  }
2346
2174
  return `(${getSqlText(
@@ -2395,7 +2223,6 @@ const getObjectOrRawConditions = (ctx, query, data, quotedAs, joinAs, joinShape)
2395
2223
  }
2396
2224
  };
2397
2225
  const pushJoinSql = (ctx, table, query, quotedAs) => {
2398
- var _a;
2399
2226
  const joinSet = query.join.length > 1 ? /* @__PURE__ */ new Set() : null;
2400
2227
  for (const item of query.join) {
2401
2228
  let sql;
@@ -2404,7 +2231,7 @@ const pushJoinSql = (ctx, table, query, quotedAs) => {
2404
2231
  const { aliasValue } = ctx;
2405
2232
  ctx.aliasValue = true;
2406
2233
  const as = item[2];
2407
- sql = `${item[0]} LATERAL (${getSqlText(q.toSQL(ctx))}) "${((_a = query.aliases) == null ? void 0 : _a[as]) || as}" ON true`;
2234
+ sql = `${item[0]} LATERAL (${getSqlText(q.toSQL(ctx))}) "${query.aliases?.[as] || as}" ON true`;
2408
2235
  ctx.aliasValue = aliasValue;
2409
2236
  } else {
2410
2237
  const { target, on = "true" } = processJoinItem(
@@ -2417,8 +2244,7 @@ const pushJoinSql = (ctx, table, query, quotedAs) => {
2417
2244
  sql = `${item.type} ${target} ON ${on}`;
2418
2245
  }
2419
2246
  if (joinSet) {
2420
- if (joinSet.has(sql))
2421
- continue;
2247
+ if (joinSet.has(sql)) continue;
2422
2248
  joinSet.add(sql);
2423
2249
  }
2424
2250
  ctx.sql.push(sql);
@@ -2449,27 +2275,7 @@ const getIsJoinSubQuery = (query) => {
2449
2275
  return false;
2450
2276
  };
2451
2277
 
2452
- var __defProp$j = Object.defineProperty;
2453
- var __defProps$a = Object.defineProperties;
2454
- var __getOwnPropDescs$a = Object.getOwnPropertyDescriptors;
2455
- var __getOwnPropSymbols$k = Object.getOwnPropertySymbols;
2456
- var __hasOwnProp$k = Object.prototype.hasOwnProperty;
2457
- var __propIsEnum$k = Object.prototype.propertyIsEnumerable;
2458
- var __defNormalProp$j = (obj, key, value) => key in obj ? __defProp$j(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2459
- var __spreadValues$j = (a, b) => {
2460
- for (var prop in b || (b = {}))
2461
- if (__hasOwnProp$k.call(b, prop))
2462
- __defNormalProp$j(a, prop, b[prop]);
2463
- if (__getOwnPropSymbols$k)
2464
- for (var prop of __getOwnPropSymbols$k(b)) {
2465
- if (__propIsEnum$k.call(b, prop))
2466
- __defNormalProp$j(a, prop, b[prop]);
2467
- }
2468
- return a;
2469
- };
2470
- var __spreadProps$a = (a, b) => __defProps$a(a, __getOwnPropDescs$a(b));
2471
2278
  const processJoinArgs = (joinTo, first, args, joinSubQuery, whereExists) => {
2472
- var _a;
2473
2279
  if (typeof first === "string") {
2474
2280
  if (first in joinTo.relations) {
2475
2281
  const { query: toQuery, joinQuery } = joinTo.relations[first].relationConfig;
@@ -2489,7 +2295,7 @@ const processJoinArgs = (joinTo, first, args, joinSubQuery, whereExists) => {
2489
2295
  return { w: first, a: args };
2490
2296
  } else {
2491
2297
  const joinToQ = joinTo.q;
2492
- const w = (_a = joinToQ.withShapes) == null ? void 0 : _a[first];
2298
+ const w = joinToQ.withShapes?.[first];
2493
2299
  if (!w) {
2494
2300
  throw new Error("Cannot find a `with` statement");
2495
2301
  }
@@ -2504,13 +2310,17 @@ const processJoinArgs = (joinTo, first, args, joinSubQuery, whereExists) => {
2504
2310
  logger: joinToQ.logger
2505
2311
  };
2506
2312
  j.baseQuery = j;
2507
- const joinedShapes = __spreadProps$a(__spreadValues$j({}, joinToQ.joinedShapes), {
2313
+ const joinedShapes = {
2314
+ ...joinToQ.joinedShapes,
2508
2315
  [joinToQ.as || joinTo.table]: joinTo.shape
2509
- });
2316
+ };
2510
2317
  const r = args[0](
2511
2318
  makeJoinQueryBuilder(
2512
2319
  j,
2513
- j.q.joinedShapes ? __spreadValues$j(__spreadValues$j({}, j.q.joinedShapes), joinedShapes) : joinedShapes,
2320
+ j.q.joinedShapes ? {
2321
+ ...j.q.joinedShapes,
2322
+ ...joinedShapes
2323
+ } : joinedShapes,
2514
2324
  joinTo
2515
2325
  )
2516
2326
  );
@@ -2540,16 +2350,20 @@ const processJoinArgs = (joinTo, first, args, joinSubQuery, whereExists) => {
2540
2350
  pushQueryArray(q, "or", query.or);
2541
2351
  }
2542
2352
  if (query.scopes) {
2543
- q.q.scopes = __spreadValues$j(__spreadValues$j({}, q.q.scopes), query.scopes);
2353
+ q.q.scopes = { ...q.q.scopes, ...query.scopes };
2544
2354
  }
2545
2355
  }
2546
- const joinedShapes = __spreadProps$a(__spreadValues$j({}, joinTo.q.joinedShapes), {
2356
+ const joinedShapes = {
2357
+ ...joinTo.q.joinedShapes,
2547
2358
  [joinTo.q.as || joinTo.table]: joinTo.shape
2548
- });
2359
+ };
2549
2360
  const r = args0(
2550
2361
  makeJoinQueryBuilder(
2551
2362
  q,
2552
- q.q.joinedShapes ? __spreadValues$j(__spreadValues$j({}, q.q.joinedShapes), joinedShapes) : joinedShapes,
2363
+ q.q.joinedShapes ? {
2364
+ ...q.q.joinedShapes,
2365
+ ...joinedShapes
2366
+ } : joinedShapes,
2553
2367
  joinTo
2554
2368
  )
2555
2369
  );
@@ -2563,8 +2377,7 @@ const processJoinArgs = (joinTo, first, args, joinSubQuery, whereExists) => {
2563
2377
  };
2564
2378
  };
2565
2379
  const preprocessJoinArg = (q, arg) => {
2566
- if (typeof arg !== "function")
2567
- return arg;
2380
+ if (typeof arg !== "function") return arg;
2568
2381
  arg = arg(q.relations);
2569
2382
  arg.joinQueryAfterCallback = arg.joinQuery;
2570
2383
  return arg;
@@ -2584,20 +2397,16 @@ const noneMethods = {
2584
2397
  async then(resolve, reject) {
2585
2398
  const type = this.q.returnType;
2586
2399
  if (!type || type === "all" || type === "rows" || type === "pluck")
2587
- resolve == null ? void 0 : resolve([]);
2588
- else if (type === "one" || type === "value" || type === "void")
2589
- resolve == null ? void 0 : resolve();
2590
- else if (type === "valueOrThrow" && this.q.returning)
2591
- resolve == null ? void 0 : resolve(0);
2592
- else
2593
- reject == null ? void 0 : reject(new NotFoundError(this));
2400
+ resolve?.([]);
2401
+ else if (type === "one" || type === "value" || type === "void") resolve?.();
2402
+ else if (type === "valueOrThrow" && this.q.returning) resolve?.(0);
2403
+ else reject?.(new NotFoundError(this));
2594
2404
  },
2595
2405
  // `catch` returns a Promise, so it is chainable with then/catch.
2596
2406
  catch: () => new Promise(orchidCore.noop)
2597
2407
  };
2598
2408
  const _queryNone = (q) => {
2599
- if (isQueryNone(q))
2600
- return q;
2409
+ if (isQueryNone(q)) return q;
2601
2410
  q = extendQuery(q, noneMethods);
2602
2411
  pushQueryValue(q, "and", new RawSQL("false"));
2603
2412
  return q;
@@ -2695,8 +2504,7 @@ const _queryWhereIn = (q, and, arg, values, not) => {
2695
2504
  item[key] = { in: values2 };
2696
2505
  }
2697
2506
  }
2698
- if (not)
2699
- item = { NOT: item };
2507
+ if (not) item = { NOT: item };
2700
2508
  if (and) {
2701
2509
  pushQueryValue(q, "and", item);
2702
2510
  } else {
@@ -3396,8 +3204,7 @@ const setQueryObjectValue = (q, object, key, value) => {
3396
3204
  q.q[object] = {
3397
3205
  [key]: value
3398
3206
  };
3399
- else
3400
- q.q[object][key] = value;
3207
+ else q.q[object][key] = value;
3401
3208
  return q;
3402
3209
  };
3403
3210
  const throwIfNoWhere = (q, method) => {
@@ -3409,8 +3216,7 @@ const throwIfNoWhere = (q, method) => {
3409
3216
  }
3410
3217
  };
3411
3218
  const throwIfJoinLateral = (q, method) => {
3412
- var _a;
3413
- if ((_a = q.q.join) == null ? void 0 : _a.some(
3219
+ if (q.q.join?.some(
3414
3220
  (x) => Array.isArray(x) || "s" in x.args && x.args.s
3415
3221
  )) {
3416
3222
  throw new OrchidOrmInternalError(
@@ -3421,7 +3227,7 @@ const throwIfJoinLateral = (q, method) => {
3421
3227
  };
3422
3228
  const saveSearchAlias = (q, as, key) => {
3423
3229
  const shapes = q.q[key];
3424
- if (shapes == null ? void 0 : shapes[as]) {
3230
+ if (shapes?.[as]) {
3425
3231
  let suffix = 2;
3426
3232
  while (shapes[as = `${as}${suffix}`]) {
3427
3233
  suffix++;
@@ -3439,8 +3245,8 @@ const extendQuery = (q, methods) => {
3439
3245
  return cloned;
3440
3246
  };
3441
3247
  const getPrimaryKeys = (q) => {
3442
- var _a, _b;
3443
- return (_b = (_a = q.internal).primaryKeys) != null ? _b : _a.primaryKeys = collectPrimaryKeys(q);
3248
+ var _a;
3249
+ return (_a = q.internal).primaryKeys ?? (_a.primaryKeys = collectPrimaryKeys(q));
3444
3250
  };
3445
3251
  const collectPrimaryKeys = (q) => {
3446
3252
  const primaryKeys = [];
@@ -3450,8 +3256,9 @@ const collectPrimaryKeys = (q) => {
3450
3256
  primaryKeys.push(key);
3451
3257
  }
3452
3258
  }
3453
- if (q.internal.primaryKeys) {
3454
- primaryKeys.push(...q.internal.primaryKeys);
3259
+ const pKeys = q.internal.primaryKeys;
3260
+ if (pKeys) {
3261
+ primaryKeys.push(...pKeys);
3455
3262
  }
3456
3263
  return primaryKeys;
3457
3264
  };
@@ -3482,28 +3289,13 @@ const _queryRows = (q) => {
3482
3289
  q.q.returnType = "rows";
3483
3290
  return q;
3484
3291
  };
3292
+ const getFullColumnTable = (q, column, index, as) => {
3293
+ const table = column.slice(0, index);
3294
+ return as && table !== as && q.q.aliases?.[table] === as ? as : table;
3295
+ };
3485
3296
 
3486
- var __defProp$i = Object.defineProperty;
3487
- var __defProps$9 = Object.defineProperties;
3488
- var __getOwnPropDescs$9 = Object.getOwnPropertyDescriptors;
3489
- var __getOwnPropSymbols$j = Object.getOwnPropertySymbols;
3490
- var __hasOwnProp$j = Object.prototype.hasOwnProperty;
3491
- var __propIsEnum$j = Object.prototype.propertyIsEnumerable;
3492
- var __defNormalProp$i = (obj, key, value) => key in obj ? __defProp$i(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3493
- var __spreadValues$i = (a, b) => {
3494
- for (var prop in b || (b = {}))
3495
- if (__hasOwnProp$j.call(b, prop))
3496
- __defNormalProp$i(a, prop, b[prop]);
3497
- if (__getOwnPropSymbols$j)
3498
- for (var prop of __getOwnPropSymbols$j(b)) {
3499
- if (__propIsEnum$j.call(b, prop))
3500
- __defNormalProp$i(a, prop, b[prop]);
3501
- }
3502
- return a;
3503
- };
3504
- var __spreadProps$9 = (a, b) => __defProps$9(a, __getOwnPropDescs$9(b));
3505
- const _join = (query, require2, type, first, args) => {
3506
- var _a, _b, _c, _d;
3297
+ const _join = (query, require, type, first, args) => {
3298
+ var _a;
3507
3299
  let joinKey;
3508
3300
  let shape;
3509
3301
  let parsers;
@@ -3512,7 +3304,7 @@ const _join = (query, require2, type, first, args) => {
3512
3304
  let joinSubQuery = false;
3513
3305
  first = preprocessJoinArg(query, first);
3514
3306
  if (typeof first === "object") {
3515
- if (require2 && isQueryNone(first)) {
3307
+ if (require && isQueryNone(first)) {
3516
3308
  return _queryNone(query);
3517
3309
  }
3518
3310
  const q2 = first;
@@ -3538,12 +3330,11 @@ const _join = (query, require2, type, first, args) => {
3538
3330
  batchParsers = r.q.batchParsers;
3539
3331
  computeds = r.q.computeds;
3540
3332
  } else {
3541
- const w = (_a = query.q.withShapes) == null ? void 0 : _a[joinKey];
3542
- shape = w == null ? void 0 : w.shape;
3543
- computeds = w == null ? void 0 : w.computeds;
3333
+ const w = query.q.withShapes?.[joinKey];
3334
+ shape = w?.shape;
3335
+ computeds = w?.computeds;
3544
3336
  if (shape) {
3545
- if (!require2)
3546
- shape = __spreadValues$i({}, shape);
3337
+ if (!require) shape = { ...shape };
3547
3338
  const arg = { parsers: {} };
3548
3339
  for (const key in shape) {
3549
3340
  addColumnParserToQuery(arg, key, shape[key]);
@@ -3558,7 +3349,7 @@ const _join = (query, require2, type, first, args) => {
3558
3349
  joinSubQuery
3559
3350
  );
3560
3351
  if (joinKey && "s" in joinArgs && joinArgs.s) {
3561
- const j = "j" in joinArgs ? (_b = joinArgs.r) != null ? _b : joinArgs.j : "r" in joinArgs ? joinArgs.r : joinArgs.q;
3352
+ const j = "j" in joinArgs ? joinArgs.r ?? joinArgs.j : "r" in joinArgs ? joinArgs.r : joinArgs.q;
3562
3353
  if (j.q.select || !j.q.selectAllColumns) {
3563
3354
  const shape2 = getShapeFromSelect(j, true);
3564
3355
  setQueryObjectValue(
@@ -3574,7 +3365,7 @@ const _join = (query, require2, type, first, args) => {
3574
3365
  j.q.parsers
3575
3366
  );
3576
3367
  if (j.q.batchParsers) {
3577
- ((_d = (_c = query.q).joinedBatchParsers) != null ? _d : _c.joinedBatchParsers = {})[joinKey] = j.q.batchParsers;
3368
+ ((_a = query.q).joinedBatchParsers ?? (_a.joinedBatchParsers = {}))[joinKey] = j.q.batchParsers;
3578
3369
  }
3579
3370
  setQueryObjectValue(
3580
3371
  query,
@@ -3592,7 +3383,7 @@ const _join = (query, require2, type, first, args) => {
3592
3383
  computeds
3593
3384
  );
3594
3385
  }
3595
- } else if (require2 && "r" in joinArgs && isQueryNone(joinArgs.r)) {
3386
+ } else if (require && "r" in joinArgs && isQueryNone(joinArgs.r)) {
3596
3387
  return _queryNone(query);
3597
3388
  } else {
3598
3389
  addAllShapesAndParsers(
@@ -3614,13 +3405,12 @@ const _join = (query, require2, type, first, args) => {
3614
3405
  return q;
3615
3406
  };
3616
3407
  const addAllShapesAndParsers = (query, joinKey, shape, parsers, batchParsers, computeds) => {
3617
- var _a, _b;
3618
- if (!joinKey)
3619
- return;
3408
+ var _a;
3409
+ if (!joinKey) return;
3620
3410
  setQueryObjectValue(query, "joinedShapes", joinKey, shape);
3621
3411
  setQueryObjectValue(query, "joinedParsers", joinKey, parsers);
3622
3412
  if (batchParsers) {
3623
- ((_b = (_a = query.q).joinedBatchParsers) != null ? _b : _a.joinedBatchParsers = {})[joinKey] = batchParsers;
3413
+ ((_a = query.q).joinedBatchParsers ?? (_a.joinedBatchParsers = {}))[joinKey] = batchParsers;
3624
3414
  }
3625
3415
  setQueryObjectValue(
3626
3416
  query,
@@ -3630,7 +3420,7 @@ const addAllShapesAndParsers = (query, joinKey, shape, parsers, batchParsers, co
3630
3420
  );
3631
3421
  };
3632
3422
  const _joinLateral = (self, type, arg, cb, as) => {
3633
- var _a, _b, _c, _d, _e, _f, _g;
3423
+ var _a, _b, _c;
3634
3424
  const q = self;
3635
3425
  let relation;
3636
3426
  if (typeof arg === "string") {
@@ -3638,15 +3428,16 @@ const _joinLateral = (self, type, arg, cb, as) => {
3638
3428
  if (relation) {
3639
3429
  arg = _clone(relation.relationConfig.query);
3640
3430
  } else {
3641
- const w = (_a = q.q.withShapes) == null ? void 0 : _a[arg];
3431
+ const w = q.q.withShapes?.[arg];
3642
3432
  if (w) {
3643
3433
  const t = Object.create(q.queryBuilder);
3644
3434
  t.table = arg;
3645
3435
  t.shape = w.shape;
3646
3436
  t.computeds = w.computeds;
3647
- t.q = __spreadProps$9(__spreadValues$i({}, t.q), {
3437
+ t.q = {
3438
+ ...t.q,
3648
3439
  shape: w.shape
3649
- });
3440
+ };
3650
3441
  t.baseQuery = t;
3651
3442
  arg = t;
3652
3443
  }
@@ -3655,7 +3446,7 @@ const _joinLateral = (self, type, arg, cb, as) => {
3655
3446
  const query = arg;
3656
3447
  query.q.joinTo = q;
3657
3448
  const joinedAs = getQueryAs(q);
3658
- ((_c = (_b = query.q).joinedShapes) != null ? _c : _b.joinedShapes = {})[joinedAs] = q.q.shape;
3449
+ ((_a = query.q).joinedShapes ?? (_a.joinedShapes = {}))[joinedAs] = q.q.shape;
3659
3450
  let result = resolveSubQueryCallback(query, cb);
3660
3451
  if (relation) {
3661
3452
  result = relation.relationConfig.joinQuery(
@@ -3669,11 +3460,11 @@ const _joinLateral = (self, type, arg, cb, as) => {
3669
3460
  setQueryObjectValue(q, "joinedShapes", joinKey, shape);
3670
3461
  setQueryObjectValue(q, "joinedParsers", joinKey, result.q.parsers);
3671
3462
  if (result.q.batchParsers) {
3672
- ((_e = (_d = q.q).joinedBatchParsers) != null ? _e : _d.joinedBatchParsers = {})[joinKey] = result.q.batchParsers;
3463
+ ((_b = q.q).joinedBatchParsers ?? (_b.joinedBatchParsers = {}))[joinKey] = result.q.batchParsers;
3673
3464
  }
3674
3465
  }
3675
3466
  as || (as = getQueryAs(result));
3676
- ((_g = (_f = q.q).joinedComputeds) != null ? _g : _f.joinedComputeds = {})[as] = result.q.computeds;
3467
+ ((_c = q.q).joinedComputeds ?? (_c.joinedComputeds = {}))[as] = result.q.computeds;
3677
3468
  return pushQueryValue(q, "join", [type, result, as]);
3678
3469
  };
3679
3470
 
@@ -3737,11 +3528,9 @@ const parsePostgresArray = (source, entries, transform) => {
3737
3528
  let pos = 0;
3738
3529
  if (source[0] === "[") {
3739
3530
  pos = source.indexOf("=") + 1;
3740
- if (!pos)
3741
- pos = source.length;
3531
+ if (!pos) pos = source.length;
3742
3532
  }
3743
- if (source[pos] === "{")
3744
- pos++;
3533
+ if (source[pos] === "{") pos++;
3745
3534
  let recorded = "";
3746
3535
  while (pos < source.length) {
3747
3536
  const character = source[pos++];
@@ -3762,8 +3551,7 @@ const parsePostgresArray = (source, entries, transform) => {
3762
3551
  while (pos < source.length) {
3763
3552
  let char;
3764
3553
  while ((char = source[pos++]) === "\\") {
3765
- if (!(esc = !esc))
3766
- rec += "\\";
3554
+ if (!(esc = !esc)) rec += "\\";
3767
3555
  }
3768
3556
  if (esc) {
3769
3557
  esc = false;
@@ -4050,20 +3838,14 @@ const defaultSchemaConfig = {
4050
3838
 
4051
3839
  const escape = (value, migration, nested) => {
4052
3840
  const type = typeof value;
4053
- if (type === "number" || type === "bigint")
4054
- return String(value);
4055
- else if (type === "string")
4056
- return escapeString(value);
4057
- else if (type === "boolean")
4058
- return value ? "true" : "false";
4059
- else if (value instanceof Date)
4060
- return `'${value.toISOString()}'`;
3841
+ if (type === "number" || type === "bigint") return String(value);
3842
+ else if (type === "string") return escapeString(value);
3843
+ else if (type === "boolean") return value ? "true" : "false";
3844
+ else if (value instanceof Date) return `'${value.toISOString()}'`;
4061
3845
  else if (Array.isArray(value))
4062
3846
  return migration && nested && !value.length ? "" : (migration ? nested ? "{" : "'{" : nested ? "[" : "ARRAY[") + value.map((el) => escape(el, migration, true)).join(",") + (migration ? nested ? "}" : "}'" : "]");
4063
- else if (value === null || value === void 0)
4064
- return "NULL";
4065
- else
4066
- return escapeString(JSON.stringify(value));
3847
+ else if (value === null || value === void 0) return "NULL";
3848
+ else return escapeString(JSON.stringify(value));
4067
3849
  };
4068
3850
  const escapeForLog = (value) => escape(value);
4069
3851
  const escapeForMigration = (value) => escape(value, true);
@@ -4073,15 +3855,14 @@ const makeMessage = (colors, timeColor, time, sqlColor, sql, valuesColor, values
4073
3855
  const elapsed = process.hrtime(time);
4074
3856
  const formattedTime = `(${elapsed[0] ? `${elapsed[0]}s ` : ""}${(elapsed[1] / 1e6).toFixed(1)}ms)`;
4075
3857
  const result = `${colors ? timeColor(formattedTime) : formattedTime} ${colors ? sqlColor(sql) : sql}`;
4076
- if (!(values == null ? void 0 : values.length)) {
3858
+ if (!values?.length) {
4077
3859
  return result;
4078
3860
  }
4079
3861
  const formattedValues = `[${values.map(escapeForLog).join(", ")}]`;
4080
3862
  return `${result} ${colors ? valuesColor(formattedValues) : formattedValues}`;
4081
3863
  };
4082
3864
  const logParamToLogObject = (logger, log) => {
4083
- if (!log)
4084
- return;
3865
+ if (!log) return;
4085
3866
  const logObject = Object.assign(
4086
3867
  {
4087
3868
  colors: true,
@@ -4129,25 +3910,6 @@ class QueryLog {
4129
3910
  }
4130
3911
  }
4131
3912
 
4132
- var __defProp$h = Object.defineProperty;
4133
- var __defProps$8 = Object.defineProperties;
4134
- var __getOwnPropDescs$8 = Object.getOwnPropertyDescriptors;
4135
- var __getOwnPropSymbols$i = Object.getOwnPropertySymbols;
4136
- var __hasOwnProp$i = Object.prototype.hasOwnProperty;
4137
- var __propIsEnum$i = Object.prototype.propertyIsEnumerable;
4138
- var __defNormalProp$h = (obj, key, value) => key in obj ? __defProp$h(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
4139
- var __spreadValues$h = (a, b) => {
4140
- for (var prop in b || (b = {}))
4141
- if (__hasOwnProp$i.call(b, prop))
4142
- __defNormalProp$h(a, prop, b[prop]);
4143
- if (__getOwnPropSymbols$i)
4144
- for (var prop of __getOwnPropSymbols$i(b)) {
4145
- if (__propIsEnum$i.call(b, prop))
4146
- __defNormalProp$h(a, prop, b[prop]);
4147
- }
4148
- return a;
4149
- };
4150
- var __spreadProps$8 = (a, b) => __defProps$8(a, __getOwnPropDescs$8(b));
4151
3913
  const commitSql$1 = {
4152
3914
  text: "COMMIT"
4153
3915
  };
@@ -4171,7 +3933,6 @@ const _afterCommitError = (result, hookResults, catchAfterCommitError) => {
4171
3933
  };
4172
3934
  class Transaction {
4173
3935
  async transaction(cbOrOptions, cb) {
4174
- var _a;
4175
3936
  let options;
4176
3937
  let fn;
4177
3938
  if (typeof cbOrOptions === "function") {
@@ -4184,15 +3945,13 @@ class Transaction {
4184
3945
  const sql = {
4185
3946
  values: orchidCore.emptyArray
4186
3947
  };
4187
- const log = options.log !== void 0 ? (_a = this.q.log) != null ? _a : logParamToLogObject(this.q.logger, options.log) : this.q.log;
3948
+ const log = options.log !== void 0 ? this.q.log ?? logParamToLogObject(this.q.logger, options.log) : this.q.log;
4188
3949
  let logData;
4189
3950
  let trx = this.internal.transactionStorage.getStore();
4190
3951
  const transactionId = trx ? trx.transactionId + 1 : 0;
4191
3952
  const callback = (adapter) => {
4192
- if (log)
4193
- log.afterQuery(sql, logData);
4194
- if (log)
4195
- logData = log.beforeQuery(commitSql$1);
3953
+ if (log) log.afterQuery(sql, logData);
3954
+ if (log) logData = log.beforeQuery(commitSql$1);
4196
3955
  if (trx) {
4197
3956
  trx.transactionId = transactionId;
4198
3957
  return fn();
@@ -4208,15 +3967,12 @@ class Transaction {
4208
3967
  };
4209
3968
  if (!trx) {
4210
3969
  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` : ""}`;
4211
- if (log)
4212
- logData = log.beforeQuery(sql);
3970
+ if (log) logData = log.beforeQuery(sql);
4213
3971
  const result = await this.q.adapter.transaction(sql, callback).catch((err) => {
4214
- if (log)
4215
- log.afterQuery(rollbackSql$1, logData);
3972
+ if (log) log.afterQuery(rollbackSql$1, logData);
4216
3973
  throw err;
4217
3974
  });
4218
- if (log)
4219
- log.afterQuery(commitSql$1, logData);
3975
+ if (log) log.afterQuery(commitSql$1, logData);
4220
3976
  await runAfterCommit(
4221
3977
  trx.afterCommit,
4222
3978
  result
@@ -4225,8 +3981,7 @@ class Transaction {
4225
3981
  } else {
4226
3982
  try {
4227
3983
  sql.text = `SAVEPOINT "${transactionId}"`;
4228
- if (log)
4229
- logData = log.beforeQuery(sql);
3984
+ if (log) logData = log.beforeQuery(sql);
4230
3985
  const { adapter } = trx;
4231
3986
  await adapter.query(sql);
4232
3987
  let result;
@@ -4234,19 +3989,15 @@ class Transaction {
4234
3989
  result = await callback(adapter);
4235
3990
  } catch (err) {
4236
3991
  sql.text = `ROLLBACK TO SAVEPOINT "${transactionId}"`;
4237
- if (log)
4238
- logData = log.beforeQuery(sql);
3992
+ if (log) logData = log.beforeQuery(sql);
4239
3993
  await adapter.query(sql);
4240
- if (log)
4241
- log.afterQuery(sql, logData);
3994
+ if (log) log.afterQuery(sql, logData);
4242
3995
  throw err;
4243
3996
  }
4244
3997
  sql.text = `RELEASE SAVEPOINT "${transactionId}"`;
4245
- if (log)
4246
- logData = log.beforeQuery(sql);
3998
+ if (log) logData = log.beforeQuery(sql);
4247
3999
  await adapter.query(sql);
4248
- if (log)
4249
- log.afterQuery(sql, logData);
4000
+ if (log) log.afterQuery(sql, logData);
4250
4001
  if (transactionId === trx.testTransactionCount) {
4251
4002
  await runAfterCommit(
4252
4003
  trx.afterCommit,
@@ -4281,8 +4032,7 @@ class Transaction {
4281
4032
  */
4282
4033
  ensureTransaction(cb) {
4283
4034
  const trx = this.internal.transactionStorage.getStore();
4284
- if (trx)
4285
- return cb();
4035
+ if (trx) return cb();
4286
4036
  return Transaction.prototype.transaction.call(this, cb);
4287
4037
  }
4288
4038
  isInTransaction() {
@@ -4314,9 +4064,10 @@ const runAfterCommit = async (afterCommit, result) => {
4314
4064
  let r = 0;
4315
4065
  for (let i = 0, len = afterCommit.length; i < len; i += 3) {
4316
4066
  for (const fn of afterCommit[i + 2]) {
4317
- resultsWithNames.push(__spreadProps$8(__spreadValues$h({}, hookResults[r++]), {
4067
+ resultsWithNames.push({
4068
+ ...hookResults[r++],
4318
4069
  name: fn.name
4319
- }));
4070
+ });
4320
4071
  }
4321
4072
  }
4322
4073
  _afterCommitError(result, resultsWithNames, catchAfterCommitError);
@@ -4336,7 +4087,6 @@ const applyBatchTransforms = (query, batches) => {
4336
4087
  }
4337
4088
  };
4338
4089
  const finalizeNestedHookSelect = (batches, returnType, tempColumns, renames, key) => {
4339
- var _a;
4340
4090
  if (renames) {
4341
4091
  for (const { data } of batches) {
4342
4092
  for (const record of data) {
@@ -4348,7 +4098,7 @@ const finalizeNestedHookSelect = (batches, returnType, tempColumns, renames, key
4348
4098
  }
4349
4099
  }
4350
4100
  }
4351
- if (tempColumns == null ? void 0 : tempColumns.size) {
4101
+ if (tempColumns?.size) {
4352
4102
  for (const { data } of batches) {
4353
4103
  for (const record of data) {
4354
4104
  if (record) {
@@ -4371,30 +4121,11 @@ const finalizeNestedHookSelect = (batches, returnType, tempColumns, renames, key
4371
4121
  }
4372
4122
  } else if (returnType === "value" || returnType === "valueOrThrow") {
4373
4123
  for (const item of batches) {
4374
- item.parent[item.key] = (_a = item.data[0]) == null ? void 0 : _a[key];
4124
+ item.parent[item.key] = item.data[0]?.[key];
4375
4125
  }
4376
4126
  }
4377
4127
  };
4378
4128
 
4379
- var __defProp$g = Object.defineProperty;
4380
- var __defProps$7 = Object.defineProperties;
4381
- var __getOwnPropDescs$7 = Object.getOwnPropertyDescriptors;
4382
- var __getOwnPropSymbols$h = Object.getOwnPropertySymbols;
4383
- var __hasOwnProp$h = Object.prototype.hasOwnProperty;
4384
- var __propIsEnum$h = Object.prototype.propertyIsEnumerable;
4385
- var __defNormalProp$g = (obj, key, value) => key in obj ? __defProp$g(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
4386
- var __spreadValues$g = (a, b) => {
4387
- for (var prop in b || (b = {}))
4388
- if (__hasOwnProp$h.call(b, prop))
4389
- __defNormalProp$g(a, prop, b[prop]);
4390
- if (__getOwnPropSymbols$h)
4391
- for (var prop of __getOwnPropSymbols$h(b)) {
4392
- if (__propIsEnum$h.call(b, prop))
4393
- __defNormalProp$g(a, prop, b[prop]);
4394
- }
4395
- return a;
4396
- };
4397
- var __spreadProps$7 = (a, b) => __defProps$7(a, __getOwnPropDescs$7(b));
4398
4129
  class ComputedColumn {
4399
4130
  constructor(kind, deps, fn) {
4400
4131
  this.kind = kind;
@@ -4411,9 +4142,10 @@ const applyComputedColumns = (q, fn) => {
4411
4142
  for (const key in computed) {
4412
4143
  const item = computed[key];
4413
4144
  if (item instanceof ComputedColumn) {
4414
- q.q.computeds = __spreadProps$7(__spreadValues$g({}, q.q.computeds), {
4145
+ q.q.computeds = {
4146
+ ...q.q.computeds,
4415
4147
  [key]: item
4416
- });
4148
+ };
4417
4149
  } else {
4418
4150
  const data = (q.shape[key] = item.result.value || UnknownColumn.instance).data;
4419
4151
  data.computed = item;
@@ -4435,7 +4167,7 @@ const processComputedResult = (query, result) => {
4435
4167
  if (Array.isArray(res)) {
4436
4168
  saveBatchComputed(key, result, res);
4437
4169
  } else {
4438
- (promises != null ? promises : promises = []).push(
4170
+ (promises ?? (promises = [])).push(
4439
4171
  res.then(
4440
4172
  (res2) => saveBatchComputed(key, result, res2)
4441
4173
  )
@@ -4443,8 +4175,7 @@ const processComputedResult = (query, result) => {
4443
4175
  }
4444
4176
  }
4445
4177
  }
4446
- if (!promises)
4447
- return;
4178
+ if (!promises) return;
4448
4179
  return Promise.all(promises);
4449
4180
  };
4450
4181
  const processComputedBatches = (query, batches, originalReturnType, returnType, tempColumns, renames, key) => {
@@ -4480,7 +4211,7 @@ const processComputedBatches = (query, batches, originalReturnType, returnType,
4480
4211
  if (Array.isArray(res)) {
4481
4212
  saveBatchComputed(key2, data, res, blanks);
4482
4213
  } else {
4483
- (promises != null ? promises : promises = []).push(
4214
+ (promises ?? (promises = [])).push(
4484
4215
  res.then(
4485
4216
  (res2) => saveBatchComputed(key2, data, res2, blanks)
4486
4217
  )
@@ -4489,8 +4220,7 @@ const processComputedBatches = (query, batches, originalReturnType, returnType,
4489
4220
  }
4490
4221
  }
4491
4222
  }
4492
- if (!promises)
4493
- return;
4223
+ if (!promises) return;
4494
4224
  return Promise.all(promises).then(() => {
4495
4225
  finalizeNestedHookSelect(
4496
4226
  batches,
@@ -4504,7 +4234,7 @@ const processComputedBatches = (query, batches, originalReturnType, returnType,
4504
4234
  };
4505
4235
  const saveBatchComputed = (key, result, res, blanks) => {
4506
4236
  const len = result.length;
4507
- const actual = res.length + ((blanks == null ? void 0 : blanks.size) || 0);
4237
+ const actual = res.length + (blanks?.size || 0);
4508
4238
  if (len !== actual) {
4509
4239
  throw new Error(
4510
4240
  `Incorrect length of batch computed result for column ${key}. Expected ${len}, received ${actual}.`
@@ -4523,25 +4253,6 @@ const saveBatchComputed = (key, result, res, blanks) => {
4523
4253
  }
4524
4254
  };
4525
4255
 
4526
- var __defProp$f = Object.defineProperty;
4527
- var __defProps$6 = Object.defineProperties;
4528
- var __getOwnPropDescs$6 = Object.getOwnPropertyDescriptors;
4529
- var __getOwnPropSymbols$g = Object.getOwnPropertySymbols;
4530
- var __hasOwnProp$g = Object.prototype.hasOwnProperty;
4531
- var __propIsEnum$g = Object.prototype.propertyIsEnumerable;
4532
- var __defNormalProp$f = (obj, key, value) => key in obj ? __defProp$f(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
4533
- var __spreadValues$f = (a, b) => {
4534
- for (var prop in b || (b = {}))
4535
- if (__hasOwnProp$g.call(b, prop))
4536
- __defNormalProp$f(a, prop, b[prop]);
4537
- if (__getOwnPropSymbols$g)
4538
- for (var prop of __getOwnPropSymbols$g(b)) {
4539
- if (__propIsEnum$g.call(b, prop))
4540
- __defNormalProp$f(a, prop, b[prop]);
4541
- }
4542
- return a;
4543
- };
4544
- var __spreadProps$6 = (a, b) => __defProps$6(a, __getOwnPropDescs$6(b));
4545
4256
  const queryMethodByReturnType = {
4546
4257
  undefined: "query",
4547
4258
  all: "query",
@@ -4564,11 +4275,9 @@ let getThen;
4564
4275
  if (process.versions.bun) {
4565
4276
  getThen = function() {
4566
4277
  queryError = new Error();
4567
- if (!this.internal)
4568
- return maybeWrappedThen;
4278
+ if (!this.internal) return maybeWrappedThen;
4569
4279
  const trx = this.internal.transactionStorage.getStore();
4570
- if (!trx)
4571
- return maybeWrappedThen;
4280
+ if (!trx) return maybeWrappedThen;
4572
4281
  return (resolve, reject) => {
4573
4282
  return this.internal.transactionStorage.run(trx, () => {
4574
4283
  return maybeWrappedThen.call(this, resolve, reject);
@@ -4630,7 +4339,7 @@ function maybeWrappedThen(resolve, reject) {
4630
4339
  } else {
4631
4340
  return then(
4632
4341
  this,
4633
- (trx == null ? void 0 : trx.adapter) || this.q.adapter,
4342
+ trx?.adapter || this.q.adapter,
4634
4343
  trx,
4635
4344
  beforeHooks,
4636
4345
  afterHooks,
@@ -4647,11 +4356,10 @@ const callAfterHook = function(cb) {
4647
4356
  };
4648
4357
  const beginSql = { text: "BEGIN" };
4649
4358
  const then = async (q, adapter, trx, beforeHooks, afterHooks, afterCommitHooks, resolve, reject) => {
4650
- var _a, _b, _c;
4651
4359
  const { q: query } = q;
4652
4360
  let sql;
4653
4361
  let logData;
4654
- const log = (_a = trx == null ? void 0 : trx.log) != null ? _a : query.log;
4362
+ const log = trx?.log ?? query.log;
4655
4363
  const localError = queryError;
4656
4364
  try {
4657
4365
  if (beforeHooks || query.before) {
@@ -4687,11 +4395,9 @@ const then = async (q, adapter, trx, beforeHooks, afterHooks, afterCommitHooks,
4687
4395
  } else {
4688
4396
  const queryMethod = queryMethodByReturnType[tempReturnType];
4689
4397
  if (!trx) {
4690
- if (log)
4691
- logData = log.beforeQuery(beginSql);
4398
+ if (log) logData = log.beforeQuery(beginSql);
4692
4399
  await adapter.arrays(beginSql);
4693
- if (log)
4694
- log.afterQuery(beginSql, logData);
4400
+ if (log) log.afterQuery(beginSql, logData);
4695
4401
  }
4696
4402
  for (const item of sql.batch) {
4697
4403
  sql = item;
@@ -4711,11 +4417,9 @@ const then = async (q, adapter, trx, beforeHooks, afterHooks, afterCommitHooks,
4711
4417
  }
4712
4418
  }
4713
4419
  if (!trx) {
4714
- if (log)
4715
- logData = log.beforeQuery(commitSql$1);
4420
+ if (log) logData = log.beforeQuery(commitSql$1);
4716
4421
  await adapter.arrays(commitSql$1);
4717
- if (log)
4718
- log.afterQuery(commitSql$1, logData);
4422
+ if (log) log.afterQuery(commitSql$1, logData);
4719
4423
  }
4720
4424
  if (query.patchResult) {
4721
4425
  await query.patchResult(q, queryResult);
@@ -4730,9 +4434,8 @@ const then = async (q, adapter, trx, beforeHooks, afterHooks, afterCommitHooks,
4730
4434
  if (hookSelect) {
4731
4435
  for (const column of hookSelect.keys()) {
4732
4436
  const as = hookSelect.get(column).as;
4733
- if (as)
4734
- (renames != null ? renames : renames = {})[column] = as;
4735
- (_b = tempColumns != null ? tempColumns : tempColumns = /* @__PURE__ */ new Set()) == null ? void 0 : _b.add(as || column);
4437
+ if (as) (renames ?? (renames = {}))[column] = as;
4438
+ (tempColumns ?? (tempColumns = /* @__PURE__ */ new Set()))?.add(as || column);
4736
4439
  }
4737
4440
  if (renames) {
4738
4441
  for (const record of result) {
@@ -4745,8 +4448,7 @@ const then = async (q, adapter, trx, beforeHooks, afterHooks, afterCommitHooks,
4745
4448
  }
4746
4449
  if (query.selectedComputeds) {
4747
4450
  const promise = processComputedResult(query, result);
4748
- if (promise)
4749
- await promise;
4451
+ if (promise) await promise;
4750
4452
  }
4751
4453
  }
4752
4454
  const hasAfterHook = afterHooks || afterCommitHooks || query.after;
@@ -4764,7 +4466,7 @@ const then = async (q, adapter, trx, beforeHooks, afterHooks, afterCommitHooks,
4764
4466
  if (afterCommitHooks) {
4765
4467
  if (trx && // when inside test transactions, push to a transaction only unless it's the outer user transaction.
4766
4468
  (!trx.testTransactionCount || trx.transactionId + 1 > trx.testTransactionCount)) {
4767
- ((_c = trx.afterCommit) != null ? _c : trx.afterCommit = []).push(
4469
+ (trx.afterCommit ?? (trx.afterCommit = [])).push(
4768
4470
  result,
4769
4471
  q,
4770
4472
  afterCommitHooks
@@ -4784,7 +4486,8 @@ const then = async (q, adapter, trx, beforeHooks, afterHooks, afterCommitHooks,
4784
4486
  if (hookResults.some((result2) => result2.status === "rejected")) {
4785
4487
  _afterCommitError(
4786
4488
  result,
4787
- hookResults.map((result2, i) => __spreadProps$6(__spreadValues$f({}, result2), {
4489
+ hookResults.map((result2, i) => ({
4490
+ ...result2,
4788
4491
  name: afterCommitHooks[i].name
4789
4492
  })),
4790
4493
  q.q.catchAfterCommitError
@@ -4818,7 +4521,7 @@ const then = async (q, adapter, trx, beforeHooks, afterHooks, afterCommitHooks,
4818
4521
  if (query.transform) {
4819
4522
  result = orchidCore.applyTransforms(returnType, query.transform, result);
4820
4523
  }
4821
- return resolve == null ? void 0 : resolve(result);
4524
+ return resolve?.(result);
4822
4525
  } catch (err) {
4823
4526
  let error;
4824
4527
  if (err instanceof pg.DatabaseError) {
@@ -4844,7 +4547,7 @@ const then = async (q, adapter, trx, beforeHooks, afterHooks, afterCommitHooks,
4844
4547
  if (log && sql) {
4845
4548
  log.onError(error, sql, logData);
4846
4549
  }
4847
- return reject == null ? void 0 : reject(error);
4550
+ return reject?.(error);
4848
4551
  }
4849
4552
  };
4850
4553
  const assignError = (to, from) => {
@@ -4870,7 +4573,6 @@ const assignError = (to, from) => {
4870
4573
  return to;
4871
4574
  };
4872
4575
  const handleResult = (q, returnType, result, isSubQuery) => {
4873
- var _a, _b;
4874
4576
  const { parsers } = q.q;
4875
4577
  switch (returnType) {
4876
4578
  case "all": {
@@ -4887,20 +4589,16 @@ const handleResult = (q, returnType, result, isSubQuery) => {
4887
4589
  }
4888
4590
  case "one": {
4889
4591
  const { rows } = result;
4890
- if (!rows.length)
4891
- return;
4592
+ if (!rows.length) return;
4892
4593
  const promise = parseBatch(q, result);
4893
- if (parsers)
4894
- parseRecord(parsers, rows[0]);
4594
+ if (parsers) parseRecord(parsers, rows[0]);
4895
4595
  return promise ? promise.then(() => rows[0]) : rows[0];
4896
4596
  }
4897
4597
  case "oneOrThrow": {
4898
4598
  const { rows } = result;
4899
- if (!rows.length)
4900
- throw new NotFoundError(q);
4599
+ if (!rows.length) throw new NotFoundError(q);
4901
4600
  const promise = parseBatch(q, result);
4902
- if (parsers)
4903
- parseRecord(parsers, rows[0]);
4601
+ if (parsers) parseRecord(parsers, rows[0]);
4904
4602
  return promise ? promise.then(() => rows[0]) : rows[0];
4905
4603
  }
4906
4604
  case "rows": {
@@ -4908,8 +4606,7 @@ const handleResult = (q, returnType, result, isSubQuery) => {
4908
4606
  const promise = parseBatch(q, result);
4909
4607
  if (promise) {
4910
4608
  return promise.then(() => {
4911
- if (parsers)
4912
- parseRows(parsers, result.fields, rows);
4609
+ if (parsers) parseRows(parsers, result.fields, rows);
4913
4610
  return rows;
4914
4611
  });
4915
4612
  } else if (parsers) {
@@ -4934,11 +4631,10 @@ const handleResult = (q, returnType, result, isSubQuery) => {
4934
4631
  const promise = parseBatch(q, result);
4935
4632
  if (promise) {
4936
4633
  return promise.then(() => {
4937
- var _a2;
4938
- return ((_a2 = rows[0]) == null ? void 0 : _a2[0]) !== void 0 ? parseValue(rows[0][0], parsers) : q.q.notFoundDefault;
4634
+ return rows[0]?.[0] !== void 0 ? parseValue(rows[0][0], parsers) : q.q.notFoundDefault;
4939
4635
  });
4940
4636
  }
4941
- return ((_a = rows[0]) == null ? void 0 : _a[0]) !== void 0 ? parseValue(rows[0][0], parsers) : q.q.notFoundDefault;
4637
+ return rows[0]?.[0] !== void 0 ? parseValue(rows[0][0], parsers) : q.q.notFoundDefault;
4942
4638
  }
4943
4639
  case "valueOrThrow": {
4944
4640
  if (q.q.returning) {
@@ -4951,14 +4647,11 @@ const handleResult = (q, returnType, result, isSubQuery) => {
4951
4647
  const promise = parseBatch(q, result);
4952
4648
  if (promise) {
4953
4649
  return promise.then(() => {
4954
- var _a2;
4955
- if (((_a2 = rows[0]) == null ? void 0 : _a2[0]) === void 0)
4956
- throw new NotFoundError(q);
4650
+ if (rows[0]?.[0] === void 0) throw new NotFoundError(q);
4957
4651
  return parseValue(rows[0][0], parsers);
4958
4652
  });
4959
4653
  }
4960
- if (((_b = rows[0]) == null ? void 0 : _b[0]) === void 0)
4961
- throw new NotFoundError(q);
4654
+ if (rows[0]?.[0] === void 0) throw new NotFoundError(q);
4962
4655
  return parseValue(rows[0][0], parsers);
4963
4656
  }
4964
4657
  case "void": {
@@ -4971,8 +4664,7 @@ const parseBatch = (q, queryResult) => {
4971
4664
  if (q.q.batchParsers) {
4972
4665
  for (const parser of q.q.batchParsers) {
4973
4666
  const res = parser.fn(parser.path, queryResult);
4974
- if (res)
4975
- (promises != null ? promises : promises = []).push(res);
4667
+ if (res) (promises ?? (promises = [])).push(res);
4976
4668
  }
4977
4669
  }
4978
4670
  return promises && Promise.all(promises);
@@ -4996,7 +4688,7 @@ const parseRows = (parsers, fields, rows) => {
4996
4688
  }
4997
4689
  };
4998
4690
  const parsePluck = (parsers, isSubQuery, rows) => {
4999
- const pluck = parsers == null ? void 0 : parsers.pluck;
4691
+ const pluck = parsers?.pluck;
5000
4692
  if (pluck) {
5001
4693
  for (let i = 0; i < rows.length; i++) {
5002
4694
  rows[i] = pluck(isSubQuery ? rows[i] : rows[i][0]);
@@ -5008,25 +4700,22 @@ const parsePluck = (parsers, isSubQuery, rows) => {
5008
4700
  }
5009
4701
  };
5010
4702
  const parseValue = (value, parsers) => {
5011
- const parser = parsers == null ? void 0 : parsers[orchidCore.getValueKey];
4703
+ const parser = parsers?.[orchidCore.getValueKey];
5012
4704
  return parser ? parser(value) : value;
5013
4705
  };
5014
4706
  const filterResult = (q, returnType, queryResult, result, tempColumns, hasAfterHook) => {
5015
- var _a;
5016
4707
  if (returnType === "all") {
5017
4708
  return filterAllResult(result, tempColumns, hasAfterHook);
5018
4709
  }
5019
4710
  if (returnType === "oneOrThrow" || returnType === "one") {
5020
4711
  let row = result[0];
5021
4712
  if (!row) {
5022
- if (returnType === "oneOrThrow")
5023
- throw new NotFoundError(q);
4713
+ if (returnType === "oneOrThrow") throw new NotFoundError(q);
5024
4714
  return void 0;
5025
- } else if (!(tempColumns == null ? void 0 : tempColumns.size)) {
4715
+ } else if (!tempColumns?.size) {
5026
4716
  return row;
5027
4717
  } else {
5028
- if (hasAfterHook)
5029
- row = __spreadValues$f({}, row);
4718
+ if (hasAfterHook) row = { ...row };
5030
4719
  for (const column of tempColumns) {
5031
4720
  delete row[column];
5032
4721
  }
@@ -5034,15 +4723,14 @@ const filterResult = (q, returnType, queryResult, result, tempColumns, hasAfterH
5034
4723
  }
5035
4724
  }
5036
4725
  if (returnType === "value") {
5037
- return (_a = result[0]) == null ? void 0 : _a[getFirstResultKey(q, queryResult)];
4726
+ return result[0]?.[getFirstResultKey(q, queryResult)];
5038
4727
  }
5039
4728
  if (returnType === "valueOrThrow") {
5040
4729
  if (q.q.returning) {
5041
4730
  return queryResult.rowCount;
5042
4731
  }
5043
4732
  const row = result[0];
5044
- if (!row)
5045
- throw new NotFoundError(q);
4733
+ if (!row) throw new NotFoundError(q);
5046
4734
  return row[getFirstResultKey(q, queryResult)];
5047
4735
  }
5048
4736
  if (returnType === "pluck") {
@@ -5066,10 +4754,10 @@ const getFirstResultKey = (q, queryResult) => {
5066
4754
  return;
5067
4755
  };
5068
4756
  const filterAllResult = (result, tempColumns, hasAfterHook) => {
5069
- if (tempColumns == null ? void 0 : tempColumns.size) {
4757
+ if (tempColumns?.size) {
5070
4758
  if (hasAfterHook) {
5071
4759
  return result.map((data) => {
5072
- const record = __spreadValues$f({}, data);
4760
+ const record = { ...data };
5073
4761
  for (const key of tempColumns) {
5074
4762
  delete record[key];
5075
4763
  }
@@ -5086,38 +4774,18 @@ const filterAllResult = (result, tempColumns, hasAfterHook) => {
5086
4774
  return result;
5087
4775
  };
5088
4776
 
5089
- var __defProp$e = Object.defineProperty;
5090
- var __defProps$5 = Object.defineProperties;
5091
- var __getOwnPropDescs$5 = Object.getOwnPropertyDescriptors;
5092
- var __getOwnPropSymbols$f = Object.getOwnPropertySymbols;
5093
- var __hasOwnProp$f = Object.prototype.hasOwnProperty;
5094
- var __propIsEnum$f = Object.prototype.propertyIsEnumerable;
5095
- var __defNormalProp$e = (obj, key, value) => key in obj ? __defProp$e(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
5096
- var __spreadValues$e = (a, b) => {
5097
- for (var prop in b || (b = {}))
5098
- if (__hasOwnProp$f.call(b, prop))
5099
- __defNormalProp$e(a, prop, b[prop]);
5100
- if (__getOwnPropSymbols$f)
5101
- for (var prop of __getOwnPropSymbols$f(b)) {
5102
- if (__propIsEnum$f.call(b, prop))
5103
- __defNormalProp$e(a, prop, b[prop]);
5104
- }
5105
- return a;
5106
- };
5107
- var __spreadProps$5 = (a, b) => __defProps$5(a, __getOwnPropDescs$5(b));
5108
4777
  const addParserForRawExpression = (q, key, raw) => {
5109
- if (raw.result.value)
5110
- addColumnParserToQuery(q.q, key, raw.result.value);
4778
+ if (raw.result.value) addColumnParserToQuery(q.q, key, raw.result.value);
5111
4779
  };
5112
4780
  const addParsersForSelectJoined = (q, arg, as = arg) => {
5113
- var _a, _b, _c, _d;
5114
- const parsers = (_a = q.q.joinedParsers) == null ? void 0 : _a[arg];
4781
+ var _a;
4782
+ const parsers = q.q.joinedParsers?.[arg];
5115
4783
  if (parsers) {
5116
4784
  orchidCore.setParserToQuery(q.q, as, (row) => parseRecord(parsers, row));
5117
4785
  }
5118
- const batchParsers = (_b = q.q.joinedBatchParsers) == null ? void 0 : _b[arg];
4786
+ const batchParsers = q.q.joinedBatchParsers?.[arg];
5119
4787
  if (batchParsers) {
5120
- ((_d = (_c = q.q).batchParsers) != null ? _d : _c.batchParsers = []).push(
4788
+ ((_a = q.q).batchParsers ?? (_a.batchParsers = [])).push(
5121
4789
  ...batchParsers.map((x) => ({
5122
4790
  path: [as, ...x.path],
5123
4791
  fn: x.fn
@@ -5126,21 +4794,20 @@ const addParsersForSelectJoined = (q, arg, as = arg) => {
5126
4794
  }
5127
4795
  };
5128
4796
  const addParserForSelectItem = (q, as, key, arg, joinQuery) => {
5129
- var _a, _b, _c, _d, _e;
4797
+ var _a, _b;
5130
4798
  if (typeof arg === "object" || typeof arg === "function") {
5131
4799
  const { q: query } = arg;
5132
4800
  if (query.batchParsers) {
5133
- const batchParsers = (_b = (_a = q.q).batchParsers) != null ? _b : _a.batchParsers = [];
4801
+ const batchParsers = (_a = q.q).batchParsers ?? (_a.batchParsers = []);
5134
4802
  for (const bp of query.batchParsers) {
5135
4803
  batchParsers.push({ path: [key, ...bp.path], fn: bp.fn });
5136
4804
  }
5137
4805
  }
5138
4806
  if (query.hookSelect || query.parsers || query.transform) {
5139
- const batchParsers = (_d = (_c = q.q).batchParsers) != null ? _d : _c.batchParsers = [];
4807
+ const batchParsers = (_b = q.q).batchParsers ?? (_b.batchParsers = []);
5140
4808
  batchParsers.push({
5141
4809
  path: [key],
5142
4810
  fn: (path, queryResult) => {
5143
- var _a2, _b2, _c2;
5144
4811
  const { rows } = queryResult;
5145
4812
  const originalReturnType = query.returnType || "all";
5146
4813
  let returnType = originalReturnType;
@@ -5177,20 +4844,17 @@ const addParserForSelectItem = (q, as, key, arg, joinQuery) => {
5177
4844
  if (parsers) {
5178
4845
  if (returnType === "one") {
5179
4846
  for (const { data } of batches) {
5180
- if (data)
5181
- parseRecord(parsers, data);
4847
+ if (data) parseRecord(parsers, data);
5182
4848
  }
5183
4849
  } else {
5184
4850
  for (const { data } of batches) {
5185
- if (!data)
5186
- throw new NotFoundError(arg);
4851
+ if (!data) throw new NotFoundError(arg);
5187
4852
  parseRecord(parsers, data);
5188
4853
  }
5189
4854
  }
5190
4855
  } else if (returnType !== "one") {
5191
4856
  for (const { data } of batches) {
5192
- if (!data)
5193
- throw new NotFoundError(arg);
4857
+ if (!data) throw new NotFoundError(arg);
5194
4858
  }
5195
4859
  }
5196
4860
  if (hookSelect) {
@@ -5201,7 +4865,7 @@ const addParserForSelectItem = (q, as, key, arg, joinQuery) => {
5201
4865
  break;
5202
4866
  }
5203
4867
  case "pluck": {
5204
- const parse = (_a2 = query.parsers) == null ? void 0 : _a2.pluck;
4868
+ const parse = query.parsers?.pluck;
5205
4869
  if (parse) {
5206
4870
  for (const { data } of batches) {
5207
4871
  for (let i = 0; i < data.length; i++) {
@@ -5213,7 +4877,7 @@ const addParserForSelectItem = (q, as, key, arg, joinQuery) => {
5213
4877
  }
5214
4878
  case "value":
5215
4879
  case "valueOrThrow": {
5216
- const parse = (_b2 = query.parsers) == null ? void 0 : _b2[orchidCore.getValueKey];
4880
+ const parse = query.parsers?.[orchidCore.getValueKey];
5217
4881
  if (parse) {
5218
4882
  if (returnType === "value") {
5219
4883
  for (const item of batches) {
@@ -5228,8 +4892,7 @@ const addParserForSelectItem = (q, as, key, arg, joinQuery) => {
5228
4892
  }
5229
4893
  } else if (returnType !== "value") {
5230
4894
  for (const { data } of batches) {
5231
- if (data === void 0)
5232
- throw new NotFoundError(arg);
4895
+ if (data === void 0) throw new NotFoundError(arg);
5233
4896
  }
5234
4897
  }
5235
4898
  if (hookSelect) {
@@ -5245,9 +4908,8 @@ const addParserForSelectItem = (q, as, key, arg, joinQuery) => {
5245
4908
  let renames;
5246
4909
  for (const column of hookSelect.keys()) {
5247
4910
  const as2 = hookSelect.get(column).as;
5248
- if (as2)
5249
- (renames != null ? renames : renames = {})[column] = as2;
5250
- (_c2 = tempColumns != null ? tempColumns : tempColumns = /* @__PURE__ */ new Set()) == null ? void 0 : _c2.add(as2 || column);
4911
+ if (as2) (renames ?? (renames = {}))[column] = as2;
4912
+ (tempColumns ?? (tempColumns = /* @__PURE__ */ new Set()))?.add(as2 || column);
5251
4913
  }
5252
4914
  if (renames) {
5253
4915
  for (const { data } of batches) {
@@ -5272,8 +4934,7 @@ const addParserForSelectItem = (q, as, key, arg, joinQuery) => {
5272
4934
  renames,
5273
4935
  key
5274
4936
  );
5275
- if (maybePromise)
5276
- return maybePromise;
4937
+ if (maybePromise) return maybePromise;
5277
4938
  }
5278
4939
  finalizeNestedHookSelect(
5279
4940
  batches,
@@ -5288,7 +4949,7 @@ const addParserForSelectItem = (q, as, key, arg, joinQuery) => {
5288
4949
  }
5289
4950
  });
5290
4951
  }
5291
- if (!joinQuery && ((_e = arg.q) == null ? void 0 : _e.subQuery) && arg.q.expr) {
4952
+ if (!joinQuery && arg.q?.subQuery && arg.q.expr) {
5292
4953
  arg = arg.q.expr;
5293
4954
  }
5294
4955
  if (orchidCore.isExpression(arg)) {
@@ -5328,7 +4989,6 @@ const collectNestedSelectBatches = (batches, rows, path, last) => {
5328
4989
  };
5329
4990
  const emptyArrSQL = new RawSQL("'[]'");
5330
4991
  const processSelectArg = (q, as, arg, columnAs) => {
5331
- var _a;
5332
4992
  if (typeof arg === "string") {
5333
4993
  return setParserForSelectedString(q, arg, as, columnAs);
5334
4994
  }
@@ -5371,10 +5031,10 @@ const processSelectArg = (q, as, arg, columnAs) => {
5371
5031
  query = value;
5372
5032
  }
5373
5033
  }
5374
- const asOverride = (_a = value.q.aliases[key]) != null ? _a : key;
5034
+ const asOverride = value.q.aliases[key] ?? key;
5375
5035
  value.q.joinedForSelect = asOverride;
5376
5036
  if (asOverride !== key) {
5377
- aliases = __spreadProps$5(__spreadValues$e({}, q.q.aliases), { [key]: asOverride });
5037
+ aliases = { ...q.q.aliases, [key]: asOverride };
5378
5038
  }
5379
5039
  _joinLateral(
5380
5040
  q,
@@ -5385,8 +5045,7 @@ const processSelectArg = (q, as, arg, columnAs) => {
5385
5045
  );
5386
5046
  }
5387
5047
  }
5388
- if (aliases)
5389
- q.q.aliases = aliases;
5048
+ if (aliases) q.q.aliases = aliases;
5390
5049
  selectAs[key] = addParserForSelectItem(
5391
5050
  q,
5392
5051
  as,
@@ -5398,65 +5057,63 @@ const processSelectArg = (q, as, arg, columnAs) => {
5398
5057
  return { selectAs };
5399
5058
  };
5400
5059
  const setParserForSelectedString = (q, arg, as, columnAs) => {
5401
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
5060
+ var _a, _b;
5402
5061
  const index = arg.indexOf(".");
5403
5062
  if (index !== -1) {
5404
- const table = arg.slice(0, index);
5063
+ const table = getFullColumnTable(q, arg, index, as);
5405
5064
  const column = arg.slice(index + 1);
5406
5065
  if (column === "*") {
5407
5066
  addParsersForSelectJoined(q, table, columnAs);
5408
5067
  return table === as ? column : arg;
5409
- } else if (table === as) {
5068
+ }
5069
+ if (table === as) {
5410
5070
  if (columnAs) {
5411
- const parser = (_a = q.q.parsers) == null ? void 0 : _a[column];
5412
- if (parser)
5413
- q.q.parsers[columnAs] = parser;
5071
+ const parser2 = q.q.parsers?.[column];
5072
+ if (parser2) q.q.parsers[columnAs] = parser2;
5414
5073
  }
5415
5074
  return handleComputed(q, q.q.computeds, column);
5416
- } else {
5417
- const parser = (_c = (_b = q.q.joinedParsers) == null ? void 0 : _b[table]) == null ? void 0 : _c[column];
5418
- if (parser)
5419
- orchidCore.setParserToQuery(q.q, columnAs || column, parser);
5420
- const batchParsers = (_d = q.q.joinedBatchParsers) == null ? void 0 : _d[table];
5421
- if (batchParsers) {
5422
- for (const bp of batchParsers) {
5423
- if (bp.path[0] === column) {
5424
- ((_f = (_e = q.q).batchParsers) != null ? _f : _e.batchParsers = []).push(bp);
5425
- }
5075
+ }
5076
+ const parser = q.q.joinedParsers?.[table]?.[column];
5077
+ if (parser) orchidCore.setParserToQuery(q.q, columnAs || column, parser);
5078
+ const batchParsers = q.q.joinedBatchParsers?.[table];
5079
+ if (batchParsers) {
5080
+ for (const bp of batchParsers) {
5081
+ if (bp.path[0] === column) {
5082
+ ((_a = q.q).batchParsers ?? (_a.batchParsers = [])).push(bp);
5426
5083
  }
5427
5084
  }
5428
- const computeds = (_g = q.q.joinedComputeds) == null ? void 0 : _g[table];
5429
- if (computeds == null ? void 0 : computeds[column]) {
5430
- const computed = computeds[column];
5431
- const map = (_i = (_h = q.q).hookSelect) != null ? _i : _h.hookSelect = /* @__PURE__ */ new Map();
5432
- for (const column2 of computed.deps) {
5433
- map.set(column2, { select: `${table}.${column2}` });
5434
- }
5435
- q.q.selectedComputeds = __spreadProps$5(__spreadValues$e({}, q.q.selectedComputeds), {
5436
- [column]: computed
5437
- });
5438
- return;
5085
+ }
5086
+ const computeds = q.q.joinedComputeds?.[table];
5087
+ if (computeds?.[column]) {
5088
+ const computed = computeds[column];
5089
+ const map = (_b = q.q).hookSelect ?? (_b.hookSelect = /* @__PURE__ */ new Map());
5090
+ for (const column2 of computed.deps) {
5091
+ map.set(column2, { select: `${table}.${column2}` });
5439
5092
  }
5440
- return arg;
5093
+ q.q.selectedComputeds = {
5094
+ ...q.q.selectedComputeds,
5095
+ [column]: computed
5096
+ };
5097
+ return;
5441
5098
  }
5099
+ return arg;
5442
5100
  } else {
5443
5101
  if (columnAs) {
5444
- const parser = (_j = q.q.parsers) == null ? void 0 : _j[arg];
5445
- if (parser)
5446
- q.q.parsers[columnAs] = parser;
5102
+ const parser = q.q.parsers?.[arg];
5103
+ if (parser) q.q.parsers[columnAs] = parser;
5447
5104
  }
5448
5105
  return handleComputed(q, q.q.computeds, arg);
5449
5106
  }
5450
5107
  };
5451
5108
  const handleComputed = (q, computeds, column) => {
5452
- var _a, _b;
5453
- if (computeds == null ? void 0 : computeds[column]) {
5109
+ var _a;
5110
+ if (computeds?.[column]) {
5454
5111
  const computed = computeds[column];
5455
- const map = (_b = (_a = q.q).hookSelect) != null ? _b : _a.hookSelect = /* @__PURE__ */ new Map();
5112
+ const map = (_a = q.q).hookSelect ?? (_a.hookSelect = /* @__PURE__ */ new Map());
5456
5113
  for (const column2 of computed.deps) {
5457
5114
  map.set(column2, { select: column2 });
5458
5115
  }
5459
- q.q.selectedComputeds = __spreadProps$5(__spreadValues$e({}, q.q.selectedComputeds), { [column]: computed });
5116
+ q.q.selectedComputeds = { ...q.q.selectedComputeds, [column]: computed };
5460
5117
  return;
5461
5118
  }
5462
5119
  return column;
@@ -5501,8 +5158,7 @@ const getShapeFromSelect = (q, isSubQuery) => {
5501
5158
  const { returnType } = it.q;
5502
5159
  if (returnType === "value" || returnType === "valueOrThrow") {
5503
5160
  const type = it.q.getColumn;
5504
- if (type)
5505
- result[key] = type;
5161
+ if (type) result[key] = type;
5506
5162
  } else {
5507
5163
  result[key] = new JSONTextColumn(defaultSchemaConfig);
5508
5164
  }
@@ -5514,17 +5170,16 @@ const getShapeFromSelect = (q, isSubQuery) => {
5514
5170
  return result;
5515
5171
  };
5516
5172
  const addColumnToShapeFromSelect = (q, arg, shape, query, result, isSubQuery, key) => {
5517
- var _a, _b;
5518
5173
  const index = arg.indexOf(".");
5519
5174
  if (index !== -1) {
5520
- const table = arg.slice(0, index);
5175
+ const as = q.q.as || q.table;
5176
+ const table = getFullColumnTable(q, arg, index, as);
5521
5177
  const column = arg.slice(index + 1);
5522
- if (table === (q.q.as || q.table)) {
5178
+ if (table === as) {
5523
5179
  result[key || column] = shape[column];
5524
5180
  } else {
5525
- const it = (_b = (_a = query.joinedShapes) == null ? void 0 : _a[table]) == null ? void 0 : _b[column];
5526
- if (it)
5527
- result[key || column] = maybeUnNameColumn(it, isSubQuery);
5181
+ const it = query.joinedShapes?.[table]?.[column];
5182
+ if (it) result[key || column] = maybeUnNameColumn(it, isSubQuery);
5528
5183
  }
5529
5184
  } else if (arg === "*") {
5530
5185
  for (const key2 in shape) {
@@ -5535,10 +5190,10 @@ const addColumnToShapeFromSelect = (q, arg, shape, query, result, isSubQuery, ke
5535
5190
  }
5536
5191
  };
5537
5192
  const maybeUnNameColumn = (column, isSubQuery) => {
5538
- return isSubQuery && (column == null ? void 0 : column.data.name) ? orchidCore.setColumnData(column, "name", void 0) : column;
5193
+ return isSubQuery && column?.data.name ? orchidCore.setColumnData(column, "name", void 0) : column;
5539
5194
  };
5540
5195
  function _querySelect(q, args) {
5541
- var _a, _b;
5196
+ var _a;
5542
5197
  if (q.q.returning) {
5543
5198
  q.q.select = q.q.returning = void 0;
5544
5199
  }
@@ -5550,17 +5205,15 @@ function _querySelect(q, args) {
5550
5205
  }
5551
5206
  const len = args.length;
5552
5207
  if (!len) {
5553
- (_b = (_a = q.q).select) != null ? _b : _a.select = [];
5208
+ (_a = q.q).select ?? (_a.select = []);
5554
5209
  return q;
5555
5210
  }
5556
5211
  const as = q.q.as || q.table;
5557
5212
  const selectArgs = [];
5558
5213
  for (const arg of args) {
5559
5214
  const item = processSelectArg(q, as, arg);
5560
- if (item)
5561
- selectArgs.push(item);
5562
- else if (item === false)
5563
- return _queryNone(q);
5215
+ if (item) selectArgs.push(item);
5216
+ else if (item === false) return _queryNone(q);
5564
5217
  }
5565
5218
  return pushQueryArray(q, "select", selectArgs);
5566
5219
  }
@@ -5603,8 +5256,7 @@ class SelectItemExpression extends orchidCore.Expression {
5603
5256
  this.item = item;
5604
5257
  this.result = { value };
5605
5258
  this.q = query.q;
5606
- if (value)
5607
- Object.assign(this, value.operators);
5259
+ if (value) Object.assign(this, value.operators);
5608
5260
  }
5609
5261
  // `makeSQL` acts similarly to how select args are handled
5610
5262
  makeSQL(ctx, quotedAs) {
@@ -5613,17 +5265,17 @@ class SelectItemExpression extends orchidCore.Expression {
5613
5265
  }
5614
5266
 
5615
5267
  const _getSelectableColumn = (q, arg) => {
5616
- var _a, _b;
5617
5268
  let type = q.q.shape[arg];
5618
5269
  if (!type) {
5619
5270
  const index = arg.indexOf(".");
5620
5271
  if (index !== -1) {
5621
- const table = arg.slice(0, index);
5272
+ const as = q.q.as || q.table;
5273
+ const table = getFullColumnTable(q, arg, index, as);
5622
5274
  const column = arg.slice(index + 1);
5623
- if (table === (q.q.as || q.table)) {
5275
+ if (table === as) {
5624
5276
  type = q.shape[column];
5625
5277
  } else {
5626
- type = (_b = (_a = q.q.joinedShapes) == null ? void 0 : _a[table]) == null ? void 0 : _b[column];
5278
+ type = q.q.joinedShapes?.[table]?.[column];
5627
5279
  }
5628
5280
  }
5629
5281
  }
@@ -5631,8 +5283,7 @@ const _getSelectableColumn = (q, arg) => {
5631
5283
  };
5632
5284
  const _get = (query, returnType, arg) => {
5633
5285
  const q = query.q;
5634
- if (q.returning)
5635
- q.returning = void 0;
5286
+ if (q.returning) q.returning = void 0;
5636
5287
  q.returnType = returnType;
5637
5288
  let type;
5638
5289
  if (typeof arg === "string") {
@@ -5653,7 +5304,7 @@ const _get = (query, returnType, arg) => {
5653
5304
  }
5654
5305
  return setQueryOperators(
5655
5306
  query,
5656
- (type == null ? void 0 : type.operators) || Operators.any
5307
+ type?.operators || Operators.any
5657
5308
  );
5658
5309
  };
5659
5310
  function _queryGet(self, arg) {
@@ -5663,36 +5314,17 @@ function _queryGetOptional(self, arg) {
5663
5314
  return _get(self, "value", arg);
5664
5315
  }
5665
5316
 
5666
- var __defProp$d = Object.defineProperty;
5667
- var __defProps$4 = Object.defineProperties;
5668
- var __getOwnPropDescs$4 = Object.getOwnPropertyDescriptors;
5669
- var __getOwnPropSymbols$e = Object.getOwnPropertySymbols;
5670
- var __hasOwnProp$e = Object.prototype.hasOwnProperty;
5671
- var __propIsEnum$e = Object.prototype.propertyIsEnumerable;
5672
- var __defNormalProp$d = (obj, key, value) => key in obj ? __defProp$d(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
5673
- var __spreadValues$d = (a, b) => {
5674
- for (var prop in b || (b = {}))
5675
- if (__hasOwnProp$e.call(b, prop))
5676
- __defNormalProp$d(a, prop, b[prop]);
5677
- if (__getOwnPropSymbols$e)
5678
- for (var prop of __getOwnPropSymbols$e(b)) {
5679
- if (__propIsEnum$e.call(b, prop))
5680
- __defNormalProp$d(a, prop, b[prop]);
5681
- }
5682
- return a;
5683
- };
5684
- var __spreadProps$4 = (a, b) => __defProps$4(a, __getOwnPropDescs$4(b));
5685
5317
  const _queryAs = (self, as) => {
5686
5318
  const { q } = self;
5687
5319
  q.as = as;
5688
- q.aliases = __spreadProps$4(__spreadValues$d({}, q.aliases), {
5320
+ q.aliases = {
5321
+ ...q.aliases,
5689
5322
  [as]: q.aliases ? _queryResolveAlias(q.aliases, as) : as
5690
- });
5323
+ };
5691
5324
  return self;
5692
5325
  };
5693
5326
  const _queryResolveAlias = (aliases, as) => {
5694
- if (!aliases[as])
5695
- return as;
5327
+ if (!aliases[as]) return as;
5696
5328
  let suffix = 2;
5697
5329
  let privateAs;
5698
5330
  while (aliases[privateAs = as + suffix]) {
@@ -5718,30 +5350,13 @@ class AsMethods {
5718
5350
  }
5719
5351
  }
5720
5352
 
5721
- var __defProp$c = Object.defineProperty;
5722
- var __getOwnPropSymbols$d = Object.getOwnPropertySymbols;
5723
- var __hasOwnProp$d = Object.prototype.hasOwnProperty;
5724
- var __propIsEnum$d = Object.prototype.propertyIsEnumerable;
5725
- var __defNormalProp$c = (obj, key, value) => key in obj ? __defProp$c(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
5726
- var __spreadValues$c = (a, b) => {
5727
- for (var prop in b || (b = {}))
5728
- if (__hasOwnProp$d.call(b, prop))
5729
- __defNormalProp$c(a, prop, b[prop]);
5730
- if (__getOwnPropSymbols$d)
5731
- for (var prop of __getOwnPropSymbols$d(b)) {
5732
- if (__propIsEnum$d.call(b, prop))
5733
- __defNormalProp$c(a, prop, b[prop]);
5734
- }
5735
- return a;
5736
- };
5737
5353
  function queryFrom(self, arg) {
5738
- var _a, _b, _c;
5739
5354
  const data = self.q;
5740
5355
  if (typeof arg === "string") {
5741
5356
  data.as || (data.as = arg);
5742
- const w = (_a = data.withShapes) == null ? void 0 : _a[arg];
5743
- data.shape = (_b = w == null ? void 0 : w.shape) != null ? _b : orchidCore.emptyObject;
5744
- data.computeds = w == null ? void 0 : w.computeds;
5357
+ const w = data.withShapes?.[arg];
5358
+ data.shape = w?.shape ?? orchidCore.emptyObject;
5359
+ data.computeds = w?.computeds;
5745
5360
  } else if (orchidCore.isExpression(arg)) {
5746
5361
  data.as || (data.as = "t");
5747
5362
  } else if (Array.isArray(arg)) {
@@ -5750,8 +5365,7 @@ function queryFrom(self, arg) {
5750
5365
  if (typeof item === "string") {
5751
5366
  const w = data.withShapes[item];
5752
5367
  Object.assign(shape, w.shape);
5753
- if (w.computeds)
5754
- data.computeds = __spreadValues$c(__spreadValues$c({}, data.computeds), w.computeds);
5368
+ if (w.computeds) data.computeds = { ...data.computeds, ...w.computeds };
5755
5369
  for (const key in w.shape) {
5756
5370
  addColumnParserToQuery(
5757
5371
  self,
@@ -5761,7 +5375,7 @@ function queryFrom(self, arg) {
5761
5375
  }
5762
5376
  } else if (!orchidCore.isExpression(item)) {
5763
5377
  Object.assign(shape, getShapeFromSelect(item, true));
5764
- Object.assign((_c = data.parsers) != null ? _c : data.parsers = {}, item.q.parsers);
5378
+ Object.assign(data.parsers ?? (data.parsers = {}), item.q.parsers);
5765
5379
  }
5766
5380
  }
5767
5381
  } else {
@@ -5877,11 +5491,9 @@ function queryJson(self, coalesce) {
5877
5491
 
5878
5492
  const pushSelectSql = (ctx, table, query, quotedAs) => {
5879
5493
  const sql = selectToSql(ctx, table, query, quotedAs);
5880
- if (sql)
5881
- ctx.sql.push(sql);
5494
+ if (sql) ctx.sql.push(sql);
5882
5495
  };
5883
5496
  const selectToSql = (ctx, table, query, quotedAs, hookSelect = query.hookSelect) => {
5884
- var _a, _b;
5885
5497
  let selected;
5886
5498
  const list = [];
5887
5499
  if (query.select) {
@@ -5890,7 +5502,7 @@ const selectToSql = (ctx, table, query, quotedAs, hookSelect = query.hookSelect)
5890
5502
  let sql;
5891
5503
  if (item === "*") {
5892
5504
  if (hookSelect) {
5893
- selected != null ? selected : selected = {};
5505
+ selected ?? (selected = {});
5894
5506
  for (const key in query.selectAllKeys || query.shape) {
5895
5507
  selected[key] = quotedAs;
5896
5508
  }
@@ -5901,8 +5513,7 @@ const selectToSql = (ctx, table, query, quotedAs, hookSelect = query.hookSelect)
5901
5513
  if (index !== -1) {
5902
5514
  const tableName = item.slice(0, index);
5903
5515
  const key = item.slice(index + 1);
5904
- if (hookSelect == null ? void 0 : hookSelect.get(key))
5905
- (selected != null ? selected : selected = {})[key] = `"${tableName}"`;
5516
+ if (hookSelect?.get(key)) (selected ?? (selected = {}))[key] = `"${tableName}"`;
5906
5517
  sql = tableColumnToSqlWithAs(
5907
5518
  ctx,
5908
5519
  table.q,
@@ -5910,12 +5521,9 @@ const selectToSql = (ctx, table, query, quotedAs, hookSelect = query.hookSelect)
5910
5521
  tableName,
5911
5522
  key,
5912
5523
  key === "*" ? tableName : key,
5913
- quotedAs,
5914
- true
5915
- );
5524
+ quotedAs);
5916
5525
  } else {
5917
- if (hookSelect == null ? void 0 : hookSelect.get(item))
5918
- (selected != null ? selected : selected = {})[item] = quotedAs;
5526
+ if (hookSelect?.get(item)) (selected ?? (selected = {}))[item] = quotedAs;
5919
5527
  sql = ownColumnToSqlWithAs(
5920
5528
  ctx,
5921
5529
  table.q,
@@ -5931,8 +5539,7 @@ const selectToSql = (ctx, table, query, quotedAs, hookSelect = query.hookSelect)
5931
5539
  if ("selectAs" in item) {
5932
5540
  const obj = item.selectAs;
5933
5541
  for (const as in obj) {
5934
- if (hookSelect)
5935
- (selected != null ? selected : selected = {})[as] = true;
5542
+ if (hookSelect) (selected ?? (selected = {}))[as] = true;
5936
5543
  const value = obj[as];
5937
5544
  if (typeof value === "object") {
5938
5545
  if (orchidCore.isExpression(value)) {
@@ -5972,26 +5579,25 @@ const selectToSql = (ctx, table, query, quotedAs, hookSelect = query.hookSelect)
5972
5579
  const tableName = select.slice(0, index);
5973
5580
  quotedTable = `"${tableName}"`;
5974
5581
  columnName = select.slice(index + 1);
5975
- col = (_b = (_a = table.q.joinedShapes) == null ? void 0 : _a[tableName]) == null ? void 0 : _b[columnName];
5976
- sql = (col == null ? void 0 : col.data.computed) ? col.data.computed.toSQL(ctx, `"${tableName}"`) : `"${tableName}"."${(col == null ? void 0 : col.data.name) || columnName}"`;
5582
+ col = table.q.joinedShapes?.[tableName]?.[columnName];
5583
+ sql = col?.data.computed ? col.data.computed.toSQL(ctx, `"${tableName}"`) : `"${tableName}"."${col?.data.name || columnName}"`;
5977
5584
  } else {
5978
5585
  quotedTable = quotedAs;
5979
5586
  columnName = select;
5980
5587
  col = query.shape[select];
5981
5588
  sql = simpleColumnToSQL(ctx, query, select, col, quotedAs);
5982
5589
  }
5983
- if (selected == null ? void 0 : selected[columnName]) {
5984
- if ((selected == null ? void 0 : selected[columnName]) === quotedTable) {
5590
+ if (selected?.[columnName]) {
5591
+ if (selected?.[columnName] === quotedTable) {
5985
5592
  hookSelect.delete(column);
5986
5593
  continue;
5987
5594
  }
5988
5595
  let i = 2;
5989
5596
  let name;
5990
- while (selected[name = `${column}${i}`])
5991
- i++;
5597
+ while (selected[name = `${column}${i}`]) i++;
5992
5598
  item.as = name;
5993
5599
  sql += ` "${name}"`;
5994
- } else if (col == null ? void 0 : col.data.name) {
5600
+ } else if (col?.data.name) {
5995
5601
  sql += ` "${columnName}"`;
5996
5602
  }
5997
5603
  list.push(sql);
@@ -6004,11 +5610,9 @@ function selectedObjectToSQL(ctx, quotedAs, item) {
6004
5610
  return ctx.aliasValue ? `${sql} r` : sql;
6005
5611
  }
6006
5612
  const selectAllSql = (query, quotedAs) => {
6007
- var _a, _b, _c;
6008
- 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(", ")) || "*";
5613
+ return query.join?.length ? query.selectAllColumns?.map((item) => `${quotedAs}.${item}`).join(", ") || `${quotedAs}.*` : query.selectAllColumns?.join(", ") || "*";
6009
5614
  };
6010
5615
  const pushSubQuerySql = (ctx, query, as, list, quotedAs) => {
6011
- var _a, _b, _c;
6012
5616
  const { returnType = "all" } = query.q;
6013
5617
  if (isQueryNone(query)) {
6014
5618
  let sql;
@@ -6019,7 +5623,7 @@ const pushSubQuerySql = (ctx, query, as, list, quotedAs) => {
6019
5623
  return;
6020
5624
  case "value":
6021
5625
  case "valueOrThrow":
6022
- if (query.q.returning || ((_a = query.q.expr) == null ? void 0 : _a.result.value) instanceof IntegerBaseColumn) {
5626
+ if (query.q.returning || query.q.expr?.result.value instanceof IntegerBaseColumn) {
6023
5627
  sql = "0";
6024
5628
  } else {
6025
5629
  return;
@@ -6050,8 +5654,7 @@ const pushSubQuerySql = (ctx, query, as, list, quotedAs) => {
6050
5654
  sql = `"${query.q.joinedForSelect}".r`;
6051
5655
  break;
6052
5656
  case "valueOrThrow":
6053
- if (query.q.returning)
6054
- return;
5657
+ if (query.q.returning) return;
6055
5658
  sql = `"${query.q.joinedForSelect}".r`;
6056
5659
  break;
6057
5660
  case "void":
@@ -6059,8 +5662,7 @@ const pushSubQuerySql = (ctx, query, as, list, quotedAs) => {
6059
5662
  default:
6060
5663
  throw new UnhandledTypeError(query, returnType);
6061
5664
  }
6062
- if (sql)
6063
- list.push(`${coalesce(ctx, query, sql, quotedAs)} "${as}"`);
5665
+ if (sql) list.push(`${coalesce(ctx, query, sql, quotedAs)} "${as}"`);
6064
5666
  return;
6065
5667
  }
6066
5668
  switch (returnType) {
@@ -6071,8 +5673,8 @@ const pushSubQuerySql = (ctx, query, as, list, quotedAs) => {
6071
5673
  break;
6072
5674
  case "pluck": {
6073
5675
  const { select } = query.q;
6074
- const first = select == null ? void 0 : select[0];
6075
- if (!first && ((_b = query.q.computeds) == null ? void 0 : _b[as])) {
5676
+ const first = select?.[0];
5677
+ if (!first && query.q.computeds?.[as]) {
6076
5678
  query = queryJson(query);
6077
5679
  } else if (!first) {
6078
5680
  throw new OrchidOrmInternalError(
@@ -6089,7 +5691,7 @@ const pushSubQuerySql = (ctx, query, as, list, quotedAs) => {
6089
5691
  }
6090
5692
  case "value":
6091
5693
  case "valueOrThrow":
6092
- if (!query.q.returning && ((_c = query.q.computeds) == null ? void 0 : _c[as])) {
5694
+ if (!query.q.returning && query.q.computeds?.[as]) {
6093
5695
  query = queryJson(query);
6094
5696
  }
6095
5697
  break;
@@ -6137,8 +5739,7 @@ const orderByToSql = (ctx, data, order, quotedAs) => {
6137
5739
  return sql.join(", ");
6138
5740
  };
6139
5741
  const addOrder = (ctx, data, column, quotedAs, dir) => {
6140
- var _a;
6141
- if ((_a = data.sources) == null ? void 0 : _a[column]) {
5742
+ if (data.sources?.[column]) {
6142
5743
  const search = data.sources[column];
6143
5744
  const order = dir || (!search.order || search.order === true ? orchidCore.emptyObject : search.order);
6144
5745
  return `${order.coverDensity ? "ts_rank_cd" : "ts_rank"}(${order.weights ? `${orchidCore.addValue(ctx.values, `{${order.weights}}`)}, ` : ""}${search.vectorSQL}, "${column}"${order.normalization !== void 0 ? `, ${orchidCore.addValue(ctx.values, order.normalization)}` : ""}) ${order.dir || "DESC"}`;
@@ -6147,10 +5748,8 @@ const addOrder = (ctx, data, column, quotedAs, dir) => {
6147
5748
  };
6148
5749
 
6149
5750
  const windowToSql = (ctx, data, window, quotedAs) => {
6150
- if (typeof window === "string")
6151
- return `"${window}"`;
6152
- if (orchidCore.isExpression(window))
6153
- return `(${window.toSQL(ctx, quotedAs)})`;
5751
+ if (typeof window === "string") return `"${window}"`;
5752
+ if (orchidCore.isExpression(window)) return `(${window.toSQL(ctx, quotedAs)})`;
6154
5753
  const sql = [];
6155
5754
  if (window.partitionBy) {
6156
5755
  sql.push(
@@ -6167,38 +5766,33 @@ const windowToSql = (ctx, data, window, quotedAs) => {
6167
5766
 
6168
5767
  const pushHavingSql = (ctx, query, quotedAs) => {
6169
5768
  const conditions = havingToSql(ctx, query, quotedAs);
6170
- if (conditions == null ? void 0 : conditions.length)
6171
- ctx.sql.push("HAVING", conditions);
5769
+ if (conditions?.length) ctx.sql.push("HAVING", conditions);
6172
5770
  };
6173
5771
  const havingToSql = (ctx, query, quotedAs) => {
6174
- var _a;
6175
- return (_a = query.having) == null ? void 0 : _a.map(
5772
+ return query.having?.map(
6176
5773
  (it) => "raw" in it[0] ? templateLiteralToSQL(it, ctx, quotedAs) : it.map((item) => item.toSQL(ctx, quotedAs)).join(" AND ")
6177
5774
  ).join(" AND ");
6178
5775
  };
6179
5776
 
6180
5777
  const pushWithSql = (ctx, items) => {
6181
- if (!items.length)
6182
- return;
5778
+ if (!items.length) return;
6183
5779
  ctx.sql.push(
6184
5780
  "WITH",
6185
5781
  items.map((item) => {
6186
- var _a;
6187
5782
  let inner;
6188
5783
  if (item.q) {
6189
5784
  inner = getSqlText(makeSQL(item.q, ctx));
6190
5785
  } else {
6191
5786
  inner = item.s.toSQL(ctx, `"${item.n}"`);
6192
5787
  }
6193
- const o = (_a = item.o) != null ? _a : orchidCore.emptyObject;
5788
+ const o = item.o ?? orchidCore.emptyObject;
6194
5789
  return `${o.recursive ? "RECURSIVE " : ""}"${item.n}"${o.columns ? `(${o.columns.map((x) => `"${x}"`).join(", ")})` : ""} AS ${o.materialized ? "MATERIALIZED " : o.notMaterialized ? "NOT MATERIALIZED " : ""}(${inner})`;
6195
5790
  }).join(", ")
6196
5791
  );
6197
5792
  };
6198
5793
 
6199
5794
  const checkIfASimpleQuery = (q) => {
6200
- var _a, _b;
6201
- 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)
5795
+ if (q.q.returnType && q.q.returnType !== "all" || q.q.selectAllColumns || q.q.and?.length || q.q.or?.length || q.q.scopes)
6202
5796
  return false;
6203
5797
  const keys = Object.keys(q.q);
6204
5798
  return !keys.some((key) => queryKeysOfNotSimpleQuery.includes(key));
@@ -6267,8 +5861,7 @@ const getFrom = (ctx, table, data, quotedAs) => {
6267
5861
  return fromToSql(ctx, data, from, quotedAs);
6268
5862
  }
6269
5863
  let sql = quoteSchemaAndTable(data.schema, table.table);
6270
- if (data.only)
6271
- sql = `ONLY ${sql}`;
5864
+ if (data.only) sql = `ONLY ${sql}`;
6272
5865
  return sql;
6273
5866
  };
6274
5867
  const fromToSql = (ctx, data, from, quotedAs) => {
@@ -6293,13 +5886,11 @@ const fromToSql = (ctx, data, from, quotedAs) => {
6293
5886
  return (only === void 0 ? data.only : only) ? `ONLY ${sql}` : sql;
6294
5887
  };
6295
5888
  const getSearchLang = (ctx, data, source, quotedAs) => {
6296
- var _a;
6297
- return (_a = source.langSQL) != null ? _a : source.langSQL = "languageColumn" in source ? columnToSql(ctx, data, data.shape, source.languageColumn, quotedAs) : orchidCore.isRawSQL(source.language) ? source.language.toSQL(ctx) : orchidCore.addValue(ctx.values, source.language || data.language || "english");
5889
+ return source.langSQL ?? (source.langSQL = "languageColumn" in source ? columnToSql(ctx, data, data.shape, source.languageColumn, quotedAs) : orchidCore.isRawSQL(source.language) ? source.language.toSQL(ctx) : orchidCore.addValue(ctx.values, source.language || data.language || "english"));
6298
5890
  };
6299
5891
  const getSearchText = (ctx, data, source, quotedAs, forHeadline) => {
6300
5892
  let sql = source.textSQL;
6301
- if (sql)
6302
- return sql;
5893
+ if (sql) return sql;
6303
5894
  if ("in" in source) {
6304
5895
  if (typeof source.in === "string") {
6305
5896
  sql = columnToSql(ctx, data, data.shape, source.in, quotedAs);
@@ -6354,11 +5945,10 @@ const MAX_BINDING_PARAMS = 65536;
6354
5945
 
6355
5946
  const quotedColumns = [];
6356
5947
  const makeInsertSql = (ctx, q, query, quotedAs) => {
6357
- var _a, _b, _c, _d;
6358
5948
  const { columns, shape } = query;
6359
5949
  quotedColumns.length = columns.length;
6360
5950
  for (let i = 0, len = columns.length; i < len; i++) {
6361
- quotedColumns[i] = `"${((_a = shape[columns[i]]) == null ? void 0 : _a.data.name) || columns[i]}"`;
5951
+ quotedColumns[i] = `"${shape[columns[i]]?.data.name || columns[i]}"`;
6362
5952
  }
6363
5953
  let runtimeDefaults;
6364
5954
  if (q.internal.runtimeDefaultColumns) {
@@ -6375,7 +5965,7 @@ const makeInsertSql = (ctx, q, query, quotedAs) => {
6375
5965
  if (quotedColumns.length === 0) {
6376
5966
  const key = Object.keys(q.shape)[0];
6377
5967
  const column = q.shape[key];
6378
- quotedColumns[0] = `"${(column == null ? void 0 : column.data.name) || key}"`;
5968
+ quotedColumns[0] = `"${column?.data.name || key}"`;
6379
5969
  if (Array.isArray(values) && Array.isArray(values[0])) {
6380
5970
  values = values.map(() => [void 0]);
6381
5971
  }
@@ -6390,14 +5980,11 @@ const makeInsertSql = (ctx, q, query, quotedAs) => {
6390
5980
  const { target } = query.onConflict;
6391
5981
  if (target) {
6392
5982
  if (typeof target === "string") {
6393
- ctx.sql.push(`("${((_b = shape[target]) == null ? void 0 : _b.data.name) || target}")`);
5983
+ ctx.sql.push(`("${shape[target]?.data.name || target}")`);
6394
5984
  } else if (Array.isArray(target)) {
6395
5985
  ctx.sql.push(
6396
5986
  `(${target.reduce(
6397
- (sql, item, i) => {
6398
- var _a2;
6399
- return sql + (i ? ", " : "") + `"${((_a2 = shape[item]) == null ? void 0 : _a2.data.name) || item}"`;
6400
- },
5987
+ (sql, item, i) => sql + (i ? ", " : "") + `"${shape[item]?.data.name || item}"`,
6401
5988
  ""
6402
5989
  )})`
6403
5990
  );
@@ -6412,14 +5999,13 @@ const makeInsertSql = (ctx, q, query, quotedAs) => {
6412
5999
  const { merge } = query.onConflict;
6413
6000
  if (merge) {
6414
6001
  if (typeof merge === "string") {
6415
- const name = ((_c = shape[merge]) == null ? void 0 : _c.data.name) || merge;
6002
+ const name = shape[merge]?.data.name || merge;
6416
6003
  sql = `DO UPDATE SET "${name}" = excluded."${name}"`;
6417
6004
  } else if ("except" in merge) {
6418
6005
  sql = mergeColumnsSql(columns, quotedColumns, target, merge.except);
6419
6006
  } else {
6420
6007
  sql = `DO UPDATE SET ${merge.reduce((sql2, item, i) => {
6421
- var _a2;
6422
- const name = ((_a2 = shape[item]) == null ? void 0 : _a2.data.name) || item;
6008
+ const name = shape[item]?.data.name || item;
6423
6009
  return sql2 + (i ? ", " : "") + `"${name}" = excluded."${name}"`;
6424
6010
  }, "")}`;
6425
6011
  }
@@ -6436,7 +6022,7 @@ const makeInsertSql = (ctx, q, query, quotedAs) => {
6436
6022
  const arr = [];
6437
6023
  for (const key in set) {
6438
6024
  arr.push(
6439
- `"${((_d = shape[key]) == null ? void 0 : _d.data.name) || key}" = ${orchidCore.addValue(
6025
+ `"${shape[key]?.data.name || key}" = ${orchidCore.addValue(
6440
6026
  ctx.values,
6441
6027
  set[key]
6442
6028
  )}`
@@ -6593,8 +6179,7 @@ const encodeRow = (ctx, values, q, QueryClass, row, runtimeDefaults, quotedAs) =
6593
6179
  };
6594
6180
  const pushReturningSql = (ctx, q, data, quotedAs, hookSelect, keyword = "RETURNING") => {
6595
6181
  const { select } = data;
6596
- if (!(hookSelect == null ? void 0 : hookSelect.size) && !select)
6597
- return hookSelect && /* @__PURE__ */ new Map();
6182
+ if (!hookSelect?.size && !select) return hookSelect && /* @__PURE__ */ new Map();
6598
6183
  ctx.sql.push(keyword);
6599
6184
  if (q.q.hookSelect || hookSelect) {
6600
6185
  const tempSelect = new Map(q.q.hookSelect);
@@ -6647,16 +6232,14 @@ const processData = (ctx, table, set, data, quotedAs) => {
6647
6232
  for (const item of data) {
6648
6233
  if (typeof item === "function") {
6649
6234
  const result = item(data);
6650
- if (result)
6651
- append = orchidCore.pushOrNewArray(append, result);
6235
+ if (result) append = orchidCore.pushOrNewArray(append, result);
6652
6236
  } else if (orchidCore.isExpression(item)) {
6653
6237
  set.push(item.toSQL(ctx, quotedAs));
6654
6238
  } else {
6655
6239
  const shape = table.q.shape;
6656
6240
  for (const key in item) {
6657
6241
  const value = item[key];
6658
- if (value === void 0)
6659
- continue;
6242
+ if (value === void 0) continue;
6660
6243
  set.push(
6661
6244
  `"${shape[key].data.name || key}" = ${processValue(
6662
6245
  ctx,
@@ -6670,8 +6253,7 @@ const processData = (ctx, table, set, data, quotedAs) => {
6670
6253
  }
6671
6254
  }
6672
6255
  }
6673
- if (append)
6674
- processData(ctx, table, set, append, quotedAs);
6256
+ if (append) processData(ctx, table, set, append, quotedAs);
6675
6257
  };
6676
6258
  const processValue = (ctx, table, QueryClass, key, value, quotedAs) => {
6677
6259
  if (value && typeof value === "object") {
@@ -6692,14 +6274,13 @@ const processValue = (ctx, table, QueryClass, key, value, quotedAs) => {
6692
6274
  };
6693
6275
 
6694
6276
  const pushDeleteSql = (ctx, table, query, quotedAs) => {
6695
- var _a, _b, _c;
6696
6277
  const from = `"${table.table}"`;
6697
6278
  ctx.sql.push(`DELETE FROM ${from}`);
6698
6279
  if (from !== quotedAs) {
6699
6280
  ctx.sql.push(`AS ${quotedAs}`);
6700
6281
  }
6701
6282
  let conditions;
6702
- if ((_a = query.join) == null ? void 0 : _a.length) {
6283
+ if (query.join?.length) {
6703
6284
  const targets = [];
6704
6285
  const ons = [];
6705
6286
  const joinSet = query.join.length > 1 ? /* @__PURE__ */ new Set() : null;
@@ -6707,13 +6288,11 @@ const pushDeleteSql = (ctx, table, query, quotedAs) => {
6707
6288
  const join = processJoinItem(ctx, table, query, item.args, quotedAs);
6708
6289
  const key = `${join.target}${join.on}`;
6709
6290
  if (joinSet) {
6710
- if (joinSet.has(key))
6711
- continue;
6291
+ if (joinSet.has(key)) continue;
6712
6292
  joinSet.add(key);
6713
6293
  }
6714
6294
  targets.push(join.target);
6715
- if (join.on)
6716
- ons.push(join.on);
6295
+ if (join.on) ons.push(join.on);
6717
6296
  }
6718
6297
  if (targets.length) {
6719
6298
  ctx.sql.push(`USING ${targets.join(", ")}`);
@@ -6722,7 +6301,7 @@ const pushDeleteSql = (ctx, table, query, quotedAs) => {
6722
6301
  }
6723
6302
  pushWhereStatementSql(ctx, table, query, quotedAs);
6724
6303
  if (conditions) {
6725
- if (((_b = query.and) == null ? void 0 : _b.length) || ((_c = query.or) == null ? void 0 : _c.length) || query.scopes) {
6304
+ if (query.and?.length || query.or?.length || query.scopes) {
6726
6305
  ctx.sql.push("AND", conditions);
6727
6306
  } else {
6728
6307
  ctx.sql.push("WHERE", conditions);
@@ -6733,14 +6312,11 @@ const pushDeleteSql = (ctx, table, query, quotedAs) => {
6733
6312
 
6734
6313
  const pushTruncateSql = (ctx, table, query) => {
6735
6314
  ctx.sql.push("TRUNCATE", quoteSchemaAndTable(query.schema, table));
6736
- if (query.restartIdentity)
6737
- ctx.sql.push("RESTART IDENTITY");
6738
- if (query.cascade)
6739
- ctx.sql.push("CASCADE");
6315
+ if (query.restartIdentity) ctx.sql.push("RESTART IDENTITY");
6316
+ if (query.cascade) ctx.sql.push("CASCADE");
6740
6317
  };
6741
6318
 
6742
6319
  const pushColumnInfoSql = (ctx, table, query) => {
6743
- var _a;
6744
6320
  ctx.sql.push(
6745
6321
  `SELECT * FROM information_schema.columns WHERE table_name = ${orchidCore.addValue(
6746
6322
  ctx.values,
@@ -6751,7 +6327,7 @@ const pushColumnInfoSql = (ctx, table, query) => {
6751
6327
  ctx.sql.push(
6752
6328
  `AND column_name = ${orchidCore.addValue(
6753
6329
  ctx.values,
6754
- ((_a = table.q.shape[query.column]) == null ? void 0 : _a.data.name) || query.column
6330
+ table.q.shape[query.column]?.data.name || query.column
6755
6331
  )}`
6756
6332
  );
6757
6333
  }
@@ -6760,30 +6336,21 @@ const pushColumnInfoSql = (ctx, table, query) => {
6760
6336
  const pushCopySql = (ctx, table, query, quotedAs) => {
6761
6337
  const { sql } = ctx;
6762
6338
  const { copy } = query;
6763
- const columns = copy.columns ? `(${copy.columns.map((item) => {
6764
- var _a;
6765
- return `"${((_a = query.shape[item]) == null ? void 0 : _a.data.name) || item}"`;
6766
- }).join(", ")})` : "";
6339
+ const columns = copy.columns ? `(${copy.columns.map((item) => `"${query.shape[item]?.data.name || item}"`).join(", ")})` : "";
6767
6340
  const target = "from" in copy ? copy.from : copy.to;
6768
6341
  sql.push(
6769
6342
  `COPY "${table.table}"${columns} ${"from" in copy ? "FROM" : "TO"} ${typeof target === "string" ? escapeString(target) : `PROGRAM ${escapeString(target.program)}`}`
6770
6343
  );
6771
6344
  if (Object.keys(copy).length > (copy.columns ? 2 : 1)) {
6772
6345
  const options = [];
6773
- if (copy.format)
6774
- options.push(`FORMAT ${copy.format}`);
6775
- if (copy.freeze)
6776
- options.push(`FREEZE ${copy.freeze}`);
6346
+ if (copy.format) options.push(`FORMAT ${copy.format}`);
6347
+ if (copy.freeze) options.push(`FREEZE ${copy.freeze}`);
6777
6348
  if (copy.delimiter)
6778
6349
  options.push(`DELIMITER ${escapeString(copy.delimiter)}`);
6779
- if (copy.null)
6780
- options.push(`NULL ${escapeString(copy.null)}`);
6781
- if (copy.header)
6782
- options.push(`HEADER ${copy.header}`);
6783
- if (copy.quote)
6784
- options.push(`QUOTE ${escapeString(copy.quote)}`);
6785
- if (copy.escape)
6786
- options.push(`ESCAPE ${escapeString(copy.escape)}`);
6350
+ if (copy.null) options.push(`NULL ${escapeString(copy.null)}`);
6351
+ if (copy.header) options.push(`HEADER ${copy.header}`);
6352
+ if (copy.quote) options.push(`QUOTE ${escapeString(copy.quote)}`);
6353
+ if (copy.escape) options.push(`ESCAPE ${escapeString(copy.escape)}`);
6787
6354
  if (copy.forceQuote)
6788
6355
  options.push(
6789
6356
  `FORCE_QUOTE ${copy.forceQuote === "*" ? "*" : `(${copy.forceQuote.map((x) => `"${x}"`).join(", ")})`}`
@@ -6796,8 +6363,7 @@ const pushCopySql = (ctx, table, query, quotedAs) => {
6796
6363
  options.push(
6797
6364
  `FORCE_NULL (${copy.forceNull.map((x) => `"${x}"`).join(", ")})`
6798
6365
  );
6799
- if (copy.encoding)
6800
- options.push(`ENCODING ${escapeString(copy.encoding)}`);
6366
+ if (copy.encoding) options.push(`ENCODING ${escapeString(copy.encoding)}`);
6801
6367
  sql.push(`WITH (${options.join(", ")})`);
6802
6368
  }
6803
6369
  pushWhereStatementSql(ctx, table, query, quotedAs);
@@ -6805,26 +6371,24 @@ const pushCopySql = (ctx, table, query, quotedAs) => {
6805
6371
 
6806
6372
  const toSQLCacheKey = Symbol("toSQLCache");
6807
6373
  const toSQL = (table, options) => {
6808
- return !(options == null ? void 0 : options.clearCache) && table.q[toSQLCacheKey] || (table.q[toSQLCacheKey] = makeSQL(table, options));
6374
+ return !options?.clearCache && table.q[toSQLCacheKey] || (table.q[toSQLCacheKey] = makeSQL(table, options));
6809
6375
  };
6810
6376
  const makeSQL = (table, options) => {
6811
- var _a;
6812
6377
  const query = table.q;
6813
6378
  const sql = [];
6814
- const values = (options == null ? void 0 : options.values) || [];
6379
+ const values = options?.values || [];
6815
6380
  const ctx = {
6816
6381
  queryBuilder: table.queryBuilder,
6817
6382
  sql,
6818
6383
  values,
6819
- aliasValue: options == null ? void 0 : options.aliasValue
6384
+ aliasValue: options?.aliasValue
6820
6385
  };
6821
6386
  if (query.with) {
6822
6387
  pushWithSql(ctx, query.with);
6823
6388
  }
6824
6389
  if (query.type) {
6825
- const tableName = (_a = table.table) != null ? _a : query.as;
6826
- if (!tableName)
6827
- throw new Error(`Table is missing for ${query.type}`);
6390
+ const tableName = table.table ?? query.as;
6391
+ if (!tableName) throw new Error(`Table is missing for ${query.type}`);
6828
6392
  if (query.type === "truncate") {
6829
6393
  pushTruncateSql(ctx, tableName, query);
6830
6394
  return { text: sql.join(" "), values };
@@ -6889,8 +6453,7 @@ const makeSQL = (table, options) => {
6889
6453
  );
6890
6454
  sql.push(`GROUP BY ${group.join(", ")}`);
6891
6455
  }
6892
- if (query.having)
6893
- pushHavingSql(ctx, query, quotedAs);
6456
+ if (query.having) pushHavingSql(ctx, query, quotedAs);
6894
6457
  if (query.window) {
6895
6458
  const window = [];
6896
6459
  query.window.forEach((item) => {
@@ -6919,8 +6482,7 @@ const makeSQL = (table, options) => {
6919
6482
  orchidCore.isExpression(tableNames) ? tableNames.toSQL(ctx, quotedAs) : tableNames.map((x) => `"${x}"`).join(", ")
6920
6483
  );
6921
6484
  }
6922
- if (query.for.mode)
6923
- sql.push(query.for.mode);
6485
+ if (query.for.mode) sql.push(query.for.mode);
6924
6486
  }
6925
6487
  return { text: sql.join(" "), values, hookSelect: query.hookSelect };
6926
6488
  };
@@ -6934,78 +6496,39 @@ function pushLimitSQL(sql, values, q) {
6934
6496
  }
6935
6497
  }
6936
6498
 
6937
- var __defProp$b = Object.defineProperty;
6938
- var __getOwnPropSymbols$c = Object.getOwnPropertySymbols;
6939
- var __hasOwnProp$c = Object.prototype.hasOwnProperty;
6940
- var __propIsEnum$c = Object.prototype.propertyIsEnumerable;
6941
- var __defNormalProp$b = (obj, key, value) => key in obj ? __defProp$b(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6942
- var __spreadValues$b = (a, b) => {
6943
- for (var prop in b || (b = {}))
6944
- if (__hasOwnProp$c.call(b, prop))
6945
- __defNormalProp$b(a, prop, b[prop]);
6946
- if (__getOwnPropSymbols$c)
6947
- for (var prop of __getOwnPropSymbols$c(b)) {
6948
- if (__propIsEnum$c.call(b, prop))
6949
- __defNormalProp$b(a, prop, b[prop]);
6950
- }
6951
- return a;
6952
- };
6953
6499
  const cloneQuery = (q) => {
6954
- if (q.with)
6955
- q.with = q.with.slice(0);
6956
- if (q.select)
6957
- q.select = q.select.slice(0);
6958
- if (q.hookSelect)
6959
- q.hookSelect = new Map(q.hookSelect);
6960
- if (q.and)
6961
- q.and = q.and.slice(0);
6962
- if (q.or)
6963
- q.or = q.or.slice(0);
6964
- if (q.before)
6965
- q.before = q.before.slice(0);
6966
- if (q.after)
6967
- q.after = q.after.slice(0);
6968
- if (q.joinedShapes)
6969
- q.joinedShapes = __spreadValues$b({}, q.joinedShapes);
6970
- if (q.joinedComputeds)
6971
- q.joinedComputeds = __spreadValues$b({}, q.joinedComputeds);
6972
- if (q.batchParsers)
6973
- q.batchParsers = [...q.batchParsers];
6974
- if (q.joinedBatchParsers)
6975
- q.joinedBatchParsers = __spreadValues$b({}, q.joinedBatchParsers);
6976
- if (q.scopes)
6977
- q.scopes = __spreadValues$b({}, q.scopes);
6978
- if (q.parsers)
6979
- q.parsers = __spreadValues$b({}, q.parsers);
6500
+ if (q.with) q.with = q.with.slice(0);
6501
+ if (q.select) q.select = q.select.slice(0);
6502
+ if (q.hookSelect) q.hookSelect = new Map(q.hookSelect);
6503
+ if (q.and) q.and = q.and.slice(0);
6504
+ if (q.or) q.or = q.or.slice(0);
6505
+ if (q.before) q.before = q.before.slice(0);
6506
+ if (q.after) q.after = q.after.slice(0);
6507
+ if (q.joinedShapes) q.joinedShapes = { ...q.joinedShapes };
6508
+ if (q.joinedComputeds) q.joinedComputeds = { ...q.joinedComputeds };
6509
+ if (q.batchParsers) q.batchParsers = [...q.batchParsers];
6510
+ if (q.joinedBatchParsers) q.joinedBatchParsers = { ...q.joinedBatchParsers };
6511
+ if (q.scopes) q.scopes = { ...q.scopes };
6512
+ if (q.parsers) q.parsers = { ...q.parsers };
6980
6513
  if (q.updateData) {
6981
6514
  q.updateData = q.updateData.slice(
6982
6515
  0
6983
6516
  );
6984
6517
  }
6985
6518
  if (q.type === void 0) {
6986
- if (q.distinct)
6987
- q.distinct = q.distinct.slice(0);
6988
- if (q.join)
6989
- q.join = q.join.slice(0);
6990
- if (q.group)
6991
- q.group = q.group.slice(0);
6992
- if (q.having)
6993
- q.having = q.having.slice(0);
6994
- if (q.window)
6995
- q.window = q.window.slice(0);
6996
- if (q.union)
6997
- q.union = { b: q.union.b, u: q.union.u.slice(0) };
6998
- if (q.order)
6999
- q.order = q.order.slice(0);
6519
+ if (q.distinct) q.distinct = q.distinct.slice(0);
6520
+ if (q.join) q.join = q.join.slice(0);
6521
+ if (q.group) q.group = q.group.slice(0);
6522
+ if (q.having) q.having = q.having.slice(0);
6523
+ if (q.window) q.window = q.window.slice(0);
6524
+ if (q.union) q.union = { b: q.union.b, u: q.union.u.slice(0) };
6525
+ if (q.order) q.order = q.order.slice(0);
7000
6526
  } else if (q.type === "insert") {
7001
6527
  q.columns = q.columns.slice(0);
7002
6528
  q.values = Array.isArray(q.values) ? q.values.slice(0) : q.values;
7003
- if (q.using)
7004
- q.using = q.using.slice(0);
7005
- if (q.join)
7006
- q.join = q.join.slice(0);
7007
- if (q.beforeCreate)
7008
- q.beforeCreate = q.beforeCreate.slice(0);
6529
+ if (q.using) q.using = q.using.slice(0);
6530
+ if (q.join) q.join = q.join.slice(0);
6531
+ if (q.beforeCreate) q.beforeCreate = q.beforeCreate.slice(0);
7009
6532
  if (q.afterCreate) {
7010
6533
  q.afterCreate = q.afterCreate.slice(0);
7011
6534
  if (q.afterCreateSelect) {
@@ -7013,8 +6536,7 @@ const cloneQuery = (q) => {
7013
6536
  }
7014
6537
  }
7015
6538
  } else if (q.type === "update") {
7016
- if (q.beforeUpdate)
7017
- q.beforeUpdate = q.beforeUpdate.slice(0);
6539
+ if (q.beforeUpdate) q.beforeUpdate = q.beforeUpdate.slice(0);
7018
6540
  if (q.afterUpdate) {
7019
6541
  q.afterUpdate = q.afterUpdate.slice(0);
7020
6542
  if (q.afterUpdateSelect) {
@@ -7022,8 +6544,7 @@ const cloneQuery = (q) => {
7022
6544
  }
7023
6545
  }
7024
6546
  } else if (q.type === "delete") {
7025
- if (q.beforeDelete)
7026
- q.beforeDelete = q.beforeDelete.slice(0);
6547
+ if (q.beforeDelete) q.beforeDelete = q.beforeDelete.slice(0);
7027
6548
  if (q.afterDelete) {
7028
6549
  q.afterDelete = q.afterDelete.slice(0);
7029
6550
  if (q.afterDeleteSelect) {
@@ -7033,27 +6554,7 @@ const cloneQuery = (q) => {
7033
6554
  }
7034
6555
  };
7035
6556
 
7036
- var __defProp$a = Object.defineProperty;
7037
- var __defProps$3 = Object.defineProperties;
7038
- var __getOwnPropDescs$3 = Object.getOwnPropertyDescriptors;
7039
- var __getOwnPropSymbols$b = Object.getOwnPropertySymbols;
7040
- var __hasOwnProp$b = Object.prototype.hasOwnProperty;
7041
- var __propIsEnum$b = Object.prototype.propertyIsEnumerable;
7042
- var __defNormalProp$a = (obj, key, value) => key in obj ? __defProp$a(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
7043
- var __spreadValues$a = (a, b) => {
7044
- for (var prop in b || (b = {}))
7045
- if (__hasOwnProp$b.call(b, prop))
7046
- __defNormalProp$a(a, prop, b[prop]);
7047
- if (__getOwnPropSymbols$b)
7048
- for (var prop of __getOwnPropSymbols$b(b)) {
7049
- if (__propIsEnum$b.call(b, prop))
7050
- __defNormalProp$a(a, prop, b[prop]);
7051
- }
7052
- return a;
7053
- };
7054
- var __spreadProps$3 = (a, b) => __defProps$3(a, __getOwnPropDescs$3(b));
7055
6557
  const _chain = (fromQuery, toQuery, rel) => {
7056
- var _a, _b;
7057
6558
  const self = fromQuery;
7058
6559
  const toTable = toQuery;
7059
6560
  let query;
@@ -7073,38 +6574,23 @@ const _chain = (fromQuery, toQuery, rel) => {
7073
6574
  } else {
7074
6575
  query.q.relChain = [self];
7075
6576
  }
7076
- const aliases = self.q.as ? __spreadValues$a({}, self.q.aliases) : __spreadProps$3(__spreadValues$a({}, self.q.aliases), { [self.table]: self.table });
6577
+ const aliases = self.q.as ? { ...self.q.aliases } : { ...self.q.aliases, [self.table]: self.table };
7077
6578
  const relAliases = query.q.aliases;
7078
6579
  for (const as in relAliases) {
7079
6580
  aliases[as] = _queryResolveAlias(aliases, as);
7080
6581
  }
7081
6582
  query.q.as = aliases[query.q.as];
7082
6583
  query.q.aliases = aliases;
7083
- query.q.joinedShapes = __spreadValues$a({
7084
- [getQueryAs(self)]: self.q.shape
7085
- }, self.q.joinedShapes);
7086
- (_b = (_a = rel.modifyRelatedQuery) == null ? void 0 : _a.call(rel, query)) == null ? void 0 : _b(self);
6584
+ query.q.joinedShapes = {
6585
+ [getQueryAs(self)]: self.q.shape,
6586
+ ...self.q.joinedShapes
6587
+ };
6588
+ rel.modifyRelatedQuery?.(query)?.(self);
7087
6589
  return query;
7088
6590
  };
7089
6591
 
7090
- var __defProp$9 = Object.defineProperty;
7091
- var __getOwnPropSymbols$a = Object.getOwnPropertySymbols;
7092
- var __hasOwnProp$a = Object.prototype.hasOwnProperty;
7093
- var __propIsEnum$a = Object.prototype.propertyIsEnumerable;
7094
- var __defNormalProp$9 = (obj, key, value) => key in obj ? __defProp$9(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
7095
- var __spreadValues$9 = (a, b) => {
7096
- for (var prop in b || (b = {}))
7097
- if (__hasOwnProp$a.call(b, prop))
7098
- __defNormalProp$9(a, prop, b[prop]);
7099
- if (__getOwnPropSymbols$a)
7100
- for (var prop of __getOwnPropSymbols$a(b)) {
7101
- if (__propIsEnum$a.call(b, prop))
7102
- __defNormalProp$9(a, prop, b[prop]);
7103
- }
7104
- return a;
7105
- };
7106
6592
  const getClonedQueryData = (query) => {
7107
- const cloned = __spreadValues$9({}, query);
6593
+ const cloned = { ...query };
7108
6594
  delete cloned[toSQLCacheKey];
7109
6595
  cloneQuery(cloned);
7110
6596
  return cloned;
@@ -7148,8 +6634,7 @@ const resolveSubQueryCallback = (q, cb) => {
7148
6634
  return result;
7149
6635
  };
7150
6636
  const joinSubQuery = (q, sub) => {
7151
- if (!("relationConfig" in sub))
7152
- return sub;
6637
+ if (!("relationConfig" in sub)) return sub;
7153
6638
  return sub.relationConfig.joinQuery(
7154
6639
  sub,
7155
6640
  q
@@ -7266,10 +6751,8 @@ const typmodType = (typmod) => {
7266
6751
  } else {
7267
6752
  s += lwtypeName(type);
7268
6753
  }
7269
- if (typmod >= 0 && typmodGetZ(typmod))
7270
- s += "Z";
7271
- if (typmod >= 0 && typmodGetM(typmod))
7272
- s += "M";
6754
+ if (typmod >= 0 && typmodGetZ(typmod)) s += "Z";
6755
+ if (typmod >= 0 && typmodGetM(typmod)) s += "M";
7273
6756
  return s;
7274
6757
  };
7275
6758
  const typmodSrid = (typmod) => {
@@ -7289,36 +6772,17 @@ function uint8ArrToHex(arr) {
7289
6772
  }
7290
6773
  }
7291
6774
  const hexOctets = [];
7292
- for (let i = 0; i < arr.length; ++i)
7293
- hexOctets.push(byteToHex[arr[i]]);
6775
+ for (let i = 0; i < arr.length; ++i) hexOctets.push(byteToHex[arr[i]]);
7294
6776
  return hexOctets.join("");
7295
6777
  }
7296
6778
 
7297
- var __defProp$8 = Object.defineProperty;
7298
- var __getOwnPropSymbols$9 = Object.getOwnPropertySymbols;
7299
- var __hasOwnProp$9 = Object.prototype.hasOwnProperty;
7300
- var __propIsEnum$9 = Object.prototype.propertyIsEnumerable;
7301
- var __defNormalProp$8 = (obj, key, value) => key in obj ? __defProp$8(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
7302
- var __spreadValues$8 = (a, b) => {
7303
- for (var prop in b || (b = {}))
7304
- if (__hasOwnProp$9.call(b, prop))
7305
- __defNormalProp$8(a, prop, b[prop]);
7306
- if (__getOwnPropSymbols$9)
7307
- for (var prop of __getOwnPropSymbols$9(b)) {
7308
- if (__propIsEnum$9.call(b, prop))
7309
- __defNormalProp$8(a, prop, b[prop]);
7310
- }
7311
- return a;
7312
- };
7313
6779
  const getColumnTypes = (types, fn, nowSQL, language) => {
7314
- if (nowSQL)
7315
- orchidCore.setDefaultNowFn(nowSQL);
7316
- if (language)
7317
- orchidCore.setDefaultLanguage(language);
6780
+ if (nowSQL) orchidCore.setDefaultNowFn(nowSQL);
6781
+ if (language) orchidCore.setDefaultLanguage(language);
7318
6782
  return fn(types);
7319
6783
  };
7320
6784
  const makeColumnTypes = (schema) => {
7321
- return __spreadValues$8({
6785
+ return {
7322
6786
  schema,
7323
6787
  enum: schema.enum,
7324
6788
  array: schema.array,
@@ -7427,8 +6891,9 @@ const makeColumnTypes = (schema) => {
7427
6891
  point() {
7428
6892
  return new PostgisGeographyPointColumn(schema);
7429
6893
  }
7430
- }
7431
- }, orchidCore.makeTimestampsHelpers(makeRegexToFindInSql));
6894
+ },
6895
+ ...orchidCore.makeTimestampsHelpers(makeRegexToFindInSql)
6896
+ };
7432
6897
  };
7433
6898
  RawSQL.prototype.columnTypes = makeColumnTypes;
7434
6899
 
@@ -7443,13 +6908,13 @@ class VirtualColumn extends ColumnType {
7443
6908
  }
7444
6909
  }
7445
6910
 
7446
- const _UnknownColumn = class extends VirtualColumn {
6911
+ const _UnknownColumn = class _UnknownColumn extends VirtualColumn {
7447
6912
  constructor(schema) {
7448
6913
  super(schema, schema.unknown());
7449
6914
  }
7450
6915
  };
6916
+ _UnknownColumn.instance = new _UnknownColumn(defaultSchemaConfig);
7451
6917
  let UnknownColumn = _UnknownColumn;
7452
- UnknownColumn.instance = new _UnknownColumn(defaultSchemaConfig);
7453
6918
  RawSQL.prototype.result = { value: UnknownColumn.instance };
7454
6919
 
7455
6920
  const makeColumnsByType = (schema) => {
@@ -7513,21 +6978,6 @@ const makeColumnsByType = (schema) => {
7513
6978
  };
7514
6979
  };
7515
6980
 
7516
- var __getOwnPropSymbols$8 = Object.getOwnPropertySymbols;
7517
- var __hasOwnProp$8 = Object.prototype.hasOwnProperty;
7518
- var __propIsEnum$8 = Object.prototype.propertyIsEnumerable;
7519
- var __objRest$1 = (source, exclude) => {
7520
- var target = {};
7521
- for (var prop in source)
7522
- if (__hasOwnProp$8.call(source, prop) && exclude.indexOf(prop) < 0)
7523
- target[prop] = source[prop];
7524
- if (source != null && __getOwnPropSymbols$8)
7525
- for (var prop of __getOwnPropSymbols$8(source)) {
7526
- if (exclude.indexOf(prop) < 0 && __propIsEnum$8.call(source, prop))
7527
- target[prop] = source[prop];
7528
- }
7529
- return target;
7530
- };
7531
6981
  const { types } = pg;
7532
6982
  const defaultTypeParsers = {};
7533
6983
  for (const key in types.builtins) {
@@ -7547,8 +6997,7 @@ const returnArg = (arg) => arg;
7547
6997
  const rollbackSql = { text: "ROLLBACK" };
7548
6998
  const commitSql = { text: "COMMIT" };
7549
6999
  class Adapter {
7550
- constructor(_a) {
7551
- var _b = _a, { types: types2 = defaultTypeParsers } = _b, config = __objRest$1(_b, ["types"]);
7000
+ constructor({ types: types2 = defaultTypeParsers, ...config }) {
7552
7001
  this.types = types2;
7553
7002
  let schema = config.schema;
7554
7003
  if (config.databaseURL) {
@@ -7565,8 +7014,7 @@ class Adapter {
7565
7014
  config.databaseURL = url.toString();
7566
7015
  config.connectionString = config.databaseURL;
7567
7016
  }
7568
- if (schema)
7569
- this.schema = schema === "public" ? void 0 : schema;
7017
+ if (schema) this.schema = schema === "public" ? void 0 : schema;
7570
7018
  this.config = config;
7571
7019
  this.pool = new pg.Pool(config);
7572
7020
  if (config.connectRetry) {
@@ -7673,25 +7121,6 @@ class TransactionAdapter {
7673
7121
  }
7674
7122
  }
7675
7123
 
7676
- var __defProp$7 = Object.defineProperty;
7677
- var __defProps$2 = Object.defineProperties;
7678
- var __getOwnPropDescs$2 = Object.getOwnPropertyDescriptors;
7679
- var __getOwnPropSymbols$7 = Object.getOwnPropertySymbols;
7680
- var __hasOwnProp$7 = Object.prototype.hasOwnProperty;
7681
- var __propIsEnum$7 = Object.prototype.propertyIsEnumerable;
7682
- var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
7683
- var __spreadValues$7 = (a, b) => {
7684
- for (var prop in b || (b = {}))
7685
- if (__hasOwnProp$7.call(b, prop))
7686
- __defNormalProp$7(a, prop, b[prop]);
7687
- if (__getOwnPropSymbols$7)
7688
- for (var prop of __getOwnPropSymbols$7(b)) {
7689
- if (__propIsEnum$7.call(b, prop))
7690
- __defNormalProp$7(a, prop, b[prop]);
7691
- }
7692
- return a;
7693
- };
7694
- var __spreadProps$2 = (a, b) => __defProps$2(a, __getOwnPropDescs$2(b));
7695
7124
  class FnExpression extends orchidCore.Expression {
7696
7125
  /**
7697
7126
  * @param query - query object.
@@ -7717,12 +7146,10 @@ class FnExpression extends orchidCore.Expression {
7717
7146
  }
7718
7147
  // Builds function SQL.
7719
7148
  makeSQL(ctx, quotedAs) {
7720
- var _a;
7721
7149
  const sql = [`${this.fn}(`];
7722
7150
  const { values } = ctx;
7723
7151
  const { options } = this;
7724
- if (options.distinct && !options.withinGroup)
7725
- sql.push("DISTINCT ");
7152
+ if (options.distinct && !options.withinGroup) sql.push("DISTINCT ");
7726
7153
  sql.push(
7727
7154
  this.args.map((arg) => {
7728
7155
  if (typeof arg === "string") {
@@ -7749,13 +7176,11 @@ class FnExpression extends orchidCore.Expression {
7749
7176
  }
7750
7177
  }).join(", ")
7751
7178
  );
7752
- if (options.withinGroup)
7753
- sql.push(") WITHIN GROUP (");
7754
- else if (options.order)
7755
- sql.push(" ");
7179
+ if (options.withinGroup) sql.push(") WITHIN GROUP (");
7180
+ else if (options.order) sql.push(" ");
7756
7181
  if (options.order) {
7757
7182
  pushOrderBySql(
7758
- __spreadProps$2(__spreadValues$7({}, ctx), { sql }),
7183
+ { ...ctx, sql },
7759
7184
  this.q,
7760
7185
  quotedAs,
7761
7186
  orchidCore.toArray(options.order)
@@ -7768,7 +7193,7 @@ class FnExpression extends orchidCore.Expression {
7768
7193
  this.query,
7769
7194
  {
7770
7195
  and: options.filter ? [options.filter] : void 0,
7771
- or: (_a = options.filterOr) == null ? void 0 : _a.map((item) => [item]),
7196
+ or: options.filterOr?.map((item) => [item]),
7772
7197
  shape: this.q.shape,
7773
7198
  joinedShapes: this.q.joinedShapes
7774
7199
  },
@@ -8401,22 +7826,6 @@ class Clear {
8401
7826
  }
8402
7827
  }
8403
7828
 
8404
- var __defProp$6 = Object.defineProperty;
8405
- var __getOwnPropSymbols$6 = Object.getOwnPropertySymbols;
8406
- var __hasOwnProp$6 = Object.prototype.hasOwnProperty;
8407
- var __propIsEnum$6 = Object.prototype.propertyIsEnumerable;
8408
- var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8409
- var __spreadValues$6 = (a, b) => {
8410
- for (var prop in b || (b = {}))
8411
- if (__hasOwnProp$6.call(b, prop))
8412
- __defNormalProp$6(a, prop, b[prop]);
8413
- if (__getOwnPropSymbols$6)
8414
- for (var prop of __getOwnPropSymbols$6(b)) {
8415
- if (__propIsEnum$6.call(b, prop))
8416
- __defNormalProp$6(a, prop, b[prop]);
8417
- }
8418
- return a;
8419
- };
8420
7829
  const createSelect = (q) => {
8421
7830
  if (q.q.returnType === "void" || isSelectingCount(q)) {
8422
7831
  q.q.select = void 0;
@@ -8426,12 +7835,10 @@ const createSelect = (q) => {
8426
7835
  }
8427
7836
  };
8428
7837
  const processCreateItem = (q, item, rowIndex, ctx, encoders) => {
8429
- var _a, _b, _c;
8430
7838
  const { shape } = q.q;
8431
7839
  for (const key in item) {
8432
7840
  if (shape[key] instanceof VirtualColumn) {
8433
- (_b = (_a = shape[key]).create) == null ? void 0 : _b.call(
8434
- _a,
7841
+ shape[key].create?.(
8435
7842
  q,
8436
7843
  ctx,
8437
7844
  item,
@@ -8446,7 +7853,7 @@ const processCreateItem = (q, item, rowIndex, ctx, encoders) => {
8446
7853
  }
8447
7854
  if (!ctx.columns.has(key) && (shape[key] && !shape[key].data.computed || shape === anyShape) && item[key] !== void 0) {
8448
7855
  ctx.columns.set(key, ctx.columns.size);
8449
- encoders[key] = (_c = shape[key]) == null ? void 0 : _c.data.encode;
7856
+ encoders[key] = shape[key]?.data.encode;
8450
7857
  }
8451
7858
  }
8452
7859
  }
@@ -8459,7 +7866,7 @@ const handleOneData = (q, data, ctx) => {
8459
7866
  const encoders = {};
8460
7867
  const defaults = q.q.defaults;
8461
7868
  if (defaults) {
8462
- data = __spreadValues$6(__spreadValues$6({}, defaults), data);
7869
+ data = { ...defaults, ...data };
8463
7870
  }
8464
7871
  processCreateItem(q, data, 0, ctx, encoders);
8465
7872
  const columns = Array.from(ctx.columns.keys());
@@ -8477,7 +7884,7 @@ const handleManyData = (q, data, ctx) => {
8477
7884
  const encoders = {};
8478
7885
  const defaults = q.q.defaults;
8479
7886
  if (defaults) {
8480
- data = data.map((item) => __spreadValues$6(__spreadValues$6({}, defaults), item));
7887
+ data = data.map((item) => ({ ...defaults, ...item }));
8481
7888
  }
8482
7889
  data.forEach((item, i) => {
8483
7890
  processCreateItem(q, item, i, ctx, encoders);
@@ -8495,9 +7902,8 @@ const insert = (self, {
8495
7902
  columns,
8496
7903
  values
8497
7904
  }, kind, many) => {
8498
- var _a;
8499
7905
  const { q } = self;
8500
- if (!((_a = q.select) == null ? void 0 : _a.length)) {
7906
+ if (!q.select?.length) {
8501
7907
  q.returning = true;
8502
7908
  }
8503
7909
  delete q.and;
@@ -8506,14 +7912,12 @@ const insert = (self, {
8506
7912
  q.type = "insert";
8507
7913
  q.columns = columns;
8508
7914
  q.values = values;
8509
- if (!q.kind)
8510
- q.kind = kind;
7915
+ if (!q.kind) q.kind = kind;
8511
7916
  const { select, returnType } = q;
8512
7917
  if (!select) {
8513
7918
  if (returnType !== "void") {
8514
7919
  q.returnType = "valueOrThrow";
8515
- if (many)
8516
- q.returningMany = true;
7920
+ if (many) q.returningMany = true;
8517
7921
  }
8518
7922
  } else if (many) {
8519
7923
  if (returnType === "one" || returnType === "oneOrThrow") {
@@ -8529,14 +7933,13 @@ const insert = (self, {
8529
7933
  return self;
8530
7934
  };
8531
7935
  const getFromSelectColumns = (from, obj, many) => {
8532
- var _a;
8533
7936
  if (!many && !queryTypeWithLimitOne[from.q.returnType]) {
8534
7937
  throw new Error(
8535
7938
  "Cannot create based on a query which returns multiple records"
8536
7939
  );
8537
7940
  }
8538
7941
  const queryColumns = [];
8539
- (_a = from.q.select) == null ? void 0 : _a.forEach((item) => {
7942
+ from.q.select?.forEach((item) => {
8540
7943
  if (typeof item === "string") {
8541
7944
  const index = item.indexOf(".");
8542
7945
  queryColumns.push(index === -1 ? item : item.slice(index + 1));
@@ -8544,7 +7947,7 @@ const getFromSelectColumns = (from, obj, many) => {
8544
7947
  queryColumns.push(...Object.keys(item.selectAs));
8545
7948
  }
8546
7949
  });
8547
- if (obj == null ? void 0 : obj.columns) {
7950
+ if (obj?.columns) {
8548
7951
  queryColumns.push(...obj.columns);
8549
7952
  }
8550
7953
  return queryColumns;
@@ -8557,7 +7960,7 @@ const insertFromQuery = (q, from, many, data) => {
8557
7960
  q,
8558
7961
  {
8559
7962
  columns,
8560
- values: { from, values: obj == null ? void 0 : obj.values }
7963
+ values: { from, values: obj?.values }
8561
7964
  },
8562
7965
  "from",
8563
7966
  many
@@ -8585,8 +7988,7 @@ const _queryCreateMany = (q, data) => {
8585
7988
  const _queryInsertMany = (q, data) => {
8586
7989
  const ctx = createCtx();
8587
7990
  let result = insert(q, handleManyData(q, data, ctx), "object", true);
8588
- if (!data.length)
8589
- result = result.none();
7991
+ if (!data.length) result = result.none();
8590
7992
  return result;
8591
7993
  };
8592
7994
  const _queryCreateRaw = (q, args) => {
@@ -9224,15 +8626,13 @@ const forMethods = {
9224
8626
  noWait() {
9225
8627
  const q = _clone(this);
9226
8628
  const data = q.q;
9227
- if (data == null ? void 0 : data.for)
9228
- data.for.mode = "NO WAIT";
8629
+ if (data?.for) data.for.mode = "NO WAIT";
9229
8630
  return q;
9230
8631
  },
9231
8632
  skipLocked() {
9232
8633
  const q = _clone(this);
9233
8634
  const data = q.q;
9234
- if (data == null ? void 0 : data.for)
9235
- data.for.mode = "SKIP LOCKED";
8635
+ if (data?.for) data.for.mode = "SKIP LOCKED";
9236
8636
  return q;
9237
8637
  }
9238
8638
  };
@@ -9374,9 +8774,9 @@ class Having {
9374
8774
 
9375
8775
  const before = (q, key, cb) => pushQueryValue(q, `before${key}`, cb);
9376
8776
  const after = (q, key, select, cb, commit) => {
9377
- var _a, _b, _c;
8777
+ var _a, _b;
9378
8778
  pushQueryValue(q, `after${key}${commit ? "Commit" : ""}`, cb);
9379
- const set = (_c = (_a = q.q)[_b = `after${key}Select`]) != null ? _c : _a[_b] = /* @__PURE__ */ new Set();
8779
+ const set = (_a = q.q)[_b = `after${key}Select`] ?? (_a[_b] = /* @__PURE__ */ new Set());
9380
8780
  for (const column of select) {
9381
8781
  set.add(column);
9382
8782
  }
@@ -10356,22 +9756,6 @@ class JsonMethods {
10356
9756
  }
10357
9757
  }
10358
9758
 
10359
- var __defProp$5 = Object.defineProperty;
10360
- var __getOwnPropSymbols$5 = Object.getOwnPropertySymbols;
10361
- var __hasOwnProp$5 = Object.prototype.hasOwnProperty;
10362
- var __propIsEnum$5 = Object.prototype.propertyIsEnumerable;
10363
- var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
10364
- var __spreadValues$5 = (a, b) => {
10365
- for (var prop in b || (b = {}))
10366
- if (__hasOwnProp$5.call(b, prop))
10367
- __defNormalProp$5(a, prop, b[prop]);
10368
- if (__getOwnPropSymbols$5)
10369
- for (var prop of __getOwnPropSymbols$5(b)) {
10370
- if (__propIsEnum$5.call(b, prop))
10371
- __defNormalProp$5(a, prop, b[prop]);
10372
- }
10373
- return a;
10374
- };
10375
9759
  const mergableObjects = /* @__PURE__ */ new Set([
10376
9760
  "shape",
10377
9761
  "withShapes",
@@ -10402,7 +9786,7 @@ class MergeQueryMethods {
10402
9786
  a[key] = a[key] ? [...a[key], ...value] : value;
10403
9787
  }
10404
9788
  } else if (mergableObjects.has(key)) {
10405
- a[key] = a[key] ? __spreadValues$5(__spreadValues$5({}, a[key]), value) : value;
9789
+ a[key] = a[key] ? { ...a[key], ...value } : value;
10406
9790
  } else if (key === "union") {
10407
9791
  a[key] = a[key] ? {
10408
9792
  b: a[key].b,
@@ -10416,8 +9800,7 @@ class MergeQueryMethods {
10416
9800
  break;
10417
9801
  }
10418
9802
  }
10419
- if (b.returnType)
10420
- a.returnType = b.returnType;
9803
+ if (b.returnType) a.returnType = b.returnType;
10421
9804
  return query;
10422
9805
  }
10423
9806
  }
@@ -10567,25 +9950,6 @@ class Union {
10567
9950
  }
10568
9951
  }
10569
9952
 
10570
- var __defProp$4 = Object.defineProperty;
10571
- var __defProps$1 = Object.defineProperties;
10572
- var __getOwnPropDescs$1 = Object.getOwnPropertyDescriptors;
10573
- var __getOwnPropSymbols$4 = Object.getOwnPropertySymbols;
10574
- var __hasOwnProp$4 = Object.prototype.hasOwnProperty;
10575
- var __propIsEnum$4 = Object.prototype.propertyIsEnumerable;
10576
- var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
10577
- var __spreadValues$4 = (a, b) => {
10578
- for (var prop in b || (b = {}))
10579
- if (__hasOwnProp$4.call(b, prop))
10580
- __defNormalProp$4(a, prop, b[prop]);
10581
- if (__getOwnPropSymbols$4)
10582
- for (var prop of __getOwnPropSymbols$4(b)) {
10583
- if (__propIsEnum$4.call(b, prop))
10584
- __defNormalProp$4(a, prop, b[prop]);
10585
- }
10586
- return a;
10587
- };
10588
- var __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b));
10589
9953
  class WithMethods {
10590
9954
  with(name, second, third) {
10591
9955
  const q = _clone(this);
@@ -10598,10 +9962,11 @@ class WithMethods {
10598
9962
  } else {
10599
9963
  query = queryArg;
10600
9964
  }
10601
- if ((options == null ? void 0 : options.columns) === true) {
10602
- options = __spreadProps$1(__spreadValues$4({}, options), {
9965
+ if (options?.columns === true) {
9966
+ options = {
9967
+ ...options,
10603
9968
  columns: Object.keys(query.shape)
10604
- });
9969
+ };
10605
9970
  }
10606
9971
  pushQueryValue(q, "with", { n: name, o: options, q: query });
10607
9972
  const shape = getShapeFromSelect(query, true);
@@ -10611,7 +9976,7 @@ class WithMethods {
10611
9976
  });
10612
9977
  }
10613
9978
  withRecursive(name, ...args) {
10614
- var _a, _b, _c;
9979
+ var _a;
10615
9980
  const q = _clone(this);
10616
9981
  let [options, baseFn, recursiveFn] = args.length === 2 ? [{}, args[0], args[1]] : args;
10617
9982
  const arg = q.queryBuilder.clone();
@@ -10619,14 +9984,15 @@ class WithMethods {
10619
9984
  let query = typeof baseFn === "function" ? baseFn(arg) : baseFn;
10620
9985
  const shape = getShapeFromSelect(query, true);
10621
9986
  const withConfig = { shape, computeds: query.q.computeds };
10622
- ((_b = (_a = arg.q).withShapes) != null ? _b : _a.withShapes = {})[name] = withConfig;
9987
+ ((_a = arg.q).withShapes ?? (_a.withShapes = {}))[name] = withConfig;
10623
9988
  const recursive = recursiveFn(arg);
10624
- query = _queryUnion(query, [recursive], (_c = options.union) != null ? _c : "UNION ALL");
9989
+ query = _queryUnion(query, [recursive], options.union ?? "UNION ALL");
10625
9990
  options.recursive = true;
10626
9991
  if (options.columns === true) {
10627
- options = __spreadProps$1(__spreadValues$4({}, options), {
9992
+ options = {
9993
+ ...options,
10628
9994
  columns: Object.keys(shape)
10629
- });
9995
+ };
10630
9996
  }
10631
9997
  pushQueryValue(q, "with", { n: name, o: options, q: query });
10632
9998
  return setQueryObjectValue(q, "withShapes", name, withConfig);
@@ -10646,22 +10012,6 @@ class WithMethods {
10646
10012
  }
10647
10013
  }
10648
10014
 
10649
- var __defProp$3 = Object.defineProperty;
10650
- var __getOwnPropSymbols$3 = Object.getOwnPropertySymbols;
10651
- var __hasOwnProp$3 = Object.prototype.hasOwnProperty;
10652
- var __propIsEnum$3 = Object.prototype.propertyIsEnumerable;
10653
- var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
10654
- var __spreadValues$3 = (a, b) => {
10655
- for (var prop in b || (b = {}))
10656
- if (__hasOwnProp$3.call(b, prop))
10657
- __defNormalProp$3(a, prop, b[prop]);
10658
- if (__getOwnPropSymbols$3)
10659
- for (var prop of __getOwnPropSymbols$3(b)) {
10660
- if (__propIsEnum$3.call(b, prop))
10661
- __defNormalProp$3(a, prop, b[prop]);
10662
- }
10663
- return a;
10664
- };
10665
10015
  const _queryChangeCounter = (self, op, data) => {
10666
10016
  const q = self.q;
10667
10017
  q.type = "update";
@@ -10698,7 +10048,7 @@ const update = (self) => {
10698
10048
  };
10699
10049
  const _queryUpdate = (query, arg) => {
10700
10050
  const { q } = query;
10701
- const set = __spreadValues$3({}, arg);
10051
+ const set = { ...arg };
10702
10052
  pushQueryValue(query, "updateData", set);
10703
10053
  const { shape } = q;
10704
10054
  const ctx = {};
@@ -10740,8 +10090,7 @@ const _queryUpdate = (query, arg) => {
10740
10090
  }
10741
10091
  } else {
10742
10092
  const encode = shape[key].data.encode;
10743
- if (encode)
10744
- set[key] = encode(value);
10093
+ if (encode) set[key] = encode(value);
10745
10094
  }
10746
10095
  }
10747
10096
  }
@@ -11100,25 +10449,6 @@ class Update {
11100
10449
  }
11101
10450
  }
11102
10451
 
11103
- var __defProp$2 = Object.defineProperty;
11104
- var __defProps = Object.defineProperties;
11105
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
11106
- var __getOwnPropSymbols$2 = Object.getOwnPropertySymbols;
11107
- var __hasOwnProp$2 = Object.prototype.hasOwnProperty;
11108
- var __propIsEnum$2 = Object.prototype.propertyIsEnumerable;
11109
- var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
11110
- var __spreadValues$2 = (a, b) => {
11111
- for (var prop in b || (b = {}))
11112
- if (__hasOwnProp$2.call(b, prop))
11113
- __defNormalProp$2(a, prop, b[prop]);
11114
- if (__getOwnPropSymbols$2)
11115
- for (var prop of __getOwnPropSymbols$2(b)) {
11116
- if (__propIsEnum$2.call(b, prop))
11117
- __defNormalProp$2(a, prop, b[prop]);
11118
- }
11119
- return a;
11120
- };
11121
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
11122
10452
  class Headline extends orchidCore.Expression {
11123
10453
  constructor(q, source, params) {
11124
10454
  super();
@@ -11131,16 +10461,15 @@ class Headline extends orchidCore.Expression {
11131
10461
  makeSQL(ctx, quotedAs) {
11132
10462
  const { q, source, params } = this;
11133
10463
  const lang = getSearchLang(ctx, q, source, quotedAs);
11134
- const text = (params == null ? void 0 : params.text) ? params.text instanceof orchidCore.Expression ? params.text.toSQL(ctx, quotedAs) : columnToSql(ctx, q, q.shape, params.text, quotedAs) : getSearchText(ctx, q, source, quotedAs, true);
11135
- const options = (params == null ? void 0 : params.options) ? `, ${params.options instanceof orchidCore.Expression ? params.options.toSQL(ctx, quotedAs) : orchidCore.addValue(ctx.values, params.options)}` : "";
10464
+ const text = params?.text ? params.text instanceof orchidCore.Expression ? params.text.toSQL(ctx, quotedAs) : columnToSql(ctx, q, q.shape, params.text, quotedAs) : getSearchText(ctx, q, source, quotedAs, true);
10465
+ const options = params?.options ? `, ${params.options instanceof orchidCore.Expression ? params.options.toSQL(ctx, quotedAs) : orchidCore.addValue(ctx.values, params.options)}` : "";
11136
10466
  return `ts_headline(${lang}, ${text}, "${source.as}"${options})`;
11137
10467
  }
11138
10468
  }
11139
10469
  Object.assign(Headline, Operators.text);
11140
10470
  AggregateMethods.prototype.headline = function(search, params) {
11141
- var _a;
11142
10471
  const q = this;
11143
- const source = (_a = q.q.sources) == null ? void 0 : _a[search];
10472
+ const source = q.q.sources?.[search];
11144
10473
  if (!source)
11145
10474
  throw new OrchidOrmInternalError(q, `Search \`${search}\` is not defined`);
11146
10475
  return new Headline(
@@ -11342,9 +10671,10 @@ class SearchMethods {
11342
10671
  const q = _clone(this);
11343
10672
  if (!arg.as) {
11344
10673
  const as = saveSearchAlias(q, "@q", "joinedShapes");
11345
- arg = __spreadProps(__spreadValues$2({}, arg), {
10674
+ arg = {
10675
+ ...arg,
11346
10676
  as
11347
- });
10677
+ };
11348
10678
  }
11349
10679
  setQueryObjectValue(q, "sources", arg.as, arg);
11350
10680
  if (arg.order) {
@@ -11354,22 +10684,6 @@ class SearchMethods {
11354
10684
  }
11355
10685
  }
11356
10686
 
11357
- var __defProp$1 = Object.defineProperty;
11358
- var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
11359
- var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
11360
- var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
11361
- var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
11362
- var __spreadValues$1 = (a, b) => {
11363
- for (var prop in b || (b = {}))
11364
- if (__hasOwnProp$1.call(b, prop))
11365
- __defNormalProp$1(a, prop, b[prop]);
11366
- if (__getOwnPropSymbols$1)
11367
- for (var prop of __getOwnPropSymbols$1(b)) {
11368
- if (__propIsEnum$1.call(b, prop))
11369
- __defNormalProp$1(a, prop, b[prop]);
11370
- }
11371
- return a;
11372
- };
11373
10687
  function orCreate(query, data, updateData, mergeData) {
11374
10688
  const { q } = query;
11375
10689
  q.returnType = "one";
@@ -11385,12 +10699,11 @@ function orCreate(query, data, updateData, mergeData) {
11385
10699
  if (typeof data === "function") {
11386
10700
  data = data(updateData);
11387
10701
  }
11388
- if (mergeData)
11389
- data = __spreadValues$1(__spreadValues$1({}, mergeData), data);
10702
+ if (mergeData) data = { ...mergeData, ...data };
11390
10703
  const inner = q2.create(data);
11391
10704
  inner.q.handleResult = (q3, t, r, s) => {
11392
10705
  result = handleResult(q3, t, r, s);
11393
- return inner.q.hookSelect ? result.map((row) => __spreadValues$1({}, row)) : result;
10706
+ return inner.q.hookSelect ? result.map((row) => ({ ...row })) : result;
11394
10707
  };
11395
10708
  await inner;
11396
10709
  created = true;
@@ -11680,12 +10993,10 @@ class ScopeMethods {
11680
10993
  * @param scope - name of the scope to apply
11681
10994
  */
11682
10995
  scope(scope) {
11683
- var _a;
11684
10996
  const q = _clone(this);
11685
- if (!((_a = q.q.scopes) == null ? void 0 : _a[scope])) {
10997
+ if (!q.q.scopes?.[scope]) {
11686
10998
  const s = q.internal.scopes[scope];
11687
- if (!s)
11688
- throw new Error(`Scope ${scope} is not defined`);
10999
+ if (!s) throw new Error(`Scope ${scope} is not defined`);
11689
11000
  setQueryObjectValue(q, "scopes", scope, s);
11690
11001
  }
11691
11002
  return q;
@@ -11716,7 +11027,7 @@ class ScopeMethods {
11716
11027
  }
11717
11028
 
11718
11029
  function enableSoftDelete(q, table, shape, softDelete, scopes) {
11719
- var _a, _b;
11030
+ var _a;
11720
11031
  const column = softDelete === true ? "deletedAt" : softDelete;
11721
11032
  if (!shape[column]) {
11722
11033
  throw new Error(
@@ -11727,7 +11038,7 @@ function enableSoftDelete(q, table, shape, softDelete, scopes) {
11727
11038
  and: [{ [column]: null }]
11728
11039
  };
11729
11040
  scopes.deleted = scope;
11730
- ((_b = (_a = q.q).scopes) != null ? _b : _a.scopes = {}).nonDeleted = scope;
11041
+ ((_a = q.q).scopes ?? (_a.scopes = {})).nonDeleted = scope;
11731
11042
  const _del = _softDelete(
11732
11043
  column,
11733
11044
  q.internal.nowSQL
@@ -11810,8 +11121,7 @@ class OrExpression extends orchidCore.Expression {
11810
11121
  if (arg) {
11811
11122
  if (orchidCore.isExpression(arg)) {
11812
11123
  const sql = arg.toSQL(ctx, quotedAs);
11813
- if (sql)
11814
- res.push(sql);
11124
+ if (sql) res.push(sql);
11815
11125
  } else {
11816
11126
  res.push(`(${getSqlText(arg.toSQL(ctx))})`);
11817
11127
  }
@@ -11881,9 +11191,10 @@ class ExpressionMethods {
11881
11191
  let column;
11882
11192
  const index = arg.indexOf(".");
11883
11193
  if (index !== -1) {
11884
- const table = arg.slice(0, index);
11194
+ const as = q.q.as || q.table;
11195
+ const table = getFullColumnTable(q, arg, index, as);
11885
11196
  const col = arg.slice(index + 1);
11886
- if (table === (q.q.as || q.table)) {
11197
+ if (table === as) {
11887
11198
  column = shape[col];
11888
11199
  } else {
11889
11200
  column = q.q.joinedShapes[table][col];
@@ -12391,10 +11702,10 @@ class QueryMethods {
12391
11702
  const query = _clone(this);
12392
11703
  const q = query.q;
12393
11704
  q.type = "truncate";
12394
- if (options == null ? void 0 : options.restartIdentity) {
11705
+ if (options?.restartIdentity) {
12395
11706
  q.restartIdentity = true;
12396
11707
  }
12397
- if (options == null ? void 0 : options.cascade) {
11708
+ if (options?.cascade) {
12398
11709
  q.cascade = true;
12399
11710
  }
12400
11711
  return _queryExec(query);
@@ -12565,9 +11876,12 @@ class QueryMethods {
12565
11876
  * @param fn - helper function
12566
11877
  */
12567
11878
  makeHelper(fn) {
11879
+ const as = this.q.as || this.table;
12568
11880
  return (query, ...args) => {
12569
11881
  const q = _clone(query);
12570
- q.q.as = void 0;
11882
+ if (q.q.as) {
11883
+ setQueryObjectValue(q, "aliases", as, q.q.as);
11884
+ }
12571
11885
  return fn(q, ...args);
12572
11886
  };
12573
11887
  }
@@ -12644,12 +11958,12 @@ orchidCore.applyMixins(QueryMethods, [
12644
11958
 
12645
11959
  const makeIndex = (columns, first, second) => {
12646
11960
  if (typeof first === "string") {
12647
- const options = second != null ? second : {};
11961
+ const options = second ?? {};
12648
11962
  return {
12649
11963
  index: { columns, options, name: first }
12650
11964
  };
12651
11965
  } else {
12652
- const options = first != null ? first : {};
11966
+ const options = first ?? {};
12653
11967
  return {
12654
11968
  index: { columns, options }
12655
11969
  };
@@ -12666,16 +11980,16 @@ const tableDataMethods = {
12666
11980
  },
12667
11981
  index: makeIndex,
12668
11982
  searchIndex(columns, ...[first, second]) {
12669
- var _a, _b;
11983
+ var _a;
12670
11984
  const input = makeIndex(columns, first, second);
12671
- (_b = (_a = input.index.options).using) != null ? _b : _a.using = "gin";
11985
+ (_a = input.index.options).using ?? (_a.using = "gin");
12672
11986
  input.index.options.tsVector = true;
12673
11987
  return input;
12674
11988
  },
12675
11989
  foreignKey(columns, fnOrTable, foreignColumns, options) {
12676
11990
  return {
12677
11991
  constraint: {
12678
- name: options == null ? void 0 : options.name,
11992
+ name: options?.name,
12679
11993
  references: { columns, fnOrTable, foreignColumns, options }
12680
11994
  }
12681
11995
  };
@@ -12700,7 +12014,6 @@ const parseTableData = (dataFn) => {
12700
12014
  return tableData;
12701
12015
  };
12702
12016
  const parseTableDataInput = (tableData, item) => {
12703
- var _a, _b, _c, _d;
12704
12017
  if (item.primaryKey) {
12705
12018
  tableData.primaryKey = item.primaryKey;
12706
12019
  } else if (item.index) {
@@ -12712,47 +12025,18 @@ const parseTableDataInput = (tableData, item) => {
12712
12025
  };
12713
12026
  }
12714
12027
  }
12715
- ((_a = tableData.indexes) != null ? _a : tableData.indexes = []).push(item.index);
12028
+ (tableData.indexes ?? (tableData.indexes = [])).push(item.index);
12716
12029
  } else if (item.constraint) {
12717
- ((_b = tableData.constraints) != null ? _b : tableData.constraints = []).push(item.constraint);
12718
- if ((_d = (_c = item.constraint.references) == null ? void 0 : _c.options) == null ? void 0 : _d.dropMode) {
12030
+ (tableData.constraints ?? (tableData.constraints = [])).push(item.constraint);
12031
+ if (item.constraint.references?.options?.dropMode) {
12719
12032
  item.constraint.dropMode = item.constraint.references.options.dropMode;
12720
12033
  }
12721
12034
  }
12722
12035
  };
12723
12036
 
12724
- var __defProp = Object.defineProperty;
12725
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
12726
- var __hasOwnProp = Object.prototype.hasOwnProperty;
12727
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
12728
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
12729
- var __spreadValues = (a, b) => {
12730
- for (var prop in b || (b = {}))
12731
- if (__hasOwnProp.call(b, prop))
12732
- __defNormalProp(a, prop, b[prop]);
12733
- if (__getOwnPropSymbols)
12734
- for (var prop of __getOwnPropSymbols(b)) {
12735
- if (__propIsEnum.call(b, prop))
12736
- __defNormalProp(a, prop, b[prop]);
12737
- }
12738
- return a;
12739
- };
12740
- var __objRest = (source, exclude) => {
12741
- var target = {};
12742
- for (var prop in source)
12743
- if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
12744
- target[prop] = source[prop];
12745
- if (source != null && __getOwnPropSymbols)
12746
- for (var prop of __getOwnPropSymbols(source)) {
12747
- if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
12748
- target[prop] = source[prop];
12749
- }
12750
- return target;
12751
- };
12752
12037
  const anyShape = {};
12753
12038
  class Db extends QueryMethods {
12754
12039
  constructor(adapter, queryBuilder, table = void 0, shape = anyShape, columnTypes, transactionStorage, options, tableData = orchidCore.emptyObject) {
12755
- var _a;
12756
12040
  super();
12757
12041
  this.adapter = adapter;
12758
12042
  this.queryBuilder = queryBuilder;
@@ -12804,10 +12088,8 @@ class Db extends QueryMethods {
12804
12088
  }
12805
12089
  if (typeof column.data.default === "function") {
12806
12090
  const arr = this.internal.runtimeDefaultColumns;
12807
- if (!arr)
12808
- this.internal.runtimeDefaultColumns = [key];
12809
- else
12810
- arr.push(key);
12091
+ if (!arr) this.internal.runtimeDefaultColumns = [key];
12092
+ else arr.push(key);
12811
12093
  if (!column.data.runtimeDefault) {
12812
12094
  const {
12813
12095
  data: { default: def, encode }
@@ -12822,10 +12104,10 @@ class Db extends QueryMethods {
12822
12104
  handleResult,
12823
12105
  logger,
12824
12106
  log: logParamToLogObject(logger, options.log),
12825
- autoPreparedStatements: (_a = options.autoPreparedStatements) != null ? _a : false,
12107
+ autoPreparedStatements: options.autoPreparedStatements ?? false,
12826
12108
  parsers: hasParsers ? parsers : void 0,
12827
12109
  language: options.language,
12828
- schema: options == null ? void 0 : options.schema
12110
+ schema: options?.schema
12829
12111
  };
12830
12112
  let shapeHasPrimaryKey;
12831
12113
  for (const key in shape) {
@@ -12840,17 +12122,14 @@ class Db extends QueryMethods {
12840
12122
  }
12841
12123
  if (!shapeHasPrimaryKey && !tableData.primaryKey && shape !== anyShape && options.noPrimaryKey !== "ignore") {
12842
12124
  const message = `Table ${table} has no primary key`;
12843
- if (options.noPrimaryKey === "error")
12844
- throw new Error(message);
12845
- else
12846
- logger.warn(message);
12125
+ if (options.noPrimaryKey === "error") throw new Error(message);
12126
+ else logger.warn(message);
12847
12127
  }
12848
12128
  const columns = Object.keys(
12849
12129
  shape
12850
12130
  );
12851
12131
  this.columns = columns;
12852
- if (options.computed)
12853
- applyComputedColumns(this, options.computed);
12132
+ if (options.computed) applyComputedColumns(this, options.computed);
12854
12133
  if (prepareSelectAll) {
12855
12134
  const list = [];
12856
12135
  const keys = {};
@@ -12962,21 +12241,19 @@ class Db extends QueryMethods {
12962
12241
  * use this method to exchange a db column name to its runtime key.
12963
12242
  */
12964
12243
  columnNameToKey(name) {
12965
- var _a;
12966
12244
  let map = this.internal.columnNameToKeyMap;
12967
12245
  if (!map) {
12968
12246
  this.internal.columnNameToKeyMap = map = /* @__PURE__ */ new Map();
12969
12247
  const { shape } = this;
12970
12248
  for (const key in this.shape) {
12971
12249
  const column = shape[key];
12972
- map.set((_a = column.data.name) != null ? _a : key, key);
12250
+ map.set(column.data.name ?? key, key);
12973
12251
  }
12974
12252
  }
12975
12253
  return map.get(name);
12976
12254
  }
12977
12255
  }
12978
12256
  const performQuery = async (q, args, method) => {
12979
- var _a;
12980
12257
  const trx = q.internal.transactionStorage.getStore();
12981
12258
  let sql;
12982
12259
  if (orchidCore.isRawSQL(args[0])) {
@@ -12996,16 +12273,14 @@ const performQuery = async (q, args, method) => {
12996
12273
  values
12997
12274
  };
12998
12275
  }
12999
- const log = (_a = trx == null ? void 0 : trx.log) != null ? _a : q.q.log;
12276
+ const log = trx?.log ?? q.q.log;
13000
12277
  let logData;
13001
- if (log)
13002
- logData = log.beforeQuery(sql);
12278
+ if (log) logData = log.beforeQuery(sql);
13003
12279
  try {
13004
- const result = await ((trx == null ? void 0 : trx.adapter) || q.adapter)[method](
12280
+ const result = await (trx?.adapter || q.adapter)[method](
13005
12281
  sql
13006
12282
  );
13007
- if (log)
13008
- log.afterQuery(sql, logData);
12283
+ if (log) log.afterQuery(sql, logData);
13009
12284
  return result;
13010
12285
  } catch (err) {
13011
12286
  if (log) {
@@ -13016,27 +12291,20 @@ const performQuery = async (q, args, method) => {
13016
12291
  };
13017
12292
  orchidCore.applyMixins(Db, [QueryMethods]);
13018
12293
  Db.prototype.constructor = Db;
13019
- const createDb = (_a) => {
13020
- var _b = _a, {
13021
- log,
13022
- logger,
13023
- snakeCase,
13024
- schemaConfig = defaultSchemaConfig,
13025
- columnTypes: ctOrFn = makeColumnTypes(schemaConfig)
13026
- } = _b, options = __objRest(_b, [
13027
- "log",
13028
- "logger",
13029
- "snakeCase",
13030
- "schemaConfig",
13031
- "columnTypes"
13032
- ]);
13033
- var _a2, _b2;
12294
+ const createDb = ({
12295
+ log,
12296
+ logger,
12297
+ snakeCase,
12298
+ schemaConfig = defaultSchemaConfig,
12299
+ columnTypes: ctOrFn = makeColumnTypes(schemaConfig),
12300
+ ...options
12301
+ }) => {
13034
12302
  const adapter = "adapter" in options ? options.adapter : new Adapter(options);
13035
12303
  const commonOptions = {
13036
12304
  log,
13037
12305
  logger,
13038
- autoPreparedStatements: (_a2 = options.autoPreparedStatements) != null ? _a2 : false,
13039
- noPrimaryKey: (_b2 = options.noPrimaryKey) != null ? _b2 : "error",
12306
+ autoPreparedStatements: options.autoPreparedStatements ?? false,
12307
+ noPrimaryKey: options.noPrimaryKey ?? "error",
13040
12308
  nowSQL: options.nowSQL,
13041
12309
  snakeCase
13042
12310
  };
@@ -13058,10 +12326,10 @@ const createDb = (_a) => {
13058
12326
  adapter,
13059
12327
  qb,
13060
12328
  table,
13061
- typeof shape === "function" ? getColumnTypes(ct, shape, nowSQL, options2 == null ? void 0 : options2.language) : shape,
12329
+ typeof shape === "function" ? getColumnTypes(ct, shape, nowSQL, options2?.language) : shape,
13062
12330
  ct,
13063
12331
  transactionStorage,
13064
- __spreadValues(__spreadValues({}, commonOptions), options2),
12332
+ { ...commonOptions, ...options2 },
13065
12333
  parseTableData(dataFn)
13066
12334
  );
13067
12335
  };
@@ -13119,7 +12387,7 @@ const testTransaction = {
13119
12387
  * @param arg - ORM instance or a queryable instance (such as db.someTable).
13120
12388
  */
13121
12389
  start(arg) {
13122
- var _a, _b;
12390
+ var _a;
13123
12391
  const db = argToDb(arg);
13124
12392
  const { transactionStorage } = db.internal;
13125
12393
  const { getStore } = transactionStorage;
@@ -13131,7 +12399,7 @@ const testTransaction = {
13131
12399
  transaction: adapter.transaction
13132
12400
  }
13133
12401
  };
13134
- ((_b = (_a = db.internal)[trxForTest]) != null ? _b : _a[trxForTest] = []).push(data);
12402
+ ((_a = db.internal)[trxForTest] ?? (_a[trxForTest] = [])).push(data);
13135
12403
  return new Promise((resolve) => {
13136
12404
  data.promise = db.transaction(() => {
13137
12405
  resolve();
@@ -13153,7 +12421,7 @@ const testTransaction = {
13153
12421
  }
13154
12422
  }).finally(() => {
13155
12423
  const trx = db.internal.transactionStorage.getStore();
13156
- if (trx == null ? void 0 : trx.testTransactionCount) {
12424
+ if (trx?.testTransactionCount) {
13157
12425
  trx.testTransactionCount--;
13158
12426
  }
13159
12427
  db.internal.transactionStorage.getStore = getStore;
@@ -13166,16 +12434,14 @@ const testTransaction = {
13166
12434
  * @param arg - the same ORM or query argument passed into the `testTransaction.start`.
13167
12435
  */
13168
12436
  rollback(arg) {
13169
- var _a;
13170
12437
  const db = argToDb(arg);
13171
12438
  const data = db.internal[trxForTest];
13172
- const last = data == null ? void 0 : data.pop();
13173
- if (!last)
13174
- return;
13175
- if ((data == null ? void 0 : data.length) === 1) {
12439
+ const last = data?.pop();
12440
+ if (!last) return;
12441
+ if (data?.length === 1) {
13176
12442
  Object.assign(db.baseQuery.q.adapter, data[0].adapter);
13177
12443
  }
13178
- (_a = last.reject) == null ? void 0 : _a.call(last, new Rollback());
12444
+ last.reject?.(new Rollback());
13179
12445
  return last.promise;
13180
12446
  },
13181
12447
  /**
@@ -13185,10 +12451,9 @@ const testTransaction = {
13185
12451
  * @param arg - the same ORM or query argument passed into the `testTransaction.start`.
13186
12452
  */
13187
12453
  async close(arg) {
13188
- var _a;
13189
12454
  const db = argToDb(arg);
13190
12455
  await this.rollback(db);
13191
- if (((_a = db.internal[trxForTest]) == null ? void 0 : _a.length) === 0) {
12456
+ if (db.internal[trxForTest]?.length === 0) {
13192
12457
  return db.q.adapter.close();
13193
12458
  }
13194
12459
  }
@@ -13428,6 +12693,7 @@ exports.foreignKeyArgumentToCode = foreignKeyArgumentToCode;
13428
12693
  exports.getClonedQueryData = getClonedQueryData;
13429
12694
  exports.getColumnInfo = getColumnInfo;
13430
12695
  exports.getColumnTypes = getColumnTypes;
12696
+ exports.getFullColumnTable = getFullColumnTable;
13431
12697
  exports.getPrimaryKeys = getPrimaryKeys;
13432
12698
  exports.getQueryAs = getQueryAs;
13433
12699
  exports.getShapeFromSelect = getShapeFromSelect;