pqb 0.42.4 → 0.42.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.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
  };
@@ -3483,27 +3290,8 @@ const _queryRows = (q) => {
3483
3290
  return q;
3484
3291
  };
3485
3292
 
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;
3293
+ const _join = (query, require, type, first, args) => {
3294
+ var _a;
3507
3295
  let joinKey;
3508
3296
  let shape;
3509
3297
  let parsers;
@@ -3512,7 +3300,7 @@ const _join = (query, require2, type, first, args) => {
3512
3300
  let joinSubQuery = false;
3513
3301
  first = preprocessJoinArg(query, first);
3514
3302
  if (typeof first === "object") {
3515
- if (require2 && isQueryNone(first)) {
3303
+ if (require && isQueryNone(first)) {
3516
3304
  return _queryNone(query);
3517
3305
  }
3518
3306
  const q2 = first;
@@ -3538,12 +3326,11 @@ const _join = (query, require2, type, first, args) => {
3538
3326
  batchParsers = r.q.batchParsers;
3539
3327
  computeds = r.q.computeds;
3540
3328
  } 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;
3329
+ const w = query.q.withShapes?.[joinKey];
3330
+ shape = w?.shape;
3331
+ computeds = w?.computeds;
3544
3332
  if (shape) {
3545
- if (!require2)
3546
- shape = __spreadValues$i({}, shape);
3333
+ if (!require) shape = { ...shape };
3547
3334
  const arg = { parsers: {} };
3548
3335
  for (const key in shape) {
3549
3336
  addColumnParserToQuery(arg, key, shape[key]);
@@ -3558,7 +3345,7 @@ const _join = (query, require2, type, first, args) => {
3558
3345
  joinSubQuery
3559
3346
  );
3560
3347
  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;
3348
+ const j = "j" in joinArgs ? joinArgs.r ?? joinArgs.j : "r" in joinArgs ? joinArgs.r : joinArgs.q;
3562
3349
  if (j.q.select || !j.q.selectAllColumns) {
3563
3350
  const shape2 = getShapeFromSelect(j, true);
3564
3351
  setQueryObjectValue(
@@ -3574,7 +3361,7 @@ const _join = (query, require2, type, first, args) => {
3574
3361
  j.q.parsers
3575
3362
  );
3576
3363
  if (j.q.batchParsers) {
3577
- ((_d = (_c = query.q).joinedBatchParsers) != null ? _d : _c.joinedBatchParsers = {})[joinKey] = j.q.batchParsers;
3364
+ ((_a = query.q).joinedBatchParsers ?? (_a.joinedBatchParsers = {}))[joinKey] = j.q.batchParsers;
3578
3365
  }
3579
3366
  setQueryObjectValue(
3580
3367
  query,
@@ -3592,7 +3379,7 @@ const _join = (query, require2, type, first, args) => {
3592
3379
  computeds
3593
3380
  );
3594
3381
  }
3595
- } else if (require2 && "r" in joinArgs && isQueryNone(joinArgs.r)) {
3382
+ } else if (require && "r" in joinArgs && isQueryNone(joinArgs.r)) {
3596
3383
  return _queryNone(query);
3597
3384
  } else {
3598
3385
  addAllShapesAndParsers(
@@ -3614,13 +3401,12 @@ const _join = (query, require2, type, first, args) => {
3614
3401
  return q;
3615
3402
  };
3616
3403
  const addAllShapesAndParsers = (query, joinKey, shape, parsers, batchParsers, computeds) => {
3617
- var _a, _b;
3618
- if (!joinKey)
3619
- return;
3404
+ var _a;
3405
+ if (!joinKey) return;
3620
3406
  setQueryObjectValue(query, "joinedShapes", joinKey, shape);
3621
3407
  setQueryObjectValue(query, "joinedParsers", joinKey, parsers);
3622
3408
  if (batchParsers) {
3623
- ((_b = (_a = query.q).joinedBatchParsers) != null ? _b : _a.joinedBatchParsers = {})[joinKey] = batchParsers;
3409
+ ((_a = query.q).joinedBatchParsers ?? (_a.joinedBatchParsers = {}))[joinKey] = batchParsers;
3624
3410
  }
3625
3411
  setQueryObjectValue(
3626
3412
  query,
@@ -3630,7 +3416,7 @@ const addAllShapesAndParsers = (query, joinKey, shape, parsers, batchParsers, co
3630
3416
  );
3631
3417
  };
3632
3418
  const _joinLateral = (self, type, arg, cb, as) => {
3633
- var _a, _b, _c, _d, _e, _f, _g;
3419
+ var _a, _b, _c;
3634
3420
  const q = self;
3635
3421
  let relation;
3636
3422
  if (typeof arg === "string") {
@@ -3638,15 +3424,16 @@ const _joinLateral = (self, type, arg, cb, as) => {
3638
3424
  if (relation) {
3639
3425
  arg = _clone(relation.relationConfig.query);
3640
3426
  } else {
3641
- const w = (_a = q.q.withShapes) == null ? void 0 : _a[arg];
3427
+ const w = q.q.withShapes?.[arg];
3642
3428
  if (w) {
3643
3429
  const t = Object.create(q.queryBuilder);
3644
3430
  t.table = arg;
3645
3431
  t.shape = w.shape;
3646
3432
  t.computeds = w.computeds;
3647
- t.q = __spreadProps$9(__spreadValues$i({}, t.q), {
3433
+ t.q = {
3434
+ ...t.q,
3648
3435
  shape: w.shape
3649
- });
3436
+ };
3650
3437
  t.baseQuery = t;
3651
3438
  arg = t;
3652
3439
  }
@@ -3655,7 +3442,7 @@ const _joinLateral = (self, type, arg, cb, as) => {
3655
3442
  const query = arg;
3656
3443
  query.q.joinTo = q;
3657
3444
  const joinedAs = getQueryAs(q);
3658
- ((_c = (_b = query.q).joinedShapes) != null ? _c : _b.joinedShapes = {})[joinedAs] = q.q.shape;
3445
+ ((_a = query.q).joinedShapes ?? (_a.joinedShapes = {}))[joinedAs] = q.q.shape;
3659
3446
  let result = resolveSubQueryCallback(query, cb);
3660
3447
  if (relation) {
3661
3448
  result = relation.relationConfig.joinQuery(
@@ -3669,11 +3456,11 @@ const _joinLateral = (self, type, arg, cb, as) => {
3669
3456
  setQueryObjectValue(q, "joinedShapes", joinKey, shape);
3670
3457
  setQueryObjectValue(q, "joinedParsers", joinKey, result.q.parsers);
3671
3458
  if (result.q.batchParsers) {
3672
- ((_e = (_d = q.q).joinedBatchParsers) != null ? _e : _d.joinedBatchParsers = {})[joinKey] = result.q.batchParsers;
3459
+ ((_b = q.q).joinedBatchParsers ?? (_b.joinedBatchParsers = {}))[joinKey] = result.q.batchParsers;
3673
3460
  }
3674
3461
  }
3675
3462
  as || (as = getQueryAs(result));
3676
- ((_g = (_f = q.q).joinedComputeds) != null ? _g : _f.joinedComputeds = {})[as] = result.q.computeds;
3463
+ ((_c = q.q).joinedComputeds ?? (_c.joinedComputeds = {}))[as] = result.q.computeds;
3677
3464
  return pushQueryValue(q, "join", [type, result, as]);
3678
3465
  };
3679
3466
 
@@ -3737,11 +3524,9 @@ const parsePostgresArray = (source, entries, transform) => {
3737
3524
  let pos = 0;
3738
3525
  if (source[0] === "[") {
3739
3526
  pos = source.indexOf("=") + 1;
3740
- if (!pos)
3741
- pos = source.length;
3527
+ if (!pos) pos = source.length;
3742
3528
  }
3743
- if (source[pos] === "{")
3744
- pos++;
3529
+ if (source[pos] === "{") pos++;
3745
3530
  let recorded = "";
3746
3531
  while (pos < source.length) {
3747
3532
  const character = source[pos++];
@@ -3762,8 +3547,7 @@ const parsePostgresArray = (source, entries, transform) => {
3762
3547
  while (pos < source.length) {
3763
3548
  let char;
3764
3549
  while ((char = source[pos++]) === "\\") {
3765
- if (!(esc = !esc))
3766
- rec += "\\";
3550
+ if (!(esc = !esc)) rec += "\\";
3767
3551
  }
3768
3552
  if (esc) {
3769
3553
  esc = false;
@@ -4050,20 +3834,14 @@ const defaultSchemaConfig = {
4050
3834
 
4051
3835
  const escape = (value, migration, nested) => {
4052
3836
  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()}'`;
3837
+ if (type === "number" || type === "bigint") return String(value);
3838
+ else if (type === "string") return escapeString(value);
3839
+ else if (type === "boolean") return value ? "true" : "false";
3840
+ else if (value instanceof Date) return `'${value.toISOString()}'`;
4061
3841
  else if (Array.isArray(value))
4062
3842
  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));
3843
+ else if (value === null || value === void 0) return "NULL";
3844
+ else return escapeString(JSON.stringify(value));
4067
3845
  };
4068
3846
  const escapeForLog = (value) => escape(value);
4069
3847
  const escapeForMigration = (value) => escape(value, true);
@@ -4073,15 +3851,14 @@ const makeMessage = (colors, timeColor, time, sqlColor, sql, valuesColor, values
4073
3851
  const elapsed = process.hrtime(time);
4074
3852
  const formattedTime = `(${elapsed[0] ? `${elapsed[0]}s ` : ""}${(elapsed[1] / 1e6).toFixed(1)}ms)`;
4075
3853
  const result = `${colors ? timeColor(formattedTime) : formattedTime} ${colors ? sqlColor(sql) : sql}`;
4076
- if (!(values == null ? void 0 : values.length)) {
3854
+ if (!values?.length) {
4077
3855
  return result;
4078
3856
  }
4079
3857
  const formattedValues = `[${values.map(escapeForLog).join(", ")}]`;
4080
3858
  return `${result} ${colors ? valuesColor(formattedValues) : formattedValues}`;
4081
3859
  };
4082
3860
  const logParamToLogObject = (logger, log) => {
4083
- if (!log)
4084
- return;
3861
+ if (!log) return;
4085
3862
  const logObject = Object.assign(
4086
3863
  {
4087
3864
  colors: true,
@@ -4129,25 +3906,6 @@ class QueryLog {
4129
3906
  }
4130
3907
  }
4131
3908
 
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
3909
  const commitSql$1 = {
4152
3910
  text: "COMMIT"
4153
3911
  };
@@ -4171,7 +3929,6 @@ const _afterCommitError = (result, hookResults, catchAfterCommitError) => {
4171
3929
  };
4172
3930
  class Transaction {
4173
3931
  async transaction(cbOrOptions, cb) {
4174
- var _a;
4175
3932
  let options;
4176
3933
  let fn;
4177
3934
  if (typeof cbOrOptions === "function") {
@@ -4184,15 +3941,13 @@ class Transaction {
4184
3941
  const sql = {
4185
3942
  values: orchidCore.emptyArray
4186
3943
  };
4187
- const log = options.log !== void 0 ? (_a = this.q.log) != null ? _a : logParamToLogObject(this.q.logger, options.log) : this.q.log;
3944
+ const log = options.log !== void 0 ? this.q.log ?? logParamToLogObject(this.q.logger, options.log) : this.q.log;
4188
3945
  let logData;
4189
3946
  let trx = this.internal.transactionStorage.getStore();
4190
3947
  const transactionId = trx ? trx.transactionId + 1 : 0;
4191
3948
  const callback = (adapter) => {
4192
- if (log)
4193
- log.afterQuery(sql, logData);
4194
- if (log)
4195
- logData = log.beforeQuery(commitSql$1);
3949
+ if (log) log.afterQuery(sql, logData);
3950
+ if (log) logData = log.beforeQuery(commitSql$1);
4196
3951
  if (trx) {
4197
3952
  trx.transactionId = transactionId;
4198
3953
  return fn();
@@ -4208,15 +3963,12 @@ class Transaction {
4208
3963
  };
4209
3964
  if (!trx) {
4210
3965
  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);
3966
+ if (log) logData = log.beforeQuery(sql);
4213
3967
  const result = await this.q.adapter.transaction(sql, callback).catch((err) => {
4214
- if (log)
4215
- log.afterQuery(rollbackSql$1, logData);
3968
+ if (log) log.afterQuery(rollbackSql$1, logData);
4216
3969
  throw err;
4217
3970
  });
4218
- if (log)
4219
- log.afterQuery(commitSql$1, logData);
3971
+ if (log) log.afterQuery(commitSql$1, logData);
4220
3972
  await runAfterCommit(
4221
3973
  trx.afterCommit,
4222
3974
  result
@@ -4225,8 +3977,7 @@ class Transaction {
4225
3977
  } else {
4226
3978
  try {
4227
3979
  sql.text = `SAVEPOINT "${transactionId}"`;
4228
- if (log)
4229
- logData = log.beforeQuery(sql);
3980
+ if (log) logData = log.beforeQuery(sql);
4230
3981
  const { adapter } = trx;
4231
3982
  await adapter.query(sql);
4232
3983
  let result;
@@ -4234,19 +3985,15 @@ class Transaction {
4234
3985
  result = await callback(adapter);
4235
3986
  } catch (err) {
4236
3987
  sql.text = `ROLLBACK TO SAVEPOINT "${transactionId}"`;
4237
- if (log)
4238
- logData = log.beforeQuery(sql);
3988
+ if (log) logData = log.beforeQuery(sql);
4239
3989
  await adapter.query(sql);
4240
- if (log)
4241
- log.afterQuery(sql, logData);
3990
+ if (log) log.afterQuery(sql, logData);
4242
3991
  throw err;
4243
3992
  }
4244
3993
  sql.text = `RELEASE SAVEPOINT "${transactionId}"`;
4245
- if (log)
4246
- logData = log.beforeQuery(sql);
3994
+ if (log) logData = log.beforeQuery(sql);
4247
3995
  await adapter.query(sql);
4248
- if (log)
4249
- log.afterQuery(sql, logData);
3996
+ if (log) log.afterQuery(sql, logData);
4250
3997
  if (transactionId === trx.testTransactionCount) {
4251
3998
  await runAfterCommit(
4252
3999
  trx.afterCommit,
@@ -4281,8 +4028,7 @@ class Transaction {
4281
4028
  */
4282
4029
  ensureTransaction(cb) {
4283
4030
  const trx = this.internal.transactionStorage.getStore();
4284
- if (trx)
4285
- return cb();
4031
+ if (trx) return cb();
4286
4032
  return Transaction.prototype.transaction.call(this, cb);
4287
4033
  }
4288
4034
  isInTransaction() {
@@ -4314,9 +4060,10 @@ const runAfterCommit = async (afterCommit, result) => {
4314
4060
  let r = 0;
4315
4061
  for (let i = 0, len = afterCommit.length; i < len; i += 3) {
4316
4062
  for (const fn of afterCommit[i + 2]) {
4317
- resultsWithNames.push(__spreadProps$8(__spreadValues$h({}, hookResults[r++]), {
4063
+ resultsWithNames.push({
4064
+ ...hookResults[r++],
4318
4065
  name: fn.name
4319
- }));
4066
+ });
4320
4067
  }
4321
4068
  }
4322
4069
  _afterCommitError(result, resultsWithNames, catchAfterCommitError);
@@ -4336,7 +4083,6 @@ const applyBatchTransforms = (query, batches) => {
4336
4083
  }
4337
4084
  };
4338
4085
  const finalizeNestedHookSelect = (batches, returnType, tempColumns, renames, key) => {
4339
- var _a;
4340
4086
  if (renames) {
4341
4087
  for (const { data } of batches) {
4342
4088
  for (const record of data) {
@@ -4348,7 +4094,7 @@ const finalizeNestedHookSelect = (batches, returnType, tempColumns, renames, key
4348
4094
  }
4349
4095
  }
4350
4096
  }
4351
- if (tempColumns == null ? void 0 : tempColumns.size) {
4097
+ if (tempColumns?.size) {
4352
4098
  for (const { data } of batches) {
4353
4099
  for (const record of data) {
4354
4100
  if (record) {
@@ -4371,30 +4117,11 @@ const finalizeNestedHookSelect = (batches, returnType, tempColumns, renames, key
4371
4117
  }
4372
4118
  } else if (returnType === "value" || returnType === "valueOrThrow") {
4373
4119
  for (const item of batches) {
4374
- item.parent[item.key] = (_a = item.data[0]) == null ? void 0 : _a[key];
4120
+ item.parent[item.key] = item.data[0]?.[key];
4375
4121
  }
4376
4122
  }
4377
4123
  };
4378
4124
 
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
4125
  class ComputedColumn {
4399
4126
  constructor(kind, deps, fn) {
4400
4127
  this.kind = kind;
@@ -4411,9 +4138,10 @@ const applyComputedColumns = (q, fn) => {
4411
4138
  for (const key in computed) {
4412
4139
  const item = computed[key];
4413
4140
  if (item instanceof ComputedColumn) {
4414
- q.q.computeds = __spreadProps$7(__spreadValues$g({}, q.q.computeds), {
4141
+ q.q.computeds = {
4142
+ ...q.q.computeds,
4415
4143
  [key]: item
4416
- });
4144
+ };
4417
4145
  } else {
4418
4146
  const data = (q.shape[key] = item.result.value || UnknownColumn.instance).data;
4419
4147
  data.computed = item;
@@ -4435,7 +4163,7 @@ const processComputedResult = (query, result) => {
4435
4163
  if (Array.isArray(res)) {
4436
4164
  saveBatchComputed(key, result, res);
4437
4165
  } else {
4438
- (promises != null ? promises : promises = []).push(
4166
+ (promises ?? (promises = [])).push(
4439
4167
  res.then(
4440
4168
  (res2) => saveBatchComputed(key, result, res2)
4441
4169
  )
@@ -4443,8 +4171,7 @@ const processComputedResult = (query, result) => {
4443
4171
  }
4444
4172
  }
4445
4173
  }
4446
- if (!promises)
4447
- return;
4174
+ if (!promises) return;
4448
4175
  return Promise.all(promises);
4449
4176
  };
4450
4177
  const processComputedBatches = (query, batches, originalReturnType, returnType, tempColumns, renames, key) => {
@@ -4480,7 +4207,7 @@ const processComputedBatches = (query, batches, originalReturnType, returnType,
4480
4207
  if (Array.isArray(res)) {
4481
4208
  saveBatchComputed(key2, data, res, blanks);
4482
4209
  } else {
4483
- (promises != null ? promises : promises = []).push(
4210
+ (promises ?? (promises = [])).push(
4484
4211
  res.then(
4485
4212
  (res2) => saveBatchComputed(key2, data, res2, blanks)
4486
4213
  )
@@ -4489,8 +4216,7 @@ const processComputedBatches = (query, batches, originalReturnType, returnType,
4489
4216
  }
4490
4217
  }
4491
4218
  }
4492
- if (!promises)
4493
- return;
4219
+ if (!promises) return;
4494
4220
  return Promise.all(promises).then(() => {
4495
4221
  finalizeNestedHookSelect(
4496
4222
  batches,
@@ -4504,7 +4230,7 @@ const processComputedBatches = (query, batches, originalReturnType, returnType,
4504
4230
  };
4505
4231
  const saveBatchComputed = (key, result, res, blanks) => {
4506
4232
  const len = result.length;
4507
- const actual = res.length + ((blanks == null ? void 0 : blanks.size) || 0);
4233
+ const actual = res.length + (blanks?.size || 0);
4508
4234
  if (len !== actual) {
4509
4235
  throw new Error(
4510
4236
  `Incorrect length of batch computed result for column ${key}. Expected ${len}, received ${actual}.`
@@ -4523,25 +4249,6 @@ const saveBatchComputed = (key, result, res, blanks) => {
4523
4249
  }
4524
4250
  };
4525
4251
 
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
4252
  const queryMethodByReturnType = {
4546
4253
  undefined: "query",
4547
4254
  all: "query",
@@ -4564,11 +4271,9 @@ let getThen;
4564
4271
  if (process.versions.bun) {
4565
4272
  getThen = function() {
4566
4273
  queryError = new Error();
4567
- if (!this.internal)
4568
- return maybeWrappedThen;
4274
+ if (!this.internal) return maybeWrappedThen;
4569
4275
  const trx = this.internal.transactionStorage.getStore();
4570
- if (!trx)
4571
- return maybeWrappedThen;
4276
+ if (!trx) return maybeWrappedThen;
4572
4277
  return (resolve, reject) => {
4573
4278
  return this.internal.transactionStorage.run(trx, () => {
4574
4279
  return maybeWrappedThen.call(this, resolve, reject);
@@ -4630,7 +4335,7 @@ function maybeWrappedThen(resolve, reject) {
4630
4335
  } else {
4631
4336
  return then(
4632
4337
  this,
4633
- (trx == null ? void 0 : trx.adapter) || this.q.adapter,
4338
+ trx?.adapter || this.q.adapter,
4634
4339
  trx,
4635
4340
  beforeHooks,
4636
4341
  afterHooks,
@@ -4647,11 +4352,10 @@ const callAfterHook = function(cb) {
4647
4352
  };
4648
4353
  const beginSql = { text: "BEGIN" };
4649
4354
  const then = async (q, adapter, trx, beforeHooks, afterHooks, afterCommitHooks, resolve, reject) => {
4650
- var _a, _b, _c;
4651
4355
  const { q: query } = q;
4652
4356
  let sql;
4653
4357
  let logData;
4654
- const log = (_a = trx == null ? void 0 : trx.log) != null ? _a : query.log;
4358
+ const log = trx?.log ?? query.log;
4655
4359
  const localError = queryError;
4656
4360
  try {
4657
4361
  if (beforeHooks || query.before) {
@@ -4687,11 +4391,9 @@ const then = async (q, adapter, trx, beforeHooks, afterHooks, afterCommitHooks,
4687
4391
  } else {
4688
4392
  const queryMethod = queryMethodByReturnType[tempReturnType];
4689
4393
  if (!trx) {
4690
- if (log)
4691
- logData = log.beforeQuery(beginSql);
4394
+ if (log) logData = log.beforeQuery(beginSql);
4692
4395
  await adapter.arrays(beginSql);
4693
- if (log)
4694
- log.afterQuery(beginSql, logData);
4396
+ if (log) log.afterQuery(beginSql, logData);
4695
4397
  }
4696
4398
  for (const item of sql.batch) {
4697
4399
  sql = item;
@@ -4711,11 +4413,9 @@ const then = async (q, adapter, trx, beforeHooks, afterHooks, afterCommitHooks,
4711
4413
  }
4712
4414
  }
4713
4415
  if (!trx) {
4714
- if (log)
4715
- logData = log.beforeQuery(commitSql$1);
4416
+ if (log) logData = log.beforeQuery(commitSql$1);
4716
4417
  await adapter.arrays(commitSql$1);
4717
- if (log)
4718
- log.afterQuery(commitSql$1, logData);
4418
+ if (log) log.afterQuery(commitSql$1, logData);
4719
4419
  }
4720
4420
  if (query.patchResult) {
4721
4421
  await query.patchResult(q, queryResult);
@@ -4730,9 +4430,8 @@ const then = async (q, adapter, trx, beforeHooks, afterHooks, afterCommitHooks,
4730
4430
  if (hookSelect) {
4731
4431
  for (const column of hookSelect.keys()) {
4732
4432
  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);
4433
+ if (as) (renames ?? (renames = {}))[column] = as;
4434
+ (tempColumns ?? (tempColumns = /* @__PURE__ */ new Set()))?.add(as || column);
4736
4435
  }
4737
4436
  if (renames) {
4738
4437
  for (const record of result) {
@@ -4745,8 +4444,7 @@ const then = async (q, adapter, trx, beforeHooks, afterHooks, afterCommitHooks,
4745
4444
  }
4746
4445
  if (query.selectedComputeds) {
4747
4446
  const promise = processComputedResult(query, result);
4748
- if (promise)
4749
- await promise;
4447
+ if (promise) await promise;
4750
4448
  }
4751
4449
  }
4752
4450
  const hasAfterHook = afterHooks || afterCommitHooks || query.after;
@@ -4764,7 +4462,7 @@ const then = async (q, adapter, trx, beforeHooks, afterHooks, afterCommitHooks,
4764
4462
  if (afterCommitHooks) {
4765
4463
  if (trx && // when inside test transactions, push to a transaction only unless it's the outer user transaction.
4766
4464
  (!trx.testTransactionCount || trx.transactionId + 1 > trx.testTransactionCount)) {
4767
- ((_c = trx.afterCommit) != null ? _c : trx.afterCommit = []).push(
4465
+ (trx.afterCommit ?? (trx.afterCommit = [])).push(
4768
4466
  result,
4769
4467
  q,
4770
4468
  afterCommitHooks
@@ -4784,7 +4482,8 @@ const then = async (q, adapter, trx, beforeHooks, afterHooks, afterCommitHooks,
4784
4482
  if (hookResults.some((result2) => result2.status === "rejected")) {
4785
4483
  _afterCommitError(
4786
4484
  result,
4787
- hookResults.map((result2, i) => __spreadProps$6(__spreadValues$f({}, result2), {
4485
+ hookResults.map((result2, i) => ({
4486
+ ...result2,
4788
4487
  name: afterCommitHooks[i].name
4789
4488
  })),
4790
4489
  q.q.catchAfterCommitError
@@ -4818,7 +4517,7 @@ const then = async (q, adapter, trx, beforeHooks, afterHooks, afterCommitHooks,
4818
4517
  if (query.transform) {
4819
4518
  result = orchidCore.applyTransforms(returnType, query.transform, result);
4820
4519
  }
4821
- return resolve == null ? void 0 : resolve(result);
4520
+ return resolve?.(result);
4822
4521
  } catch (err) {
4823
4522
  let error;
4824
4523
  if (err instanceof pg.DatabaseError) {
@@ -4844,7 +4543,7 @@ const then = async (q, adapter, trx, beforeHooks, afterHooks, afterCommitHooks,
4844
4543
  if (log && sql) {
4845
4544
  log.onError(error, sql, logData);
4846
4545
  }
4847
- return reject == null ? void 0 : reject(error);
4546
+ return reject?.(error);
4848
4547
  }
4849
4548
  };
4850
4549
  const assignError = (to, from) => {
@@ -4870,7 +4569,6 @@ const assignError = (to, from) => {
4870
4569
  return to;
4871
4570
  };
4872
4571
  const handleResult = (q, returnType, result, isSubQuery) => {
4873
- var _a, _b;
4874
4572
  const { parsers } = q.q;
4875
4573
  switch (returnType) {
4876
4574
  case "all": {
@@ -4887,20 +4585,16 @@ const handleResult = (q, returnType, result, isSubQuery) => {
4887
4585
  }
4888
4586
  case "one": {
4889
4587
  const { rows } = result;
4890
- if (!rows.length)
4891
- return;
4588
+ if (!rows.length) return;
4892
4589
  const promise = parseBatch(q, result);
4893
- if (parsers)
4894
- parseRecord(parsers, rows[0]);
4590
+ if (parsers) parseRecord(parsers, rows[0]);
4895
4591
  return promise ? promise.then(() => rows[0]) : rows[0];
4896
4592
  }
4897
4593
  case "oneOrThrow": {
4898
4594
  const { rows } = result;
4899
- if (!rows.length)
4900
- throw new NotFoundError(q);
4595
+ if (!rows.length) throw new NotFoundError(q);
4901
4596
  const promise = parseBatch(q, result);
4902
- if (parsers)
4903
- parseRecord(parsers, rows[0]);
4597
+ if (parsers) parseRecord(parsers, rows[0]);
4904
4598
  return promise ? promise.then(() => rows[0]) : rows[0];
4905
4599
  }
4906
4600
  case "rows": {
@@ -4908,8 +4602,7 @@ const handleResult = (q, returnType, result, isSubQuery) => {
4908
4602
  const promise = parseBatch(q, result);
4909
4603
  if (promise) {
4910
4604
  return promise.then(() => {
4911
- if (parsers)
4912
- parseRows(parsers, result.fields, rows);
4605
+ if (parsers) parseRows(parsers, result.fields, rows);
4913
4606
  return rows;
4914
4607
  });
4915
4608
  } else if (parsers) {
@@ -4934,11 +4627,10 @@ const handleResult = (q, returnType, result, isSubQuery) => {
4934
4627
  const promise = parseBatch(q, result);
4935
4628
  if (promise) {
4936
4629
  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;
4630
+ return rows[0]?.[0] !== void 0 ? parseValue(rows[0][0], parsers) : q.q.notFoundDefault;
4939
4631
  });
4940
4632
  }
4941
- return ((_a = rows[0]) == null ? void 0 : _a[0]) !== void 0 ? parseValue(rows[0][0], parsers) : q.q.notFoundDefault;
4633
+ return rows[0]?.[0] !== void 0 ? parseValue(rows[0][0], parsers) : q.q.notFoundDefault;
4942
4634
  }
4943
4635
  case "valueOrThrow": {
4944
4636
  if (q.q.returning) {
@@ -4951,14 +4643,11 @@ const handleResult = (q, returnType, result, isSubQuery) => {
4951
4643
  const promise = parseBatch(q, result);
4952
4644
  if (promise) {
4953
4645
  return promise.then(() => {
4954
- var _a2;
4955
- if (((_a2 = rows[0]) == null ? void 0 : _a2[0]) === void 0)
4956
- throw new NotFoundError(q);
4646
+ if (rows[0]?.[0] === void 0) throw new NotFoundError(q);
4957
4647
  return parseValue(rows[0][0], parsers);
4958
4648
  });
4959
4649
  }
4960
- if (((_b = rows[0]) == null ? void 0 : _b[0]) === void 0)
4961
- throw new NotFoundError(q);
4650
+ if (rows[0]?.[0] === void 0) throw new NotFoundError(q);
4962
4651
  return parseValue(rows[0][0], parsers);
4963
4652
  }
4964
4653
  case "void": {
@@ -4971,8 +4660,7 @@ const parseBatch = (q, queryResult) => {
4971
4660
  if (q.q.batchParsers) {
4972
4661
  for (const parser of q.q.batchParsers) {
4973
4662
  const res = parser.fn(parser.path, queryResult);
4974
- if (res)
4975
- (promises != null ? promises : promises = []).push(res);
4663
+ if (res) (promises ?? (promises = [])).push(res);
4976
4664
  }
4977
4665
  }
4978
4666
  return promises && Promise.all(promises);
@@ -4996,7 +4684,7 @@ const parseRows = (parsers, fields, rows) => {
4996
4684
  }
4997
4685
  };
4998
4686
  const parsePluck = (parsers, isSubQuery, rows) => {
4999
- const pluck = parsers == null ? void 0 : parsers.pluck;
4687
+ const pluck = parsers?.pluck;
5000
4688
  if (pluck) {
5001
4689
  for (let i = 0; i < rows.length; i++) {
5002
4690
  rows[i] = pluck(isSubQuery ? rows[i] : rows[i][0]);
@@ -5008,25 +4696,22 @@ const parsePluck = (parsers, isSubQuery, rows) => {
5008
4696
  }
5009
4697
  };
5010
4698
  const parseValue = (value, parsers) => {
5011
- const parser = parsers == null ? void 0 : parsers[orchidCore.getValueKey];
4699
+ const parser = parsers?.[orchidCore.getValueKey];
5012
4700
  return parser ? parser(value) : value;
5013
4701
  };
5014
4702
  const filterResult = (q, returnType, queryResult, result, tempColumns, hasAfterHook) => {
5015
- var _a;
5016
4703
  if (returnType === "all") {
5017
4704
  return filterAllResult(result, tempColumns, hasAfterHook);
5018
4705
  }
5019
4706
  if (returnType === "oneOrThrow" || returnType === "one") {
5020
4707
  let row = result[0];
5021
4708
  if (!row) {
5022
- if (returnType === "oneOrThrow")
5023
- throw new NotFoundError(q);
4709
+ if (returnType === "oneOrThrow") throw new NotFoundError(q);
5024
4710
  return void 0;
5025
- } else if (!(tempColumns == null ? void 0 : tempColumns.size)) {
4711
+ } else if (!tempColumns?.size) {
5026
4712
  return row;
5027
4713
  } else {
5028
- if (hasAfterHook)
5029
- row = __spreadValues$f({}, row);
4714
+ if (hasAfterHook) row = { ...row };
5030
4715
  for (const column of tempColumns) {
5031
4716
  delete row[column];
5032
4717
  }
@@ -5034,15 +4719,14 @@ const filterResult = (q, returnType, queryResult, result, tempColumns, hasAfterH
5034
4719
  }
5035
4720
  }
5036
4721
  if (returnType === "value") {
5037
- return (_a = result[0]) == null ? void 0 : _a[getFirstResultKey(q, queryResult)];
4722
+ return result[0]?.[getFirstResultKey(q, queryResult)];
5038
4723
  }
5039
4724
  if (returnType === "valueOrThrow") {
5040
4725
  if (q.q.returning) {
5041
4726
  return queryResult.rowCount;
5042
4727
  }
5043
4728
  const row = result[0];
5044
- if (!row)
5045
- throw new NotFoundError(q);
4729
+ if (!row) throw new NotFoundError(q);
5046
4730
  return row[getFirstResultKey(q, queryResult)];
5047
4731
  }
5048
4732
  if (returnType === "pluck") {
@@ -5066,10 +4750,10 @@ const getFirstResultKey = (q, queryResult) => {
5066
4750
  return;
5067
4751
  };
5068
4752
  const filterAllResult = (result, tempColumns, hasAfterHook) => {
5069
- if (tempColumns == null ? void 0 : tempColumns.size) {
4753
+ if (tempColumns?.size) {
5070
4754
  if (hasAfterHook) {
5071
4755
  return result.map((data) => {
5072
- const record = __spreadValues$f({}, data);
4756
+ const record = { ...data };
5073
4757
  for (const key of tempColumns) {
5074
4758
  delete record[key];
5075
4759
  }
@@ -5086,38 +4770,18 @@ const filterAllResult = (result, tempColumns, hasAfterHook) => {
5086
4770
  return result;
5087
4771
  };
5088
4772
 
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
4773
  const addParserForRawExpression = (q, key, raw) => {
5109
- if (raw.result.value)
5110
- addColumnParserToQuery(q.q, key, raw.result.value);
4774
+ if (raw.result.value) addColumnParserToQuery(q.q, key, raw.result.value);
5111
4775
  };
5112
4776
  const addParsersForSelectJoined = (q, arg, as = arg) => {
5113
- var _a, _b, _c, _d;
5114
- const parsers = (_a = q.q.joinedParsers) == null ? void 0 : _a[arg];
4777
+ var _a;
4778
+ const parsers = q.q.joinedParsers?.[arg];
5115
4779
  if (parsers) {
5116
4780
  orchidCore.setParserToQuery(q.q, as, (row) => parseRecord(parsers, row));
5117
4781
  }
5118
- const batchParsers = (_b = q.q.joinedBatchParsers) == null ? void 0 : _b[arg];
4782
+ const batchParsers = q.q.joinedBatchParsers?.[arg];
5119
4783
  if (batchParsers) {
5120
- ((_d = (_c = q.q).batchParsers) != null ? _d : _c.batchParsers = []).push(
4784
+ ((_a = q.q).batchParsers ?? (_a.batchParsers = [])).push(
5121
4785
  ...batchParsers.map((x) => ({
5122
4786
  path: [as, ...x.path],
5123
4787
  fn: x.fn
@@ -5126,21 +4790,20 @@ const addParsersForSelectJoined = (q, arg, as = arg) => {
5126
4790
  }
5127
4791
  };
5128
4792
  const addParserForSelectItem = (q, as, key, arg, joinQuery) => {
5129
- var _a, _b, _c, _d, _e;
4793
+ var _a, _b;
5130
4794
  if (typeof arg === "object" || typeof arg === "function") {
5131
4795
  const { q: query } = arg;
5132
4796
  if (query.batchParsers) {
5133
- const batchParsers = (_b = (_a = q.q).batchParsers) != null ? _b : _a.batchParsers = [];
4797
+ const batchParsers = (_a = q.q).batchParsers ?? (_a.batchParsers = []);
5134
4798
  for (const bp of query.batchParsers) {
5135
4799
  batchParsers.push({ path: [key, ...bp.path], fn: bp.fn });
5136
4800
  }
5137
4801
  }
5138
4802
  if (query.hookSelect || query.parsers || query.transform) {
5139
- const batchParsers = (_d = (_c = q.q).batchParsers) != null ? _d : _c.batchParsers = [];
4803
+ const batchParsers = (_b = q.q).batchParsers ?? (_b.batchParsers = []);
5140
4804
  batchParsers.push({
5141
4805
  path: [key],
5142
4806
  fn: (path, queryResult) => {
5143
- var _a2, _b2, _c2;
5144
4807
  const { rows } = queryResult;
5145
4808
  const originalReturnType = query.returnType || "all";
5146
4809
  let returnType = originalReturnType;
@@ -5177,20 +4840,17 @@ const addParserForSelectItem = (q, as, key, arg, joinQuery) => {
5177
4840
  if (parsers) {
5178
4841
  if (returnType === "one") {
5179
4842
  for (const { data } of batches) {
5180
- if (data)
5181
- parseRecord(parsers, data);
4843
+ if (data) parseRecord(parsers, data);
5182
4844
  }
5183
4845
  } else {
5184
4846
  for (const { data } of batches) {
5185
- if (!data)
5186
- throw new NotFoundError(arg);
4847
+ if (!data) throw new NotFoundError(arg);
5187
4848
  parseRecord(parsers, data);
5188
4849
  }
5189
4850
  }
5190
4851
  } else if (returnType !== "one") {
5191
4852
  for (const { data } of batches) {
5192
- if (!data)
5193
- throw new NotFoundError(arg);
4853
+ if (!data) throw new NotFoundError(arg);
5194
4854
  }
5195
4855
  }
5196
4856
  if (hookSelect) {
@@ -5201,7 +4861,7 @@ const addParserForSelectItem = (q, as, key, arg, joinQuery) => {
5201
4861
  break;
5202
4862
  }
5203
4863
  case "pluck": {
5204
- const parse = (_a2 = query.parsers) == null ? void 0 : _a2.pluck;
4864
+ const parse = query.parsers?.pluck;
5205
4865
  if (parse) {
5206
4866
  for (const { data } of batches) {
5207
4867
  for (let i = 0; i < data.length; i++) {
@@ -5213,7 +4873,7 @@ const addParserForSelectItem = (q, as, key, arg, joinQuery) => {
5213
4873
  }
5214
4874
  case "value":
5215
4875
  case "valueOrThrow": {
5216
- const parse = (_b2 = query.parsers) == null ? void 0 : _b2[orchidCore.getValueKey];
4876
+ const parse = query.parsers?.[orchidCore.getValueKey];
5217
4877
  if (parse) {
5218
4878
  if (returnType === "value") {
5219
4879
  for (const item of batches) {
@@ -5228,8 +4888,7 @@ const addParserForSelectItem = (q, as, key, arg, joinQuery) => {
5228
4888
  }
5229
4889
  } else if (returnType !== "value") {
5230
4890
  for (const { data } of batches) {
5231
- if (data === void 0)
5232
- throw new NotFoundError(arg);
4891
+ if (data === void 0) throw new NotFoundError(arg);
5233
4892
  }
5234
4893
  }
5235
4894
  if (hookSelect) {
@@ -5245,9 +4904,8 @@ const addParserForSelectItem = (q, as, key, arg, joinQuery) => {
5245
4904
  let renames;
5246
4905
  for (const column of hookSelect.keys()) {
5247
4906
  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);
4907
+ if (as2) (renames ?? (renames = {}))[column] = as2;
4908
+ (tempColumns ?? (tempColumns = /* @__PURE__ */ new Set()))?.add(as2 || column);
5251
4909
  }
5252
4910
  if (renames) {
5253
4911
  for (const { data } of batches) {
@@ -5272,8 +4930,7 @@ const addParserForSelectItem = (q, as, key, arg, joinQuery) => {
5272
4930
  renames,
5273
4931
  key
5274
4932
  );
5275
- if (maybePromise)
5276
- return maybePromise;
4933
+ if (maybePromise) return maybePromise;
5277
4934
  }
5278
4935
  finalizeNestedHookSelect(
5279
4936
  batches,
@@ -5288,7 +4945,7 @@ const addParserForSelectItem = (q, as, key, arg, joinQuery) => {
5288
4945
  }
5289
4946
  });
5290
4947
  }
5291
- if (!joinQuery && ((_e = arg.q) == null ? void 0 : _e.subQuery) && arg.q.expr) {
4948
+ if (!joinQuery && arg.q?.subQuery && arg.q.expr) {
5292
4949
  arg = arg.q.expr;
5293
4950
  }
5294
4951
  if (orchidCore.isExpression(arg)) {
@@ -5328,7 +4985,6 @@ const collectNestedSelectBatches = (batches, rows, path, last) => {
5328
4985
  };
5329
4986
  const emptyArrSQL = new RawSQL("'[]'");
5330
4987
  const processSelectArg = (q, as, arg, columnAs) => {
5331
- var _a;
5332
4988
  if (typeof arg === "string") {
5333
4989
  return setParserForSelectedString(q, arg, as, columnAs);
5334
4990
  }
@@ -5371,10 +5027,10 @@ const processSelectArg = (q, as, arg, columnAs) => {
5371
5027
  query = value;
5372
5028
  }
5373
5029
  }
5374
- const asOverride = (_a = value.q.aliases[key]) != null ? _a : key;
5030
+ const asOverride = value.q.aliases[key] ?? key;
5375
5031
  value.q.joinedForSelect = asOverride;
5376
5032
  if (asOverride !== key) {
5377
- aliases = __spreadProps$5(__spreadValues$e({}, q.q.aliases), { [key]: asOverride });
5033
+ aliases = { ...q.q.aliases, [key]: asOverride };
5378
5034
  }
5379
5035
  _joinLateral(
5380
5036
  q,
@@ -5385,8 +5041,7 @@ const processSelectArg = (q, as, arg, columnAs) => {
5385
5041
  );
5386
5042
  }
5387
5043
  }
5388
- if (aliases)
5389
- q.q.aliases = aliases;
5044
+ if (aliases) q.q.aliases = aliases;
5390
5045
  selectAs[key] = addParserForSelectItem(
5391
5046
  q,
5392
5047
  as,
@@ -5398,7 +5053,7 @@ const processSelectArg = (q, as, arg, columnAs) => {
5398
5053
  return { selectAs };
5399
5054
  };
5400
5055
  const setParserForSelectedString = (q, arg, as, columnAs) => {
5401
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
5056
+ var _a, _b;
5402
5057
  const index = arg.indexOf(".");
5403
5058
  if (index !== -1) {
5404
5059
  const table = arg.slice(0, index);
@@ -5408,55 +5063,53 @@ const setParserForSelectedString = (q, arg, as, columnAs) => {
5408
5063
  return table === as ? column : arg;
5409
5064
  } else if (table === as) {
5410
5065
  if (columnAs) {
5411
- const parser = (_a = q.q.parsers) == null ? void 0 : _a[column];
5412
- if (parser)
5413
- q.q.parsers[columnAs] = parser;
5066
+ const parser = q.q.parsers?.[column];
5067
+ if (parser) q.q.parsers[columnAs] = parser;
5414
5068
  }
5415
5069
  return handleComputed(q, q.q.computeds, column);
5416
5070
  } 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];
5071
+ const parser = q.q.joinedParsers?.[table]?.[column];
5072
+ if (parser) orchidCore.setParserToQuery(q.q, columnAs || column, parser);
5073
+ const batchParsers = q.q.joinedBatchParsers?.[table];
5421
5074
  if (batchParsers) {
5422
5075
  for (const bp of batchParsers) {
5423
5076
  if (bp.path[0] === column) {
5424
- ((_f = (_e = q.q).batchParsers) != null ? _f : _e.batchParsers = []).push(bp);
5077
+ ((_a = q.q).batchParsers ?? (_a.batchParsers = [])).push(bp);
5425
5078
  }
5426
5079
  }
5427
5080
  }
5428
- const computeds = (_g = q.q.joinedComputeds) == null ? void 0 : _g[table];
5429
- if (computeds == null ? void 0 : computeds[column]) {
5081
+ const computeds = q.q.joinedComputeds?.[table];
5082
+ if (computeds?.[column]) {
5430
5083
  const computed = computeds[column];
5431
- const map = (_i = (_h = q.q).hookSelect) != null ? _i : _h.hookSelect = /* @__PURE__ */ new Map();
5084
+ const map = (_b = q.q).hookSelect ?? (_b.hookSelect = /* @__PURE__ */ new Map());
5432
5085
  for (const column2 of computed.deps) {
5433
5086
  map.set(column2, { select: `${table}.${column2}` });
5434
5087
  }
5435
- q.q.selectedComputeds = __spreadProps$5(__spreadValues$e({}, q.q.selectedComputeds), {
5088
+ q.q.selectedComputeds = {
5089
+ ...q.q.selectedComputeds,
5436
5090
  [column]: computed
5437
- });
5091
+ };
5438
5092
  return;
5439
5093
  }
5440
5094
  return arg;
5441
5095
  }
5442
5096
  } else {
5443
5097
  if (columnAs) {
5444
- const parser = (_j = q.q.parsers) == null ? void 0 : _j[arg];
5445
- if (parser)
5446
- q.q.parsers[columnAs] = parser;
5098
+ const parser = q.q.parsers?.[arg];
5099
+ if (parser) q.q.parsers[columnAs] = parser;
5447
5100
  }
5448
5101
  return handleComputed(q, q.q.computeds, arg);
5449
5102
  }
5450
5103
  };
5451
5104
  const handleComputed = (q, computeds, column) => {
5452
- var _a, _b;
5453
- if (computeds == null ? void 0 : computeds[column]) {
5105
+ var _a;
5106
+ if (computeds?.[column]) {
5454
5107
  const computed = computeds[column];
5455
- const map = (_b = (_a = q.q).hookSelect) != null ? _b : _a.hookSelect = /* @__PURE__ */ new Map();
5108
+ const map = (_a = q.q).hookSelect ?? (_a.hookSelect = /* @__PURE__ */ new Map());
5456
5109
  for (const column2 of computed.deps) {
5457
5110
  map.set(column2, { select: column2 });
5458
5111
  }
5459
- q.q.selectedComputeds = __spreadProps$5(__spreadValues$e({}, q.q.selectedComputeds), { [column]: computed });
5112
+ q.q.selectedComputeds = { ...q.q.selectedComputeds, [column]: computed };
5460
5113
  return;
5461
5114
  }
5462
5115
  return column;
@@ -5501,8 +5154,7 @@ const getShapeFromSelect = (q, isSubQuery) => {
5501
5154
  const { returnType } = it.q;
5502
5155
  if (returnType === "value" || returnType === "valueOrThrow") {
5503
5156
  const type = it.q.getColumn;
5504
- if (type)
5505
- result[key] = type;
5157
+ if (type) result[key] = type;
5506
5158
  } else {
5507
5159
  result[key] = new JSONTextColumn(defaultSchemaConfig);
5508
5160
  }
@@ -5514,7 +5166,6 @@ const getShapeFromSelect = (q, isSubQuery) => {
5514
5166
  return result;
5515
5167
  };
5516
5168
  const addColumnToShapeFromSelect = (q, arg, shape, query, result, isSubQuery, key) => {
5517
- var _a, _b;
5518
5169
  const index = arg.indexOf(".");
5519
5170
  if (index !== -1) {
5520
5171
  const table = arg.slice(0, index);
@@ -5522,9 +5173,8 @@ const addColumnToShapeFromSelect = (q, arg, shape, query, result, isSubQuery, ke
5522
5173
  if (table === (q.q.as || q.table)) {
5523
5174
  result[key || column] = shape[column];
5524
5175
  } 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);
5176
+ const it = query.joinedShapes?.[table]?.[column];
5177
+ if (it) result[key || column] = maybeUnNameColumn(it, isSubQuery);
5528
5178
  }
5529
5179
  } else if (arg === "*") {
5530
5180
  for (const key2 in shape) {
@@ -5535,10 +5185,10 @@ const addColumnToShapeFromSelect = (q, arg, shape, query, result, isSubQuery, ke
5535
5185
  }
5536
5186
  };
5537
5187
  const maybeUnNameColumn = (column, isSubQuery) => {
5538
- return isSubQuery && (column == null ? void 0 : column.data.name) ? orchidCore.setColumnData(column, "name", void 0) : column;
5188
+ return isSubQuery && column?.data.name ? orchidCore.setColumnData(column, "name", void 0) : column;
5539
5189
  };
5540
5190
  function _querySelect(q, args) {
5541
- var _a, _b;
5191
+ var _a;
5542
5192
  if (q.q.returning) {
5543
5193
  q.q.select = q.q.returning = void 0;
5544
5194
  }
@@ -5550,17 +5200,15 @@ function _querySelect(q, args) {
5550
5200
  }
5551
5201
  const len = args.length;
5552
5202
  if (!len) {
5553
- (_b = (_a = q.q).select) != null ? _b : _a.select = [];
5203
+ (_a = q.q).select ?? (_a.select = []);
5554
5204
  return q;
5555
5205
  }
5556
5206
  const as = q.q.as || q.table;
5557
5207
  const selectArgs = [];
5558
5208
  for (const arg of args) {
5559
5209
  const item = processSelectArg(q, as, arg);
5560
- if (item)
5561
- selectArgs.push(item);
5562
- else if (item === false)
5563
- return _queryNone(q);
5210
+ if (item) selectArgs.push(item);
5211
+ else if (item === false) return _queryNone(q);
5564
5212
  }
5565
5213
  return pushQueryArray(q, "select", selectArgs);
5566
5214
  }
@@ -5603,8 +5251,7 @@ class SelectItemExpression extends orchidCore.Expression {
5603
5251
  this.item = item;
5604
5252
  this.result = { value };
5605
5253
  this.q = query.q;
5606
- if (value)
5607
- Object.assign(this, value.operators);
5254
+ if (value) Object.assign(this, value.operators);
5608
5255
  }
5609
5256
  // `makeSQL` acts similarly to how select args are handled
5610
5257
  makeSQL(ctx, quotedAs) {
@@ -5613,7 +5260,6 @@ class SelectItemExpression extends orchidCore.Expression {
5613
5260
  }
5614
5261
 
5615
5262
  const _getSelectableColumn = (q, arg) => {
5616
- var _a, _b;
5617
5263
  let type = q.q.shape[arg];
5618
5264
  if (!type) {
5619
5265
  const index = arg.indexOf(".");
@@ -5623,7 +5269,7 @@ const _getSelectableColumn = (q, arg) => {
5623
5269
  if (table === (q.q.as || q.table)) {
5624
5270
  type = q.shape[column];
5625
5271
  } else {
5626
- type = (_b = (_a = q.q.joinedShapes) == null ? void 0 : _a[table]) == null ? void 0 : _b[column];
5272
+ type = q.q.joinedShapes?.[table]?.[column];
5627
5273
  }
5628
5274
  }
5629
5275
  }
@@ -5631,8 +5277,7 @@ const _getSelectableColumn = (q, arg) => {
5631
5277
  };
5632
5278
  const _get = (query, returnType, arg) => {
5633
5279
  const q = query.q;
5634
- if (q.returning)
5635
- q.returning = void 0;
5280
+ if (q.returning) q.returning = void 0;
5636
5281
  q.returnType = returnType;
5637
5282
  let type;
5638
5283
  if (typeof arg === "string") {
@@ -5653,7 +5298,7 @@ const _get = (query, returnType, arg) => {
5653
5298
  }
5654
5299
  return setQueryOperators(
5655
5300
  query,
5656
- (type == null ? void 0 : type.operators) || Operators.any
5301
+ type?.operators || Operators.any
5657
5302
  );
5658
5303
  };
5659
5304
  function _queryGet(self, arg) {
@@ -5663,36 +5308,17 @@ function _queryGetOptional(self, arg) {
5663
5308
  return _get(self, "value", arg);
5664
5309
  }
5665
5310
 
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
5311
  const _queryAs = (self, as) => {
5686
5312
  const { q } = self;
5687
5313
  q.as = as;
5688
- q.aliases = __spreadProps$4(__spreadValues$d({}, q.aliases), {
5314
+ q.aliases = {
5315
+ ...q.aliases,
5689
5316
  [as]: q.aliases ? _queryResolveAlias(q.aliases, as) : as
5690
- });
5317
+ };
5691
5318
  return self;
5692
5319
  };
5693
5320
  const _queryResolveAlias = (aliases, as) => {
5694
- if (!aliases[as])
5695
- return as;
5321
+ if (!aliases[as]) return as;
5696
5322
  let suffix = 2;
5697
5323
  let privateAs;
5698
5324
  while (aliases[privateAs = as + suffix]) {
@@ -5718,30 +5344,13 @@ class AsMethods {
5718
5344
  }
5719
5345
  }
5720
5346
 
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
5347
  function queryFrom(self, arg) {
5738
- var _a, _b, _c;
5739
5348
  const data = self.q;
5740
5349
  if (typeof arg === "string") {
5741
5350
  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;
5351
+ const w = data.withShapes?.[arg];
5352
+ data.shape = w?.shape ?? orchidCore.emptyObject;
5353
+ data.computeds = w?.computeds;
5745
5354
  } else if (orchidCore.isExpression(arg)) {
5746
5355
  data.as || (data.as = "t");
5747
5356
  } else if (Array.isArray(arg)) {
@@ -5750,8 +5359,7 @@ function queryFrom(self, arg) {
5750
5359
  if (typeof item === "string") {
5751
5360
  const w = data.withShapes[item];
5752
5361
  Object.assign(shape, w.shape);
5753
- if (w.computeds)
5754
- data.computeds = __spreadValues$c(__spreadValues$c({}, data.computeds), w.computeds);
5362
+ if (w.computeds) data.computeds = { ...data.computeds, ...w.computeds };
5755
5363
  for (const key in w.shape) {
5756
5364
  addColumnParserToQuery(
5757
5365
  self,
@@ -5761,7 +5369,7 @@ function queryFrom(self, arg) {
5761
5369
  }
5762
5370
  } else if (!orchidCore.isExpression(item)) {
5763
5371
  Object.assign(shape, getShapeFromSelect(item, true));
5764
- Object.assign((_c = data.parsers) != null ? _c : data.parsers = {}, item.q.parsers);
5372
+ Object.assign(data.parsers ?? (data.parsers = {}), item.q.parsers);
5765
5373
  }
5766
5374
  }
5767
5375
  } else {
@@ -5877,11 +5485,9 @@ function queryJson(self, coalesce) {
5877
5485
 
5878
5486
  const pushSelectSql = (ctx, table, query, quotedAs) => {
5879
5487
  const sql = selectToSql(ctx, table, query, quotedAs);
5880
- if (sql)
5881
- ctx.sql.push(sql);
5488
+ if (sql) ctx.sql.push(sql);
5882
5489
  };
5883
5490
  const selectToSql = (ctx, table, query, quotedAs, hookSelect = query.hookSelect) => {
5884
- var _a, _b;
5885
5491
  let selected;
5886
5492
  const list = [];
5887
5493
  if (query.select) {
@@ -5890,7 +5496,7 @@ const selectToSql = (ctx, table, query, quotedAs, hookSelect = query.hookSelect)
5890
5496
  let sql;
5891
5497
  if (item === "*") {
5892
5498
  if (hookSelect) {
5893
- selected != null ? selected : selected = {};
5499
+ selected ?? (selected = {});
5894
5500
  for (const key in query.selectAllKeys || query.shape) {
5895
5501
  selected[key] = quotedAs;
5896
5502
  }
@@ -5901,8 +5507,7 @@ const selectToSql = (ctx, table, query, quotedAs, hookSelect = query.hookSelect)
5901
5507
  if (index !== -1) {
5902
5508
  const tableName = item.slice(0, index);
5903
5509
  const key = item.slice(index + 1);
5904
- if (hookSelect == null ? void 0 : hookSelect.get(key))
5905
- (selected != null ? selected : selected = {})[key] = `"${tableName}"`;
5510
+ if (hookSelect?.get(key)) (selected ?? (selected = {}))[key] = `"${tableName}"`;
5906
5511
  sql = tableColumnToSqlWithAs(
5907
5512
  ctx,
5908
5513
  table.q,
@@ -5910,12 +5515,9 @@ const selectToSql = (ctx, table, query, quotedAs, hookSelect = query.hookSelect)
5910
5515
  tableName,
5911
5516
  key,
5912
5517
  key === "*" ? tableName : key,
5913
- quotedAs,
5914
- true
5915
- );
5518
+ quotedAs);
5916
5519
  } else {
5917
- if (hookSelect == null ? void 0 : hookSelect.get(item))
5918
- (selected != null ? selected : selected = {})[item] = quotedAs;
5520
+ if (hookSelect?.get(item)) (selected ?? (selected = {}))[item] = quotedAs;
5919
5521
  sql = ownColumnToSqlWithAs(
5920
5522
  ctx,
5921
5523
  table.q,
@@ -5931,8 +5533,7 @@ const selectToSql = (ctx, table, query, quotedAs, hookSelect = query.hookSelect)
5931
5533
  if ("selectAs" in item) {
5932
5534
  const obj = item.selectAs;
5933
5535
  for (const as in obj) {
5934
- if (hookSelect)
5935
- (selected != null ? selected : selected = {})[as] = true;
5536
+ if (hookSelect) (selected ?? (selected = {}))[as] = true;
5936
5537
  const value = obj[as];
5937
5538
  if (typeof value === "object") {
5938
5539
  if (orchidCore.isExpression(value)) {
@@ -5972,26 +5573,25 @@ const selectToSql = (ctx, table, query, quotedAs, hookSelect = query.hookSelect)
5972
5573
  const tableName = select.slice(0, index);
5973
5574
  quotedTable = `"${tableName}"`;
5974
5575
  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}"`;
5576
+ col = table.q.joinedShapes?.[tableName]?.[columnName];
5577
+ sql = col?.data.computed ? col.data.computed.toSQL(ctx, `"${tableName}"`) : `"${tableName}"."${col?.data.name || columnName}"`;
5977
5578
  } else {
5978
5579
  quotedTable = quotedAs;
5979
5580
  columnName = select;
5980
5581
  col = query.shape[select];
5981
5582
  sql = simpleColumnToSQL(ctx, query, select, col, quotedAs);
5982
5583
  }
5983
- if (selected == null ? void 0 : selected[columnName]) {
5984
- if ((selected == null ? void 0 : selected[columnName]) === quotedTable) {
5584
+ if (selected?.[columnName]) {
5585
+ if (selected?.[columnName] === quotedTable) {
5985
5586
  hookSelect.delete(column);
5986
5587
  continue;
5987
5588
  }
5988
5589
  let i = 2;
5989
5590
  let name;
5990
- while (selected[name = `${column}${i}`])
5991
- i++;
5591
+ while (selected[name = `${column}${i}`]) i++;
5992
5592
  item.as = name;
5993
5593
  sql += ` "${name}"`;
5994
- } else if (col == null ? void 0 : col.data.name) {
5594
+ } else if (col?.data.name) {
5995
5595
  sql += ` "${columnName}"`;
5996
5596
  }
5997
5597
  list.push(sql);
@@ -6004,11 +5604,9 @@ function selectedObjectToSQL(ctx, quotedAs, item) {
6004
5604
  return ctx.aliasValue ? `${sql} r` : sql;
6005
5605
  }
6006
5606
  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(", ")) || "*";
5607
+ return query.join?.length ? query.selectAllColumns?.map((item) => `${quotedAs}.${item}`).join(", ") || `${quotedAs}.*` : query.selectAllColumns?.join(", ") || "*";
6009
5608
  };
6010
5609
  const pushSubQuerySql = (ctx, query, as, list, quotedAs) => {
6011
- var _a, _b, _c;
6012
5610
  const { returnType = "all" } = query.q;
6013
5611
  if (isQueryNone(query)) {
6014
5612
  let sql;
@@ -6019,7 +5617,7 @@ const pushSubQuerySql = (ctx, query, as, list, quotedAs) => {
6019
5617
  return;
6020
5618
  case "value":
6021
5619
  case "valueOrThrow":
6022
- if (query.q.returning || ((_a = query.q.expr) == null ? void 0 : _a.result.value) instanceof IntegerBaseColumn) {
5620
+ if (query.q.returning || query.q.expr?.result.value instanceof IntegerBaseColumn) {
6023
5621
  sql = "0";
6024
5622
  } else {
6025
5623
  return;
@@ -6050,8 +5648,7 @@ const pushSubQuerySql = (ctx, query, as, list, quotedAs) => {
6050
5648
  sql = `"${query.q.joinedForSelect}".r`;
6051
5649
  break;
6052
5650
  case "valueOrThrow":
6053
- if (query.q.returning)
6054
- return;
5651
+ if (query.q.returning) return;
6055
5652
  sql = `"${query.q.joinedForSelect}".r`;
6056
5653
  break;
6057
5654
  case "void":
@@ -6059,8 +5656,7 @@ const pushSubQuerySql = (ctx, query, as, list, quotedAs) => {
6059
5656
  default:
6060
5657
  throw new UnhandledTypeError(query, returnType);
6061
5658
  }
6062
- if (sql)
6063
- list.push(`${coalesce(ctx, query, sql, quotedAs)} "${as}"`);
5659
+ if (sql) list.push(`${coalesce(ctx, query, sql, quotedAs)} "${as}"`);
6064
5660
  return;
6065
5661
  }
6066
5662
  switch (returnType) {
@@ -6071,8 +5667,8 @@ const pushSubQuerySql = (ctx, query, as, list, quotedAs) => {
6071
5667
  break;
6072
5668
  case "pluck": {
6073
5669
  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])) {
5670
+ const first = select?.[0];
5671
+ if (!first && query.q.computeds?.[as]) {
6076
5672
  query = queryJson(query);
6077
5673
  } else if (!first) {
6078
5674
  throw new OrchidOrmInternalError(
@@ -6089,7 +5685,7 @@ const pushSubQuerySql = (ctx, query, as, list, quotedAs) => {
6089
5685
  }
6090
5686
  case "value":
6091
5687
  case "valueOrThrow":
6092
- if (!query.q.returning && ((_c = query.q.computeds) == null ? void 0 : _c[as])) {
5688
+ if (!query.q.returning && query.q.computeds?.[as]) {
6093
5689
  query = queryJson(query);
6094
5690
  }
6095
5691
  break;
@@ -6137,8 +5733,7 @@ const orderByToSql = (ctx, data, order, quotedAs) => {
6137
5733
  return sql.join(", ");
6138
5734
  };
6139
5735
  const addOrder = (ctx, data, column, quotedAs, dir) => {
6140
- var _a;
6141
- if ((_a = data.sources) == null ? void 0 : _a[column]) {
5736
+ if (data.sources?.[column]) {
6142
5737
  const search = data.sources[column];
6143
5738
  const order = dir || (!search.order || search.order === true ? orchidCore.emptyObject : search.order);
6144
5739
  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 +5742,8 @@ const addOrder = (ctx, data, column, quotedAs, dir) => {
6147
5742
  };
6148
5743
 
6149
5744
  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)})`;
5745
+ if (typeof window === "string") return `"${window}"`;
5746
+ if (orchidCore.isExpression(window)) return `(${window.toSQL(ctx, quotedAs)})`;
6154
5747
  const sql = [];
6155
5748
  if (window.partitionBy) {
6156
5749
  sql.push(
@@ -6167,38 +5760,33 @@ const windowToSql = (ctx, data, window, quotedAs) => {
6167
5760
 
6168
5761
  const pushHavingSql = (ctx, query, quotedAs) => {
6169
5762
  const conditions = havingToSql(ctx, query, quotedAs);
6170
- if (conditions == null ? void 0 : conditions.length)
6171
- ctx.sql.push("HAVING", conditions);
5763
+ if (conditions?.length) ctx.sql.push("HAVING", conditions);
6172
5764
  };
6173
5765
  const havingToSql = (ctx, query, quotedAs) => {
6174
- var _a;
6175
- return (_a = query.having) == null ? void 0 : _a.map(
5766
+ return query.having?.map(
6176
5767
  (it) => "raw" in it[0] ? templateLiteralToSQL(it, ctx, quotedAs) : it.map((item) => item.toSQL(ctx, quotedAs)).join(" AND ")
6177
5768
  ).join(" AND ");
6178
5769
  };
6179
5770
 
6180
5771
  const pushWithSql = (ctx, items) => {
6181
- if (!items.length)
6182
- return;
5772
+ if (!items.length) return;
6183
5773
  ctx.sql.push(
6184
5774
  "WITH",
6185
5775
  items.map((item) => {
6186
- var _a;
6187
5776
  let inner;
6188
5777
  if (item.q) {
6189
5778
  inner = getSqlText(makeSQL(item.q, ctx));
6190
5779
  } else {
6191
5780
  inner = item.s.toSQL(ctx, `"${item.n}"`);
6192
5781
  }
6193
- const o = (_a = item.o) != null ? _a : orchidCore.emptyObject;
5782
+ const o = item.o ?? orchidCore.emptyObject;
6194
5783
  return `${o.recursive ? "RECURSIVE " : ""}"${item.n}"${o.columns ? `(${o.columns.map((x) => `"${x}"`).join(", ")})` : ""} AS ${o.materialized ? "MATERIALIZED " : o.notMaterialized ? "NOT MATERIALIZED " : ""}(${inner})`;
6195
5784
  }).join(", ")
6196
5785
  );
6197
5786
  };
6198
5787
 
6199
5788
  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)
5789
+ if (q.q.returnType && q.q.returnType !== "all" || q.q.selectAllColumns || q.q.and?.length || q.q.or?.length || q.q.scopes)
6202
5790
  return false;
6203
5791
  const keys = Object.keys(q.q);
6204
5792
  return !keys.some((key) => queryKeysOfNotSimpleQuery.includes(key));
@@ -6267,8 +5855,7 @@ const getFrom = (ctx, table, data, quotedAs) => {
6267
5855
  return fromToSql(ctx, data, from, quotedAs);
6268
5856
  }
6269
5857
  let sql = quoteSchemaAndTable(data.schema, table.table);
6270
- if (data.only)
6271
- sql = `ONLY ${sql}`;
5858
+ if (data.only) sql = `ONLY ${sql}`;
6272
5859
  return sql;
6273
5860
  };
6274
5861
  const fromToSql = (ctx, data, from, quotedAs) => {
@@ -6293,13 +5880,11 @@ const fromToSql = (ctx, data, from, quotedAs) => {
6293
5880
  return (only === void 0 ? data.only : only) ? `ONLY ${sql}` : sql;
6294
5881
  };
6295
5882
  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");
5883
+ 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
5884
  };
6299
5885
  const getSearchText = (ctx, data, source, quotedAs, forHeadline) => {
6300
5886
  let sql = source.textSQL;
6301
- if (sql)
6302
- return sql;
5887
+ if (sql) return sql;
6303
5888
  if ("in" in source) {
6304
5889
  if (typeof source.in === "string") {
6305
5890
  sql = columnToSql(ctx, data, data.shape, source.in, quotedAs);
@@ -6354,11 +5939,10 @@ const MAX_BINDING_PARAMS = 65536;
6354
5939
 
6355
5940
  const quotedColumns = [];
6356
5941
  const makeInsertSql = (ctx, q, query, quotedAs) => {
6357
- var _a, _b, _c, _d;
6358
5942
  const { columns, shape } = query;
6359
5943
  quotedColumns.length = columns.length;
6360
5944
  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]}"`;
5945
+ quotedColumns[i] = `"${shape[columns[i]]?.data.name || columns[i]}"`;
6362
5946
  }
6363
5947
  let runtimeDefaults;
6364
5948
  if (q.internal.runtimeDefaultColumns) {
@@ -6375,7 +5959,7 @@ const makeInsertSql = (ctx, q, query, quotedAs) => {
6375
5959
  if (quotedColumns.length === 0) {
6376
5960
  const key = Object.keys(q.shape)[0];
6377
5961
  const column = q.shape[key];
6378
- quotedColumns[0] = `"${(column == null ? void 0 : column.data.name) || key}"`;
5962
+ quotedColumns[0] = `"${column?.data.name || key}"`;
6379
5963
  if (Array.isArray(values) && Array.isArray(values[0])) {
6380
5964
  values = values.map(() => [void 0]);
6381
5965
  }
@@ -6390,14 +5974,11 @@ const makeInsertSql = (ctx, q, query, quotedAs) => {
6390
5974
  const { target } = query.onConflict;
6391
5975
  if (target) {
6392
5976
  if (typeof target === "string") {
6393
- ctx.sql.push(`("${((_b = shape[target]) == null ? void 0 : _b.data.name) || target}")`);
5977
+ ctx.sql.push(`("${shape[target]?.data.name || target}")`);
6394
5978
  } else if (Array.isArray(target)) {
6395
5979
  ctx.sql.push(
6396
5980
  `(${target.reduce(
6397
- (sql, item, i) => {
6398
- var _a2;
6399
- return sql + (i ? ", " : "") + `"${((_a2 = shape[item]) == null ? void 0 : _a2.data.name) || item}"`;
6400
- },
5981
+ (sql, item, i) => sql + (i ? ", " : "") + `"${shape[item]?.data.name || item}"`,
6401
5982
  ""
6402
5983
  )})`
6403
5984
  );
@@ -6412,14 +5993,13 @@ const makeInsertSql = (ctx, q, query, quotedAs) => {
6412
5993
  const { merge } = query.onConflict;
6413
5994
  if (merge) {
6414
5995
  if (typeof merge === "string") {
6415
- const name = ((_c = shape[merge]) == null ? void 0 : _c.data.name) || merge;
5996
+ const name = shape[merge]?.data.name || merge;
6416
5997
  sql = `DO UPDATE SET "${name}" = excluded."${name}"`;
6417
5998
  } else if ("except" in merge) {
6418
5999
  sql = mergeColumnsSql(columns, quotedColumns, target, merge.except);
6419
6000
  } else {
6420
6001
  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;
6002
+ const name = shape[item]?.data.name || item;
6423
6003
  return sql2 + (i ? ", " : "") + `"${name}" = excluded."${name}"`;
6424
6004
  }, "")}`;
6425
6005
  }
@@ -6436,7 +6016,7 @@ const makeInsertSql = (ctx, q, query, quotedAs) => {
6436
6016
  const arr = [];
6437
6017
  for (const key in set) {
6438
6018
  arr.push(
6439
- `"${((_d = shape[key]) == null ? void 0 : _d.data.name) || key}" = ${orchidCore.addValue(
6019
+ `"${shape[key]?.data.name || key}" = ${orchidCore.addValue(
6440
6020
  ctx.values,
6441
6021
  set[key]
6442
6022
  )}`
@@ -6593,8 +6173,7 @@ const encodeRow = (ctx, values, q, QueryClass, row, runtimeDefaults, quotedAs) =
6593
6173
  };
6594
6174
  const pushReturningSql = (ctx, q, data, quotedAs, hookSelect, keyword = "RETURNING") => {
6595
6175
  const { select } = data;
6596
- if (!(hookSelect == null ? void 0 : hookSelect.size) && !select)
6597
- return hookSelect && /* @__PURE__ */ new Map();
6176
+ if (!hookSelect?.size && !select) return hookSelect && /* @__PURE__ */ new Map();
6598
6177
  ctx.sql.push(keyword);
6599
6178
  if (q.q.hookSelect || hookSelect) {
6600
6179
  const tempSelect = new Map(q.q.hookSelect);
@@ -6647,16 +6226,14 @@ const processData = (ctx, table, set, data, quotedAs) => {
6647
6226
  for (const item of data) {
6648
6227
  if (typeof item === "function") {
6649
6228
  const result = item(data);
6650
- if (result)
6651
- append = orchidCore.pushOrNewArray(append, result);
6229
+ if (result) append = orchidCore.pushOrNewArray(append, result);
6652
6230
  } else if (orchidCore.isExpression(item)) {
6653
6231
  set.push(item.toSQL(ctx, quotedAs));
6654
6232
  } else {
6655
6233
  const shape = table.q.shape;
6656
6234
  for (const key in item) {
6657
6235
  const value = item[key];
6658
- if (value === void 0)
6659
- continue;
6236
+ if (value === void 0) continue;
6660
6237
  set.push(
6661
6238
  `"${shape[key].data.name || key}" = ${processValue(
6662
6239
  ctx,
@@ -6670,8 +6247,7 @@ const processData = (ctx, table, set, data, quotedAs) => {
6670
6247
  }
6671
6248
  }
6672
6249
  }
6673
- if (append)
6674
- processData(ctx, table, set, append, quotedAs);
6250
+ if (append) processData(ctx, table, set, append, quotedAs);
6675
6251
  };
6676
6252
  const processValue = (ctx, table, QueryClass, key, value, quotedAs) => {
6677
6253
  if (value && typeof value === "object") {
@@ -6692,14 +6268,13 @@ const processValue = (ctx, table, QueryClass, key, value, quotedAs) => {
6692
6268
  };
6693
6269
 
6694
6270
  const pushDeleteSql = (ctx, table, query, quotedAs) => {
6695
- var _a, _b, _c;
6696
6271
  const from = `"${table.table}"`;
6697
6272
  ctx.sql.push(`DELETE FROM ${from}`);
6698
6273
  if (from !== quotedAs) {
6699
6274
  ctx.sql.push(`AS ${quotedAs}`);
6700
6275
  }
6701
6276
  let conditions;
6702
- if ((_a = query.join) == null ? void 0 : _a.length) {
6277
+ if (query.join?.length) {
6703
6278
  const targets = [];
6704
6279
  const ons = [];
6705
6280
  const joinSet = query.join.length > 1 ? /* @__PURE__ */ new Set() : null;
@@ -6707,13 +6282,11 @@ const pushDeleteSql = (ctx, table, query, quotedAs) => {
6707
6282
  const join = processJoinItem(ctx, table, query, item.args, quotedAs);
6708
6283
  const key = `${join.target}${join.on}`;
6709
6284
  if (joinSet) {
6710
- if (joinSet.has(key))
6711
- continue;
6285
+ if (joinSet.has(key)) continue;
6712
6286
  joinSet.add(key);
6713
6287
  }
6714
6288
  targets.push(join.target);
6715
- if (join.on)
6716
- ons.push(join.on);
6289
+ if (join.on) ons.push(join.on);
6717
6290
  }
6718
6291
  if (targets.length) {
6719
6292
  ctx.sql.push(`USING ${targets.join(", ")}`);
@@ -6722,7 +6295,7 @@ const pushDeleteSql = (ctx, table, query, quotedAs) => {
6722
6295
  }
6723
6296
  pushWhereStatementSql(ctx, table, query, quotedAs);
6724
6297
  if (conditions) {
6725
- if (((_b = query.and) == null ? void 0 : _b.length) || ((_c = query.or) == null ? void 0 : _c.length) || query.scopes) {
6298
+ if (query.and?.length || query.or?.length || query.scopes) {
6726
6299
  ctx.sql.push("AND", conditions);
6727
6300
  } else {
6728
6301
  ctx.sql.push("WHERE", conditions);
@@ -6733,14 +6306,11 @@ const pushDeleteSql = (ctx, table, query, quotedAs) => {
6733
6306
 
6734
6307
  const pushTruncateSql = (ctx, table, query) => {
6735
6308
  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");
6309
+ if (query.restartIdentity) ctx.sql.push("RESTART IDENTITY");
6310
+ if (query.cascade) ctx.sql.push("CASCADE");
6740
6311
  };
6741
6312
 
6742
6313
  const pushColumnInfoSql = (ctx, table, query) => {
6743
- var _a;
6744
6314
  ctx.sql.push(
6745
6315
  `SELECT * FROM information_schema.columns WHERE table_name = ${orchidCore.addValue(
6746
6316
  ctx.values,
@@ -6751,7 +6321,7 @@ const pushColumnInfoSql = (ctx, table, query) => {
6751
6321
  ctx.sql.push(
6752
6322
  `AND column_name = ${orchidCore.addValue(
6753
6323
  ctx.values,
6754
- ((_a = table.q.shape[query.column]) == null ? void 0 : _a.data.name) || query.column
6324
+ table.q.shape[query.column]?.data.name || query.column
6755
6325
  )}`
6756
6326
  );
6757
6327
  }
@@ -6760,30 +6330,21 @@ const pushColumnInfoSql = (ctx, table, query) => {
6760
6330
  const pushCopySql = (ctx, table, query, quotedAs) => {
6761
6331
  const { sql } = ctx;
6762
6332
  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(", ")})` : "";
6333
+ const columns = copy.columns ? `(${copy.columns.map((item) => `"${query.shape[item]?.data.name || item}"`).join(", ")})` : "";
6767
6334
  const target = "from" in copy ? copy.from : copy.to;
6768
6335
  sql.push(
6769
6336
  `COPY "${table.table}"${columns} ${"from" in copy ? "FROM" : "TO"} ${typeof target === "string" ? escapeString(target) : `PROGRAM ${escapeString(target.program)}`}`
6770
6337
  );
6771
6338
  if (Object.keys(copy).length > (copy.columns ? 2 : 1)) {
6772
6339
  const options = [];
6773
- if (copy.format)
6774
- options.push(`FORMAT ${copy.format}`);
6775
- if (copy.freeze)
6776
- options.push(`FREEZE ${copy.freeze}`);
6340
+ if (copy.format) options.push(`FORMAT ${copy.format}`);
6341
+ if (copy.freeze) options.push(`FREEZE ${copy.freeze}`);
6777
6342
  if (copy.delimiter)
6778
6343
  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)}`);
6344
+ if (copy.null) options.push(`NULL ${escapeString(copy.null)}`);
6345
+ if (copy.header) options.push(`HEADER ${copy.header}`);
6346
+ if (copy.quote) options.push(`QUOTE ${escapeString(copy.quote)}`);
6347
+ if (copy.escape) options.push(`ESCAPE ${escapeString(copy.escape)}`);
6787
6348
  if (copy.forceQuote)
6788
6349
  options.push(
6789
6350
  `FORCE_QUOTE ${copy.forceQuote === "*" ? "*" : `(${copy.forceQuote.map((x) => `"${x}"`).join(", ")})`}`
@@ -6796,8 +6357,7 @@ const pushCopySql = (ctx, table, query, quotedAs) => {
6796
6357
  options.push(
6797
6358
  `FORCE_NULL (${copy.forceNull.map((x) => `"${x}"`).join(", ")})`
6798
6359
  );
6799
- if (copy.encoding)
6800
- options.push(`ENCODING ${escapeString(copy.encoding)}`);
6360
+ if (copy.encoding) options.push(`ENCODING ${escapeString(copy.encoding)}`);
6801
6361
  sql.push(`WITH (${options.join(", ")})`);
6802
6362
  }
6803
6363
  pushWhereStatementSql(ctx, table, query, quotedAs);
@@ -6805,26 +6365,24 @@ const pushCopySql = (ctx, table, query, quotedAs) => {
6805
6365
 
6806
6366
  const toSQLCacheKey = Symbol("toSQLCache");
6807
6367
  const toSQL = (table, options) => {
6808
- return !(options == null ? void 0 : options.clearCache) && table.q[toSQLCacheKey] || (table.q[toSQLCacheKey] = makeSQL(table, options));
6368
+ return !options?.clearCache && table.q[toSQLCacheKey] || (table.q[toSQLCacheKey] = makeSQL(table, options));
6809
6369
  };
6810
6370
  const makeSQL = (table, options) => {
6811
- var _a;
6812
6371
  const query = table.q;
6813
6372
  const sql = [];
6814
- const values = (options == null ? void 0 : options.values) || [];
6373
+ const values = options?.values || [];
6815
6374
  const ctx = {
6816
6375
  queryBuilder: table.queryBuilder,
6817
6376
  sql,
6818
6377
  values,
6819
- aliasValue: options == null ? void 0 : options.aliasValue
6378
+ aliasValue: options?.aliasValue
6820
6379
  };
6821
6380
  if (query.with) {
6822
6381
  pushWithSql(ctx, query.with);
6823
6382
  }
6824
6383
  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}`);
6384
+ const tableName = table.table ?? query.as;
6385
+ if (!tableName) throw new Error(`Table is missing for ${query.type}`);
6828
6386
  if (query.type === "truncate") {
6829
6387
  pushTruncateSql(ctx, tableName, query);
6830
6388
  return { text: sql.join(" "), values };
@@ -6889,8 +6447,7 @@ const makeSQL = (table, options) => {
6889
6447
  );
6890
6448
  sql.push(`GROUP BY ${group.join(", ")}`);
6891
6449
  }
6892
- if (query.having)
6893
- pushHavingSql(ctx, query, quotedAs);
6450
+ if (query.having) pushHavingSql(ctx, query, quotedAs);
6894
6451
  if (query.window) {
6895
6452
  const window = [];
6896
6453
  query.window.forEach((item) => {
@@ -6919,8 +6476,7 @@ const makeSQL = (table, options) => {
6919
6476
  orchidCore.isExpression(tableNames) ? tableNames.toSQL(ctx, quotedAs) : tableNames.map((x) => `"${x}"`).join(", ")
6920
6477
  );
6921
6478
  }
6922
- if (query.for.mode)
6923
- sql.push(query.for.mode);
6479
+ if (query.for.mode) sql.push(query.for.mode);
6924
6480
  }
6925
6481
  return { text: sql.join(" "), values, hookSelect: query.hookSelect };
6926
6482
  };
@@ -6934,78 +6490,39 @@ function pushLimitSQL(sql, values, q) {
6934
6490
  }
6935
6491
  }
6936
6492
 
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
6493
  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);
6494
+ if (q.with) q.with = q.with.slice(0);
6495
+ if (q.select) q.select = q.select.slice(0);
6496
+ if (q.hookSelect) q.hookSelect = new Map(q.hookSelect);
6497
+ if (q.and) q.and = q.and.slice(0);
6498
+ if (q.or) q.or = q.or.slice(0);
6499
+ if (q.before) q.before = q.before.slice(0);
6500
+ if (q.after) q.after = q.after.slice(0);
6501
+ if (q.joinedShapes) q.joinedShapes = { ...q.joinedShapes };
6502
+ if (q.joinedComputeds) q.joinedComputeds = { ...q.joinedComputeds };
6503
+ if (q.batchParsers) q.batchParsers = [...q.batchParsers];
6504
+ if (q.joinedBatchParsers) q.joinedBatchParsers = { ...q.joinedBatchParsers };
6505
+ if (q.scopes) q.scopes = { ...q.scopes };
6506
+ if (q.parsers) q.parsers = { ...q.parsers };
6980
6507
  if (q.updateData) {
6981
6508
  q.updateData = q.updateData.slice(
6982
6509
  0
6983
6510
  );
6984
6511
  }
6985
6512
  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);
6513
+ if (q.distinct) q.distinct = q.distinct.slice(0);
6514
+ if (q.join) q.join = q.join.slice(0);
6515
+ if (q.group) q.group = q.group.slice(0);
6516
+ if (q.having) q.having = q.having.slice(0);
6517
+ if (q.window) q.window = q.window.slice(0);
6518
+ if (q.union) q.union = { b: q.union.b, u: q.union.u.slice(0) };
6519
+ if (q.order) q.order = q.order.slice(0);
7000
6520
  } else if (q.type === "insert") {
7001
6521
  q.columns = q.columns.slice(0);
7002
6522
  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);
6523
+ if (q.using) q.using = q.using.slice(0);
6524
+ if (q.join) q.join = q.join.slice(0);
6525
+ if (q.beforeCreate) q.beforeCreate = q.beforeCreate.slice(0);
7009
6526
  if (q.afterCreate) {
7010
6527
  q.afterCreate = q.afterCreate.slice(0);
7011
6528
  if (q.afterCreateSelect) {
@@ -7013,8 +6530,7 @@ const cloneQuery = (q) => {
7013
6530
  }
7014
6531
  }
7015
6532
  } else if (q.type === "update") {
7016
- if (q.beforeUpdate)
7017
- q.beforeUpdate = q.beforeUpdate.slice(0);
6533
+ if (q.beforeUpdate) q.beforeUpdate = q.beforeUpdate.slice(0);
7018
6534
  if (q.afterUpdate) {
7019
6535
  q.afterUpdate = q.afterUpdate.slice(0);
7020
6536
  if (q.afterUpdateSelect) {
@@ -7022,8 +6538,7 @@ const cloneQuery = (q) => {
7022
6538
  }
7023
6539
  }
7024
6540
  } else if (q.type === "delete") {
7025
- if (q.beforeDelete)
7026
- q.beforeDelete = q.beforeDelete.slice(0);
6541
+ if (q.beforeDelete) q.beforeDelete = q.beforeDelete.slice(0);
7027
6542
  if (q.afterDelete) {
7028
6543
  q.afterDelete = q.afterDelete.slice(0);
7029
6544
  if (q.afterDeleteSelect) {
@@ -7033,27 +6548,7 @@ const cloneQuery = (q) => {
7033
6548
  }
7034
6549
  };
7035
6550
 
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
6551
  const _chain = (fromQuery, toQuery, rel) => {
7056
- var _a, _b;
7057
6552
  const self = fromQuery;
7058
6553
  const toTable = toQuery;
7059
6554
  let query;
@@ -7073,38 +6568,23 @@ const _chain = (fromQuery, toQuery, rel) => {
7073
6568
  } else {
7074
6569
  query.q.relChain = [self];
7075
6570
  }
7076
- const aliases = self.q.as ? __spreadValues$a({}, self.q.aliases) : __spreadProps$3(__spreadValues$a({}, self.q.aliases), { [self.table]: self.table });
6571
+ const aliases = self.q.as ? { ...self.q.aliases } : { ...self.q.aliases, [self.table]: self.table };
7077
6572
  const relAliases = query.q.aliases;
7078
6573
  for (const as in relAliases) {
7079
6574
  aliases[as] = _queryResolveAlias(aliases, as);
7080
6575
  }
7081
6576
  query.q.as = aliases[query.q.as];
7082
6577
  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);
6578
+ query.q.joinedShapes = {
6579
+ [getQueryAs(self)]: self.q.shape,
6580
+ ...self.q.joinedShapes
6581
+ };
6582
+ rel.modifyRelatedQuery?.(query)?.(self);
7087
6583
  return query;
7088
6584
  };
7089
6585
 
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
6586
  const getClonedQueryData = (query) => {
7107
- const cloned = __spreadValues$9({}, query);
6587
+ const cloned = { ...query };
7108
6588
  delete cloned[toSQLCacheKey];
7109
6589
  cloneQuery(cloned);
7110
6590
  return cloned;
@@ -7148,8 +6628,7 @@ const resolveSubQueryCallback = (q, cb) => {
7148
6628
  return result;
7149
6629
  };
7150
6630
  const joinSubQuery = (q, sub) => {
7151
- if (!("relationConfig" in sub))
7152
- return sub;
6631
+ if (!("relationConfig" in sub)) return sub;
7153
6632
  return sub.relationConfig.joinQuery(
7154
6633
  sub,
7155
6634
  q
@@ -7266,10 +6745,8 @@ const typmodType = (typmod) => {
7266
6745
  } else {
7267
6746
  s += lwtypeName(type);
7268
6747
  }
7269
- if (typmod >= 0 && typmodGetZ(typmod))
7270
- s += "Z";
7271
- if (typmod >= 0 && typmodGetM(typmod))
7272
- s += "M";
6748
+ if (typmod >= 0 && typmodGetZ(typmod)) s += "Z";
6749
+ if (typmod >= 0 && typmodGetM(typmod)) s += "M";
7273
6750
  return s;
7274
6751
  };
7275
6752
  const typmodSrid = (typmod) => {
@@ -7289,36 +6766,17 @@ function uint8ArrToHex(arr) {
7289
6766
  }
7290
6767
  }
7291
6768
  const hexOctets = [];
7292
- for (let i = 0; i < arr.length; ++i)
7293
- hexOctets.push(byteToHex[arr[i]]);
6769
+ for (let i = 0; i < arr.length; ++i) hexOctets.push(byteToHex[arr[i]]);
7294
6770
  return hexOctets.join("");
7295
6771
  }
7296
6772
 
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
6773
  const getColumnTypes = (types, fn, nowSQL, language) => {
7314
- if (nowSQL)
7315
- orchidCore.setDefaultNowFn(nowSQL);
7316
- if (language)
7317
- orchidCore.setDefaultLanguage(language);
6774
+ if (nowSQL) orchidCore.setDefaultNowFn(nowSQL);
6775
+ if (language) orchidCore.setDefaultLanguage(language);
7318
6776
  return fn(types);
7319
6777
  };
7320
6778
  const makeColumnTypes = (schema) => {
7321
- return __spreadValues$8({
6779
+ return {
7322
6780
  schema,
7323
6781
  enum: schema.enum,
7324
6782
  array: schema.array,
@@ -7427,8 +6885,9 @@ const makeColumnTypes = (schema) => {
7427
6885
  point() {
7428
6886
  return new PostgisGeographyPointColumn(schema);
7429
6887
  }
7430
- }
7431
- }, orchidCore.makeTimestampsHelpers(makeRegexToFindInSql));
6888
+ },
6889
+ ...orchidCore.makeTimestampsHelpers(makeRegexToFindInSql)
6890
+ };
7432
6891
  };
7433
6892
  RawSQL.prototype.columnTypes = makeColumnTypes;
7434
6893
 
@@ -7443,13 +6902,13 @@ class VirtualColumn extends ColumnType {
7443
6902
  }
7444
6903
  }
7445
6904
 
7446
- const _UnknownColumn = class extends VirtualColumn {
6905
+ const _UnknownColumn = class _UnknownColumn extends VirtualColumn {
7447
6906
  constructor(schema) {
7448
6907
  super(schema, schema.unknown());
7449
6908
  }
7450
6909
  };
6910
+ _UnknownColumn.instance = new _UnknownColumn(defaultSchemaConfig);
7451
6911
  let UnknownColumn = _UnknownColumn;
7452
- UnknownColumn.instance = new _UnknownColumn(defaultSchemaConfig);
7453
6912
  RawSQL.prototype.result = { value: UnknownColumn.instance };
7454
6913
 
7455
6914
  const makeColumnsByType = (schema) => {
@@ -7513,21 +6972,6 @@ const makeColumnsByType = (schema) => {
7513
6972
  };
7514
6973
  };
7515
6974
 
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
6975
  const { types } = pg;
7532
6976
  const defaultTypeParsers = {};
7533
6977
  for (const key in types.builtins) {
@@ -7547,8 +6991,7 @@ const returnArg = (arg) => arg;
7547
6991
  const rollbackSql = { text: "ROLLBACK" };
7548
6992
  const commitSql = { text: "COMMIT" };
7549
6993
  class Adapter {
7550
- constructor(_a) {
7551
- var _b = _a, { types: types2 = defaultTypeParsers } = _b, config = __objRest$1(_b, ["types"]);
6994
+ constructor({ types: types2 = defaultTypeParsers, ...config }) {
7552
6995
  this.types = types2;
7553
6996
  let schema = config.schema;
7554
6997
  if (config.databaseURL) {
@@ -7565,8 +7008,7 @@ class Adapter {
7565
7008
  config.databaseURL = url.toString();
7566
7009
  config.connectionString = config.databaseURL;
7567
7010
  }
7568
- if (schema)
7569
- this.schema = schema === "public" ? void 0 : schema;
7011
+ if (schema) this.schema = schema === "public" ? void 0 : schema;
7570
7012
  this.config = config;
7571
7013
  this.pool = new pg.Pool(config);
7572
7014
  if (config.connectRetry) {
@@ -7673,25 +7115,6 @@ class TransactionAdapter {
7673
7115
  }
7674
7116
  }
7675
7117
 
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
7118
  class FnExpression extends orchidCore.Expression {
7696
7119
  /**
7697
7120
  * @param query - query object.
@@ -7717,12 +7140,10 @@ class FnExpression extends orchidCore.Expression {
7717
7140
  }
7718
7141
  // Builds function SQL.
7719
7142
  makeSQL(ctx, quotedAs) {
7720
- var _a;
7721
7143
  const sql = [`${this.fn}(`];
7722
7144
  const { values } = ctx;
7723
7145
  const { options } = this;
7724
- if (options.distinct && !options.withinGroup)
7725
- sql.push("DISTINCT ");
7146
+ if (options.distinct && !options.withinGroup) sql.push("DISTINCT ");
7726
7147
  sql.push(
7727
7148
  this.args.map((arg) => {
7728
7149
  if (typeof arg === "string") {
@@ -7749,13 +7170,11 @@ class FnExpression extends orchidCore.Expression {
7749
7170
  }
7750
7171
  }).join(", ")
7751
7172
  );
7752
- if (options.withinGroup)
7753
- sql.push(") WITHIN GROUP (");
7754
- else if (options.order)
7755
- sql.push(" ");
7173
+ if (options.withinGroup) sql.push(") WITHIN GROUP (");
7174
+ else if (options.order) sql.push(" ");
7756
7175
  if (options.order) {
7757
7176
  pushOrderBySql(
7758
- __spreadProps$2(__spreadValues$7({}, ctx), { sql }),
7177
+ { ...ctx, sql },
7759
7178
  this.q,
7760
7179
  quotedAs,
7761
7180
  orchidCore.toArray(options.order)
@@ -7768,7 +7187,7 @@ class FnExpression extends orchidCore.Expression {
7768
7187
  this.query,
7769
7188
  {
7770
7189
  and: options.filter ? [options.filter] : void 0,
7771
- or: (_a = options.filterOr) == null ? void 0 : _a.map((item) => [item]),
7190
+ or: options.filterOr?.map((item) => [item]),
7772
7191
  shape: this.q.shape,
7773
7192
  joinedShapes: this.q.joinedShapes
7774
7193
  },
@@ -8401,22 +7820,6 @@ class Clear {
8401
7820
  }
8402
7821
  }
8403
7822
 
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
7823
  const createSelect = (q) => {
8421
7824
  if (q.q.returnType === "void" || isSelectingCount(q)) {
8422
7825
  q.q.select = void 0;
@@ -8426,12 +7829,10 @@ const createSelect = (q) => {
8426
7829
  }
8427
7830
  };
8428
7831
  const processCreateItem = (q, item, rowIndex, ctx, encoders) => {
8429
- var _a, _b, _c;
8430
7832
  const { shape } = q.q;
8431
7833
  for (const key in item) {
8432
7834
  if (shape[key] instanceof VirtualColumn) {
8433
- (_b = (_a = shape[key]).create) == null ? void 0 : _b.call(
8434
- _a,
7835
+ shape[key].create?.(
8435
7836
  q,
8436
7837
  ctx,
8437
7838
  item,
@@ -8446,7 +7847,7 @@ const processCreateItem = (q, item, rowIndex, ctx, encoders) => {
8446
7847
  }
8447
7848
  if (!ctx.columns.has(key) && (shape[key] && !shape[key].data.computed || shape === anyShape) && item[key] !== void 0) {
8448
7849
  ctx.columns.set(key, ctx.columns.size);
8449
- encoders[key] = (_c = shape[key]) == null ? void 0 : _c.data.encode;
7850
+ encoders[key] = shape[key]?.data.encode;
8450
7851
  }
8451
7852
  }
8452
7853
  }
@@ -8459,7 +7860,7 @@ const handleOneData = (q, data, ctx) => {
8459
7860
  const encoders = {};
8460
7861
  const defaults = q.q.defaults;
8461
7862
  if (defaults) {
8462
- data = __spreadValues$6(__spreadValues$6({}, defaults), data);
7863
+ data = { ...defaults, ...data };
8463
7864
  }
8464
7865
  processCreateItem(q, data, 0, ctx, encoders);
8465
7866
  const columns = Array.from(ctx.columns.keys());
@@ -8477,7 +7878,7 @@ const handleManyData = (q, data, ctx) => {
8477
7878
  const encoders = {};
8478
7879
  const defaults = q.q.defaults;
8479
7880
  if (defaults) {
8480
- data = data.map((item) => __spreadValues$6(__spreadValues$6({}, defaults), item));
7881
+ data = data.map((item) => ({ ...defaults, ...item }));
8481
7882
  }
8482
7883
  data.forEach((item, i) => {
8483
7884
  processCreateItem(q, item, i, ctx, encoders);
@@ -8495,9 +7896,8 @@ const insert = (self, {
8495
7896
  columns,
8496
7897
  values
8497
7898
  }, kind, many) => {
8498
- var _a;
8499
7899
  const { q } = self;
8500
- if (!((_a = q.select) == null ? void 0 : _a.length)) {
7900
+ if (!q.select?.length) {
8501
7901
  q.returning = true;
8502
7902
  }
8503
7903
  delete q.and;
@@ -8506,14 +7906,12 @@ const insert = (self, {
8506
7906
  q.type = "insert";
8507
7907
  q.columns = columns;
8508
7908
  q.values = values;
8509
- if (!q.kind)
8510
- q.kind = kind;
7909
+ if (!q.kind) q.kind = kind;
8511
7910
  const { select, returnType } = q;
8512
7911
  if (!select) {
8513
7912
  if (returnType !== "void") {
8514
7913
  q.returnType = "valueOrThrow";
8515
- if (many)
8516
- q.returningMany = true;
7914
+ if (many) q.returningMany = true;
8517
7915
  }
8518
7916
  } else if (many) {
8519
7917
  if (returnType === "one" || returnType === "oneOrThrow") {
@@ -8529,14 +7927,13 @@ const insert = (self, {
8529
7927
  return self;
8530
7928
  };
8531
7929
  const getFromSelectColumns = (from, obj, many) => {
8532
- var _a;
8533
7930
  if (!many && !queryTypeWithLimitOne[from.q.returnType]) {
8534
7931
  throw new Error(
8535
7932
  "Cannot create based on a query which returns multiple records"
8536
7933
  );
8537
7934
  }
8538
7935
  const queryColumns = [];
8539
- (_a = from.q.select) == null ? void 0 : _a.forEach((item) => {
7936
+ from.q.select?.forEach((item) => {
8540
7937
  if (typeof item === "string") {
8541
7938
  const index = item.indexOf(".");
8542
7939
  queryColumns.push(index === -1 ? item : item.slice(index + 1));
@@ -8544,7 +7941,7 @@ const getFromSelectColumns = (from, obj, many) => {
8544
7941
  queryColumns.push(...Object.keys(item.selectAs));
8545
7942
  }
8546
7943
  });
8547
- if (obj == null ? void 0 : obj.columns) {
7944
+ if (obj?.columns) {
8548
7945
  queryColumns.push(...obj.columns);
8549
7946
  }
8550
7947
  return queryColumns;
@@ -8557,7 +7954,7 @@ const insertFromQuery = (q, from, many, data) => {
8557
7954
  q,
8558
7955
  {
8559
7956
  columns,
8560
- values: { from, values: obj == null ? void 0 : obj.values }
7957
+ values: { from, values: obj?.values }
8561
7958
  },
8562
7959
  "from",
8563
7960
  many
@@ -8585,8 +7982,7 @@ const _queryCreateMany = (q, data) => {
8585
7982
  const _queryInsertMany = (q, data) => {
8586
7983
  const ctx = createCtx();
8587
7984
  let result = insert(q, handleManyData(q, data, ctx), "object", true);
8588
- if (!data.length)
8589
- result = result.none();
7985
+ if (!data.length) result = result.none();
8590
7986
  return result;
8591
7987
  };
8592
7988
  const _queryCreateRaw = (q, args) => {
@@ -9224,15 +8620,13 @@ const forMethods = {
9224
8620
  noWait() {
9225
8621
  const q = _clone(this);
9226
8622
  const data = q.q;
9227
- if (data == null ? void 0 : data.for)
9228
- data.for.mode = "NO WAIT";
8623
+ if (data?.for) data.for.mode = "NO WAIT";
9229
8624
  return q;
9230
8625
  },
9231
8626
  skipLocked() {
9232
8627
  const q = _clone(this);
9233
8628
  const data = q.q;
9234
- if (data == null ? void 0 : data.for)
9235
- data.for.mode = "SKIP LOCKED";
8629
+ if (data?.for) data.for.mode = "SKIP LOCKED";
9236
8630
  return q;
9237
8631
  }
9238
8632
  };
@@ -9374,9 +8768,9 @@ class Having {
9374
8768
 
9375
8769
  const before = (q, key, cb) => pushQueryValue(q, `before${key}`, cb);
9376
8770
  const after = (q, key, select, cb, commit) => {
9377
- var _a, _b, _c;
8771
+ var _a, _b;
9378
8772
  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();
8773
+ const set = (_a = q.q)[_b = `after${key}Select`] ?? (_a[_b] = /* @__PURE__ */ new Set());
9380
8774
  for (const column of select) {
9381
8775
  set.add(column);
9382
8776
  }
@@ -10356,22 +9750,6 @@ class JsonMethods {
10356
9750
  }
10357
9751
  }
10358
9752
 
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
9753
  const mergableObjects = /* @__PURE__ */ new Set([
10376
9754
  "shape",
10377
9755
  "withShapes",
@@ -10402,7 +9780,7 @@ class MergeQueryMethods {
10402
9780
  a[key] = a[key] ? [...a[key], ...value] : value;
10403
9781
  }
10404
9782
  } else if (mergableObjects.has(key)) {
10405
- a[key] = a[key] ? __spreadValues$5(__spreadValues$5({}, a[key]), value) : value;
9783
+ a[key] = a[key] ? { ...a[key], ...value } : value;
10406
9784
  } else if (key === "union") {
10407
9785
  a[key] = a[key] ? {
10408
9786
  b: a[key].b,
@@ -10416,8 +9794,7 @@ class MergeQueryMethods {
10416
9794
  break;
10417
9795
  }
10418
9796
  }
10419
- if (b.returnType)
10420
- a.returnType = b.returnType;
9797
+ if (b.returnType) a.returnType = b.returnType;
10421
9798
  return query;
10422
9799
  }
10423
9800
  }
@@ -10567,25 +9944,6 @@ class Union {
10567
9944
  }
10568
9945
  }
10569
9946
 
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
9947
  class WithMethods {
10590
9948
  with(name, second, third) {
10591
9949
  const q = _clone(this);
@@ -10598,10 +9956,11 @@ class WithMethods {
10598
9956
  } else {
10599
9957
  query = queryArg;
10600
9958
  }
10601
- if ((options == null ? void 0 : options.columns) === true) {
10602
- options = __spreadProps$1(__spreadValues$4({}, options), {
9959
+ if (options?.columns === true) {
9960
+ options = {
9961
+ ...options,
10603
9962
  columns: Object.keys(query.shape)
10604
- });
9963
+ };
10605
9964
  }
10606
9965
  pushQueryValue(q, "with", { n: name, o: options, q: query });
10607
9966
  const shape = getShapeFromSelect(query, true);
@@ -10611,7 +9970,7 @@ class WithMethods {
10611
9970
  });
10612
9971
  }
10613
9972
  withRecursive(name, ...args) {
10614
- var _a, _b, _c;
9973
+ var _a;
10615
9974
  const q = _clone(this);
10616
9975
  let [options, baseFn, recursiveFn] = args.length === 2 ? [{}, args[0], args[1]] : args;
10617
9976
  const arg = q.queryBuilder.clone();
@@ -10619,14 +9978,15 @@ class WithMethods {
10619
9978
  let query = typeof baseFn === "function" ? baseFn(arg) : baseFn;
10620
9979
  const shape = getShapeFromSelect(query, true);
10621
9980
  const withConfig = { shape, computeds: query.q.computeds };
10622
- ((_b = (_a = arg.q).withShapes) != null ? _b : _a.withShapes = {})[name] = withConfig;
9981
+ ((_a = arg.q).withShapes ?? (_a.withShapes = {}))[name] = withConfig;
10623
9982
  const recursive = recursiveFn(arg);
10624
- query = _queryUnion(query, [recursive], (_c = options.union) != null ? _c : "UNION ALL");
9983
+ query = _queryUnion(query, [recursive], options.union ?? "UNION ALL");
10625
9984
  options.recursive = true;
10626
9985
  if (options.columns === true) {
10627
- options = __spreadProps$1(__spreadValues$4({}, options), {
9986
+ options = {
9987
+ ...options,
10628
9988
  columns: Object.keys(shape)
10629
- });
9989
+ };
10630
9990
  }
10631
9991
  pushQueryValue(q, "with", { n: name, o: options, q: query });
10632
9992
  return setQueryObjectValue(q, "withShapes", name, withConfig);
@@ -10646,22 +10006,6 @@ class WithMethods {
10646
10006
  }
10647
10007
  }
10648
10008
 
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
10009
  const _queryChangeCounter = (self, op, data) => {
10666
10010
  const q = self.q;
10667
10011
  q.type = "update";
@@ -10698,7 +10042,7 @@ const update = (self) => {
10698
10042
  };
10699
10043
  const _queryUpdate = (query, arg) => {
10700
10044
  const { q } = query;
10701
- const set = __spreadValues$3({}, arg);
10045
+ const set = { ...arg };
10702
10046
  pushQueryValue(query, "updateData", set);
10703
10047
  const { shape } = q;
10704
10048
  const ctx = {};
@@ -10740,8 +10084,7 @@ const _queryUpdate = (query, arg) => {
10740
10084
  }
10741
10085
  } else {
10742
10086
  const encode = shape[key].data.encode;
10743
- if (encode)
10744
- set[key] = encode(value);
10087
+ if (encode) set[key] = encode(value);
10745
10088
  }
10746
10089
  }
10747
10090
  }
@@ -11100,25 +10443,6 @@ class Update {
11100
10443
  }
11101
10444
  }
11102
10445
 
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
10446
  class Headline extends orchidCore.Expression {
11123
10447
  constructor(q, source, params) {
11124
10448
  super();
@@ -11131,16 +10455,15 @@ class Headline extends orchidCore.Expression {
11131
10455
  makeSQL(ctx, quotedAs) {
11132
10456
  const { q, source, params } = this;
11133
10457
  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)}` : "";
10458
+ 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);
10459
+ const options = params?.options ? `, ${params.options instanceof orchidCore.Expression ? params.options.toSQL(ctx, quotedAs) : orchidCore.addValue(ctx.values, params.options)}` : "";
11136
10460
  return `ts_headline(${lang}, ${text}, "${source.as}"${options})`;
11137
10461
  }
11138
10462
  }
11139
10463
  Object.assign(Headline, Operators.text);
11140
10464
  AggregateMethods.prototype.headline = function(search, params) {
11141
- var _a;
11142
10465
  const q = this;
11143
- const source = (_a = q.q.sources) == null ? void 0 : _a[search];
10466
+ const source = q.q.sources?.[search];
11144
10467
  if (!source)
11145
10468
  throw new OrchidOrmInternalError(q, `Search \`${search}\` is not defined`);
11146
10469
  return new Headline(
@@ -11342,9 +10665,10 @@ class SearchMethods {
11342
10665
  const q = _clone(this);
11343
10666
  if (!arg.as) {
11344
10667
  const as = saveSearchAlias(q, "@q", "joinedShapes");
11345
- arg = __spreadProps(__spreadValues$2({}, arg), {
10668
+ arg = {
10669
+ ...arg,
11346
10670
  as
11347
- });
10671
+ };
11348
10672
  }
11349
10673
  setQueryObjectValue(q, "sources", arg.as, arg);
11350
10674
  if (arg.order) {
@@ -11354,22 +10678,6 @@ class SearchMethods {
11354
10678
  }
11355
10679
  }
11356
10680
 
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
10681
  function orCreate(query, data, updateData, mergeData) {
11374
10682
  const { q } = query;
11375
10683
  q.returnType = "one";
@@ -11385,12 +10693,11 @@ function orCreate(query, data, updateData, mergeData) {
11385
10693
  if (typeof data === "function") {
11386
10694
  data = data(updateData);
11387
10695
  }
11388
- if (mergeData)
11389
- data = __spreadValues$1(__spreadValues$1({}, mergeData), data);
10696
+ if (mergeData) data = { ...mergeData, ...data };
11390
10697
  const inner = q2.create(data);
11391
10698
  inner.q.handleResult = (q3, t, r, s) => {
11392
10699
  result = handleResult(q3, t, r, s);
11393
- return inner.q.hookSelect ? result.map((row) => __spreadValues$1({}, row)) : result;
10700
+ return inner.q.hookSelect ? result.map((row) => ({ ...row })) : result;
11394
10701
  };
11395
10702
  await inner;
11396
10703
  created = true;
@@ -11680,12 +10987,10 @@ class ScopeMethods {
11680
10987
  * @param scope - name of the scope to apply
11681
10988
  */
11682
10989
  scope(scope) {
11683
- var _a;
11684
10990
  const q = _clone(this);
11685
- if (!((_a = q.q.scopes) == null ? void 0 : _a[scope])) {
10991
+ if (!q.q.scopes?.[scope]) {
11686
10992
  const s = q.internal.scopes[scope];
11687
- if (!s)
11688
- throw new Error(`Scope ${scope} is not defined`);
10993
+ if (!s) throw new Error(`Scope ${scope} is not defined`);
11689
10994
  setQueryObjectValue(q, "scopes", scope, s);
11690
10995
  }
11691
10996
  return q;
@@ -11716,7 +11021,7 @@ class ScopeMethods {
11716
11021
  }
11717
11022
 
11718
11023
  function enableSoftDelete(q, table, shape, softDelete, scopes) {
11719
- var _a, _b;
11024
+ var _a;
11720
11025
  const column = softDelete === true ? "deletedAt" : softDelete;
11721
11026
  if (!shape[column]) {
11722
11027
  throw new Error(
@@ -11727,7 +11032,7 @@ function enableSoftDelete(q, table, shape, softDelete, scopes) {
11727
11032
  and: [{ [column]: null }]
11728
11033
  };
11729
11034
  scopes.deleted = scope;
11730
- ((_b = (_a = q.q).scopes) != null ? _b : _a.scopes = {}).nonDeleted = scope;
11035
+ ((_a = q.q).scopes ?? (_a.scopes = {})).nonDeleted = scope;
11731
11036
  const _del = _softDelete(
11732
11037
  column,
11733
11038
  q.internal.nowSQL
@@ -11810,8 +11115,7 @@ class OrExpression extends orchidCore.Expression {
11810
11115
  if (arg) {
11811
11116
  if (orchidCore.isExpression(arg)) {
11812
11117
  const sql = arg.toSQL(ctx, quotedAs);
11813
- if (sql)
11814
- res.push(sql);
11118
+ if (sql) res.push(sql);
11815
11119
  } else {
11816
11120
  res.push(`(${getSqlText(arg.toSQL(ctx))})`);
11817
11121
  }
@@ -12391,10 +11695,10 @@ class QueryMethods {
12391
11695
  const query = _clone(this);
12392
11696
  const q = query.q;
12393
11697
  q.type = "truncate";
12394
- if (options == null ? void 0 : options.restartIdentity) {
11698
+ if (options?.restartIdentity) {
12395
11699
  q.restartIdentity = true;
12396
11700
  }
12397
- if (options == null ? void 0 : options.cascade) {
11701
+ if (options?.cascade) {
12398
11702
  q.cascade = true;
12399
11703
  }
12400
11704
  return _queryExec(query);
@@ -12644,12 +11948,12 @@ orchidCore.applyMixins(QueryMethods, [
12644
11948
 
12645
11949
  const makeIndex = (columns, first, second) => {
12646
11950
  if (typeof first === "string") {
12647
- const options = second != null ? second : {};
11951
+ const options = second ?? {};
12648
11952
  return {
12649
11953
  index: { columns, options, name: first }
12650
11954
  };
12651
11955
  } else {
12652
- const options = first != null ? first : {};
11956
+ const options = first ?? {};
12653
11957
  return {
12654
11958
  index: { columns, options }
12655
11959
  };
@@ -12666,16 +11970,16 @@ const tableDataMethods = {
12666
11970
  },
12667
11971
  index: makeIndex,
12668
11972
  searchIndex(columns, ...[first, second]) {
12669
- var _a, _b;
11973
+ var _a;
12670
11974
  const input = makeIndex(columns, first, second);
12671
- (_b = (_a = input.index.options).using) != null ? _b : _a.using = "gin";
11975
+ (_a = input.index.options).using ?? (_a.using = "gin");
12672
11976
  input.index.options.tsVector = true;
12673
11977
  return input;
12674
11978
  },
12675
11979
  foreignKey(columns, fnOrTable, foreignColumns, options) {
12676
11980
  return {
12677
11981
  constraint: {
12678
- name: options == null ? void 0 : options.name,
11982
+ name: options?.name,
12679
11983
  references: { columns, fnOrTable, foreignColumns, options }
12680
11984
  }
12681
11985
  };
@@ -12700,7 +12004,6 @@ const parseTableData = (dataFn) => {
12700
12004
  return tableData;
12701
12005
  };
12702
12006
  const parseTableDataInput = (tableData, item) => {
12703
- var _a, _b, _c, _d;
12704
12007
  if (item.primaryKey) {
12705
12008
  tableData.primaryKey = item.primaryKey;
12706
12009
  } else if (item.index) {
@@ -12712,47 +12015,18 @@ const parseTableDataInput = (tableData, item) => {
12712
12015
  };
12713
12016
  }
12714
12017
  }
12715
- ((_a = tableData.indexes) != null ? _a : tableData.indexes = []).push(item.index);
12018
+ (tableData.indexes ?? (tableData.indexes = [])).push(item.index);
12716
12019
  } 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) {
12020
+ (tableData.constraints ?? (tableData.constraints = [])).push(item.constraint);
12021
+ if (item.constraint.references?.options?.dropMode) {
12719
12022
  item.constraint.dropMode = item.constraint.references.options.dropMode;
12720
12023
  }
12721
12024
  }
12722
12025
  };
12723
12026
 
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
12027
  const anyShape = {};
12753
12028
  class Db extends QueryMethods {
12754
12029
  constructor(adapter, queryBuilder, table = void 0, shape = anyShape, columnTypes, transactionStorage, options, tableData = orchidCore.emptyObject) {
12755
- var _a;
12756
12030
  super();
12757
12031
  this.adapter = adapter;
12758
12032
  this.queryBuilder = queryBuilder;
@@ -12804,10 +12078,8 @@ class Db extends QueryMethods {
12804
12078
  }
12805
12079
  if (typeof column.data.default === "function") {
12806
12080
  const arr = this.internal.runtimeDefaultColumns;
12807
- if (!arr)
12808
- this.internal.runtimeDefaultColumns = [key];
12809
- else
12810
- arr.push(key);
12081
+ if (!arr) this.internal.runtimeDefaultColumns = [key];
12082
+ else arr.push(key);
12811
12083
  if (!column.data.runtimeDefault) {
12812
12084
  const {
12813
12085
  data: { default: def, encode }
@@ -12822,10 +12094,10 @@ class Db extends QueryMethods {
12822
12094
  handleResult,
12823
12095
  logger,
12824
12096
  log: logParamToLogObject(logger, options.log),
12825
- autoPreparedStatements: (_a = options.autoPreparedStatements) != null ? _a : false,
12097
+ autoPreparedStatements: options.autoPreparedStatements ?? false,
12826
12098
  parsers: hasParsers ? parsers : void 0,
12827
12099
  language: options.language,
12828
- schema: options == null ? void 0 : options.schema
12100
+ schema: options?.schema
12829
12101
  };
12830
12102
  let shapeHasPrimaryKey;
12831
12103
  for (const key in shape) {
@@ -12840,17 +12112,14 @@ class Db extends QueryMethods {
12840
12112
  }
12841
12113
  if (!shapeHasPrimaryKey && !tableData.primaryKey && shape !== anyShape && options.noPrimaryKey !== "ignore") {
12842
12114
  const message = `Table ${table} has no primary key`;
12843
- if (options.noPrimaryKey === "error")
12844
- throw new Error(message);
12845
- else
12846
- logger.warn(message);
12115
+ if (options.noPrimaryKey === "error") throw new Error(message);
12116
+ else logger.warn(message);
12847
12117
  }
12848
12118
  const columns = Object.keys(
12849
12119
  shape
12850
12120
  );
12851
12121
  this.columns = columns;
12852
- if (options.computed)
12853
- applyComputedColumns(this, options.computed);
12122
+ if (options.computed) applyComputedColumns(this, options.computed);
12854
12123
  if (prepareSelectAll) {
12855
12124
  const list = [];
12856
12125
  const keys = {};
@@ -12962,21 +12231,19 @@ class Db extends QueryMethods {
12962
12231
  * use this method to exchange a db column name to its runtime key.
12963
12232
  */
12964
12233
  columnNameToKey(name) {
12965
- var _a;
12966
12234
  let map = this.internal.columnNameToKeyMap;
12967
12235
  if (!map) {
12968
12236
  this.internal.columnNameToKeyMap = map = /* @__PURE__ */ new Map();
12969
12237
  const { shape } = this;
12970
12238
  for (const key in this.shape) {
12971
12239
  const column = shape[key];
12972
- map.set((_a = column.data.name) != null ? _a : key, key);
12240
+ map.set(column.data.name ?? key, key);
12973
12241
  }
12974
12242
  }
12975
12243
  return map.get(name);
12976
12244
  }
12977
12245
  }
12978
12246
  const performQuery = async (q, args, method) => {
12979
- var _a;
12980
12247
  const trx = q.internal.transactionStorage.getStore();
12981
12248
  let sql;
12982
12249
  if (orchidCore.isRawSQL(args[0])) {
@@ -12996,16 +12263,14 @@ const performQuery = async (q, args, method) => {
12996
12263
  values
12997
12264
  };
12998
12265
  }
12999
- const log = (_a = trx == null ? void 0 : trx.log) != null ? _a : q.q.log;
12266
+ const log = trx?.log ?? q.q.log;
13000
12267
  let logData;
13001
- if (log)
13002
- logData = log.beforeQuery(sql);
12268
+ if (log) logData = log.beforeQuery(sql);
13003
12269
  try {
13004
- const result = await ((trx == null ? void 0 : trx.adapter) || q.adapter)[method](
12270
+ const result = await (trx?.adapter || q.adapter)[method](
13005
12271
  sql
13006
12272
  );
13007
- if (log)
13008
- log.afterQuery(sql, logData);
12273
+ if (log) log.afterQuery(sql, logData);
13009
12274
  return result;
13010
12275
  } catch (err) {
13011
12276
  if (log) {
@@ -13016,27 +12281,20 @@ const performQuery = async (q, args, method) => {
13016
12281
  };
13017
12282
  orchidCore.applyMixins(Db, [QueryMethods]);
13018
12283
  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;
12284
+ const createDb = ({
12285
+ log,
12286
+ logger,
12287
+ snakeCase,
12288
+ schemaConfig = defaultSchemaConfig,
12289
+ columnTypes: ctOrFn = makeColumnTypes(schemaConfig),
12290
+ ...options
12291
+ }) => {
13034
12292
  const adapter = "adapter" in options ? options.adapter : new Adapter(options);
13035
12293
  const commonOptions = {
13036
12294
  log,
13037
12295
  logger,
13038
- autoPreparedStatements: (_a2 = options.autoPreparedStatements) != null ? _a2 : false,
13039
- noPrimaryKey: (_b2 = options.noPrimaryKey) != null ? _b2 : "error",
12296
+ autoPreparedStatements: options.autoPreparedStatements ?? false,
12297
+ noPrimaryKey: options.noPrimaryKey ?? "error",
13040
12298
  nowSQL: options.nowSQL,
13041
12299
  snakeCase
13042
12300
  };
@@ -13058,10 +12316,10 @@ const createDb = (_a) => {
13058
12316
  adapter,
13059
12317
  qb,
13060
12318
  table,
13061
- typeof shape === "function" ? getColumnTypes(ct, shape, nowSQL, options2 == null ? void 0 : options2.language) : shape,
12319
+ typeof shape === "function" ? getColumnTypes(ct, shape, nowSQL, options2?.language) : shape,
13062
12320
  ct,
13063
12321
  transactionStorage,
13064
- __spreadValues(__spreadValues({}, commonOptions), options2),
12322
+ { ...commonOptions, ...options2 },
13065
12323
  parseTableData(dataFn)
13066
12324
  );
13067
12325
  };
@@ -13119,7 +12377,7 @@ const testTransaction = {
13119
12377
  * @param arg - ORM instance or a queryable instance (such as db.someTable).
13120
12378
  */
13121
12379
  start(arg) {
13122
- var _a, _b;
12380
+ var _a;
13123
12381
  const db = argToDb(arg);
13124
12382
  const { transactionStorage } = db.internal;
13125
12383
  const { getStore } = transactionStorage;
@@ -13131,7 +12389,7 @@ const testTransaction = {
13131
12389
  transaction: adapter.transaction
13132
12390
  }
13133
12391
  };
13134
- ((_b = (_a = db.internal)[trxForTest]) != null ? _b : _a[trxForTest] = []).push(data);
12392
+ ((_a = db.internal)[trxForTest] ?? (_a[trxForTest] = [])).push(data);
13135
12393
  return new Promise((resolve) => {
13136
12394
  data.promise = db.transaction(() => {
13137
12395
  resolve();
@@ -13153,7 +12411,7 @@ const testTransaction = {
13153
12411
  }
13154
12412
  }).finally(() => {
13155
12413
  const trx = db.internal.transactionStorage.getStore();
13156
- if (trx == null ? void 0 : trx.testTransactionCount) {
12414
+ if (trx?.testTransactionCount) {
13157
12415
  trx.testTransactionCount--;
13158
12416
  }
13159
12417
  db.internal.transactionStorage.getStore = getStore;
@@ -13166,16 +12424,14 @@ const testTransaction = {
13166
12424
  * @param arg - the same ORM or query argument passed into the `testTransaction.start`.
13167
12425
  */
13168
12426
  rollback(arg) {
13169
- var _a;
13170
12427
  const db = argToDb(arg);
13171
12428
  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) {
12429
+ const last = data?.pop();
12430
+ if (!last) return;
12431
+ if (data?.length === 1) {
13176
12432
  Object.assign(db.baseQuery.q.adapter, data[0].adapter);
13177
12433
  }
13178
- (_a = last.reject) == null ? void 0 : _a.call(last, new Rollback());
12434
+ last.reject?.(new Rollback());
13179
12435
  return last.promise;
13180
12436
  },
13181
12437
  /**
@@ -13185,10 +12441,9 @@ const testTransaction = {
13185
12441
  * @param arg - the same ORM or query argument passed into the `testTransaction.start`.
13186
12442
  */
13187
12443
  async close(arg) {
13188
- var _a;
13189
12444
  const db = argToDb(arg);
13190
12445
  await this.rollback(db);
13191
- if (((_a = db.internal[trxForTest]) == null ? void 0 : _a.length) === 0) {
12446
+ if (db.internal[trxForTest]?.length === 0) {
13192
12447
  return db.q.adapter.close();
13193
12448
  }
13194
12449
  }