pqb 0.42.4 → 0.42.6

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