pqb 0.40.10 → 0.40.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -119,25 +119,25 @@ const sqlFn = (...args) => {
119
119
  return (...args2) => new RawSQL(args2, arg);
120
120
  };
121
121
 
122
- var __defProp$m = Object.defineProperty;
123
- var __defProps$d = Object.defineProperties;
124
- var __getOwnPropDescs$d = Object.getOwnPropertyDescriptors;
125
- var __getOwnPropSymbols$n = Object.getOwnPropertySymbols;
126
- var __hasOwnProp$n = Object.prototype.hasOwnProperty;
127
- var __propIsEnum$n = Object.prototype.propertyIsEnumerable;
128
- var __defNormalProp$m = (obj, key, value) => key in obj ? __defProp$m(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
129
- var __spreadValues$m = (a, b) => {
122
+ var __defProp$n = Object.defineProperty;
123
+ var __defProps$e = Object.defineProperties;
124
+ var __getOwnPropDescs$e = Object.getOwnPropertyDescriptors;
125
+ var __getOwnPropSymbols$o = Object.getOwnPropertySymbols;
126
+ var __hasOwnProp$o = Object.prototype.hasOwnProperty;
127
+ var __propIsEnum$o = Object.prototype.propertyIsEnumerable;
128
+ var __defNormalProp$n = (obj, key, value) => key in obj ? __defProp$n(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
129
+ var __spreadValues$n = (a, b) => {
130
130
  for (var prop in b || (b = {}))
131
- if (__hasOwnProp$n.call(b, prop))
132
- __defNormalProp$m(a, prop, b[prop]);
133
- if (__getOwnPropSymbols$n)
134
- for (var prop of __getOwnPropSymbols$n(b)) {
135
- if (__propIsEnum$n.call(b, prop))
136
- __defNormalProp$m(a, prop, b[prop]);
131
+ if (__hasOwnProp$o.call(b, prop))
132
+ __defNormalProp$n(a, prop, b[prop]);
133
+ if (__getOwnPropSymbols$o)
134
+ for (var prop of __getOwnPropSymbols$o(b)) {
135
+ if (__propIsEnum$o.call(b, prop))
136
+ __defNormalProp$n(a, prop, b[prop]);
137
137
  }
138
138
  return a;
139
139
  };
140
- var __spreadProps$d = (a, b) => __defProps$d(a, __getOwnPropDescs$d(b));
140
+ var __spreadProps$e = (a, b) => __defProps$e(a, __getOwnPropDescs$e(b));
141
141
  class ColumnType extends orchidCore.ColumnTypeBase {
142
142
  /**
143
143
  * Mark the column as a primary key.
@@ -336,13 +336,13 @@ class ColumnType extends orchidCore.ColumnTypeBase {
336
336
  */
337
337
  searchIndex(...args) {
338
338
  return orchidCore.pushColumnData(this, "indexes", {
339
- options: __spreadValues$m(__spreadValues$m({}, typeof args[0] === "string" ? args[1] : args[0]), this.dataType === "tsvector" ? { using: "GIN" } : { tsVector: true }),
339
+ options: __spreadValues$n(__spreadValues$n({}, typeof args[0] === "string" ? args[1] : args[0]), this.dataType === "tsvector" ? { using: "GIN" } : { tsVector: true }),
340
340
  name: typeof args[0] === "string" ? args[0] : void 0
341
341
  });
342
342
  }
343
343
  unique(...args) {
344
344
  return orchidCore.pushColumnData(this, "indexes", {
345
- options: __spreadProps$d(__spreadValues$m({}, typeof args[0] === "string" ? args[1] : args[0]), {
345
+ options: __spreadProps$e(__spreadValues$n({}, typeof args[0] === "string" ? args[1] : args[0]), {
346
346
  unique: true
347
347
  }),
348
348
  name: typeof args[0] === "string" ? args[0] : void 0
@@ -385,25 +385,25 @@ class ColumnType extends orchidCore.ColumnTypeBase {
385
385
  }
386
386
  }
387
387
 
388
- var __defProp$l = Object.defineProperty;
389
- var __defProps$c = Object.defineProperties;
390
- var __getOwnPropDescs$c = Object.getOwnPropertyDescriptors;
391
- var __getOwnPropSymbols$m = Object.getOwnPropertySymbols;
392
- var __hasOwnProp$m = Object.prototype.hasOwnProperty;
393
- var __propIsEnum$m = Object.prototype.propertyIsEnumerable;
394
- var __defNormalProp$l = (obj, key, value) => key in obj ? __defProp$l(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
395
- var __spreadValues$l = (a, b) => {
388
+ var __defProp$m = Object.defineProperty;
389
+ var __defProps$d = Object.defineProperties;
390
+ var __getOwnPropDescs$d = Object.getOwnPropertyDescriptors;
391
+ var __getOwnPropSymbols$n = Object.getOwnPropertySymbols;
392
+ var __hasOwnProp$n = Object.prototype.hasOwnProperty;
393
+ var __propIsEnum$n = Object.prototype.propertyIsEnumerable;
394
+ var __defNormalProp$m = (obj, key, value) => key in obj ? __defProp$m(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
395
+ var __spreadValues$m = (a, b) => {
396
396
  for (var prop in b || (b = {}))
397
- if (__hasOwnProp$m.call(b, prop))
398
- __defNormalProp$l(a, prop, b[prop]);
399
- if (__getOwnPropSymbols$m)
400
- for (var prop of __getOwnPropSymbols$m(b)) {
401
- if (__propIsEnum$m.call(b, prop))
402
- __defNormalProp$l(a, prop, b[prop]);
397
+ if (__hasOwnProp$n.call(b, prop))
398
+ __defNormalProp$m(a, prop, b[prop]);
399
+ if (__getOwnPropSymbols$n)
400
+ for (var prop of __getOwnPropSymbols$n(b)) {
401
+ if (__propIsEnum$n.call(b, prop))
402
+ __defNormalProp$m(a, prop, b[prop]);
403
403
  }
404
404
  return a;
405
405
  };
406
- var __spreadProps$c = (a, b) => __defProps$c(a, __getOwnPropDescs$c(b));
406
+ var __spreadProps$d = (a, b) => __defProps$d(a, __getOwnPropDescs$d(b));
407
407
  const knownDefaults = {
408
408
  current_timestamp: "now()",
409
409
  "transaction_timestamp()": "now()"
@@ -419,7 +419,7 @@ const simplifyColumnDefault = (value) => {
419
419
  const instantiateColumn = (typeFn, params) => {
420
420
  const column = typeFn();
421
421
  const { dateTimePrecision } = params;
422
- Object.assign(column.data, __spreadProps$c(__spreadValues$l({}, params), {
422
+ Object.assign(column.data, __spreadProps$d(__spreadValues$m({}, params), {
423
423
  dateTimePrecision: (
424
424
  // 0 is default for date, 6 is default for timestamp
425
425
  dateTimePrecision && dateTimePrecision !== 6 ? dateTimePrecision : void 0
@@ -858,25 +858,25 @@ const getSqlText = (sql) => {
858
858
  throw new Error(`Batch SQL is not supported in this query`);
859
859
  };
860
860
 
861
- var __defProp$k = Object.defineProperty;
862
- var __defProps$b = Object.defineProperties;
863
- var __getOwnPropDescs$b = Object.getOwnPropertyDescriptors;
864
- var __getOwnPropSymbols$l = Object.getOwnPropertySymbols;
865
- var __hasOwnProp$l = Object.prototype.hasOwnProperty;
866
- var __propIsEnum$l = Object.prototype.propertyIsEnumerable;
867
- var __defNormalProp$k = (obj, key, value) => key in obj ? __defProp$k(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
868
- var __spreadValues$k = (a, b) => {
861
+ var __defProp$l = Object.defineProperty;
862
+ var __defProps$c = Object.defineProperties;
863
+ var __getOwnPropDescs$c = Object.getOwnPropertyDescriptors;
864
+ var __getOwnPropSymbols$m = Object.getOwnPropertySymbols;
865
+ var __hasOwnProp$m = Object.prototype.hasOwnProperty;
866
+ var __propIsEnum$m = Object.prototype.propertyIsEnumerable;
867
+ var __defNormalProp$l = (obj, key, value) => key in obj ? __defProp$l(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
868
+ var __spreadValues$l = (a, b) => {
869
869
  for (var prop in b || (b = {}))
870
- if (__hasOwnProp$l.call(b, prop))
871
- __defNormalProp$k(a, prop, b[prop]);
872
- if (__getOwnPropSymbols$l)
873
- for (var prop of __getOwnPropSymbols$l(b)) {
874
- if (__propIsEnum$l.call(b, prop))
875
- __defNormalProp$k(a, prop, b[prop]);
870
+ if (__hasOwnProp$m.call(b, prop))
871
+ __defNormalProp$l(a, prop, b[prop]);
872
+ if (__getOwnPropSymbols$m)
873
+ for (var prop of __getOwnPropSymbols$m(b)) {
874
+ if (__propIsEnum$m.call(b, prop))
875
+ __defNormalProp$l(a, prop, b[prop]);
876
876
  }
877
877
  return a;
878
878
  };
879
- var __spreadProps$b = (a, b) => __defProps$b(a, __getOwnPropDescs$b(b));
879
+ var __spreadProps$c = (a, b) => __defProps$c(a, __getOwnPropDescs$c(b));
880
880
  function setQueryOperators(query, operators) {
881
881
  const q = query.q;
882
882
  if (q.operators !== operators) {
@@ -965,7 +965,7 @@ const base = {
965
965
  (key, value, ctx, quotedAs) => `NOT ${key} IN ${quoteValue(value, ctx, quotedAs)}`
966
966
  )
967
967
  };
968
- const boolean = __spreadProps$b(__spreadValues$k({}, base), {
968
+ const boolean = __spreadProps$c(__spreadValues$l({}, base), {
969
969
  and: make(
970
970
  (key, value, ctx, quotedAs) => `${key} AND ${value.q.expr.toSQL(ctx, quotedAs)}`
971
971
  ),
@@ -973,7 +973,7 @@ const boolean = __spreadProps$b(__spreadValues$k({}, base), {
973
973
  (key, value, ctx, quotedAs) => `(${key}) OR (${value.q.expr.toSQL(ctx, quotedAs)})`
974
974
  )
975
975
  });
976
- const numeric = __spreadProps$b(__spreadValues$k({}, base), {
976
+ const numeric = __spreadProps$c(__spreadValues$l({}, base), {
977
977
  lt: make(
978
978
  (key, value, ctx, quotedAs) => `${key} < ${quoteValue(value, ctx, quotedAs)}`
979
979
  ),
@@ -994,7 +994,7 @@ const numeric = __spreadProps$b(__spreadValues$k({}, base), {
994
994
  )}`
995
995
  )
996
996
  });
997
- const text = __spreadProps$b(__spreadValues$k({}, base), {
997
+ const text = __spreadProps$c(__spreadValues$l({}, base), {
998
998
  contains: make(
999
999
  (key, value, ctx, quotedAs) => `${key} ILIKE '%' || ${quoteLikeValue(value, ctx, quotedAs)} || '%'`
1000
1000
  ),
@@ -1016,7 +1016,7 @@ const text = __spreadProps$b(__spreadValues$k({}, base), {
1016
1016
  });
1017
1017
  const encodeJsonPath = (ctx, path) => orchidCore.addValue(ctx.values, `{${Array.isArray(path) ? path.join(", ") : path}}`);
1018
1018
  const jsonPathQueryOp = (key, [path, options], ctx) => `jsonb_path_query_first(${key}, ${orchidCore.addValue(ctx.values, path)}${(options == null ? void 0 : options.vars) ? `, ${orchidCore.addValue(ctx.values, JSON.stringify(options.vars))}${options.silent ? ", true" : ""}` : (options == null ? void 0 : options.silent) ? ", NULL, true" : ""})`;
1019
- const json = __spreadProps$b(__spreadValues$k({}, base), {
1019
+ const json = __spreadProps$c(__spreadValues$l({}, base), {
1020
1020
  jsonPathQueryFirst: Object.assign(
1021
1021
  function(path, options) {
1022
1022
  var _a, _b, _c, _d, _e;
@@ -1079,25 +1079,25 @@ const Operators = {
1079
1079
  array: base
1080
1080
  };
1081
1081
 
1082
- var __defProp$j = Object.defineProperty;
1083
- var __defProps$a = Object.defineProperties;
1084
- var __getOwnPropDescs$a = Object.getOwnPropertyDescriptors;
1085
- var __getOwnPropSymbols$k = Object.getOwnPropertySymbols;
1086
- var __hasOwnProp$k = Object.prototype.hasOwnProperty;
1087
- var __propIsEnum$k = Object.prototype.propertyIsEnumerable;
1088
- var __defNormalProp$j = (obj, key, value) => key in obj ? __defProp$j(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1089
- var __spreadValues$j = (a, b) => {
1082
+ var __defProp$k = Object.defineProperty;
1083
+ var __defProps$b = Object.defineProperties;
1084
+ var __getOwnPropDescs$b = Object.getOwnPropertyDescriptors;
1085
+ var __getOwnPropSymbols$l = Object.getOwnPropertySymbols;
1086
+ var __hasOwnProp$l = Object.prototype.hasOwnProperty;
1087
+ var __propIsEnum$l = Object.prototype.propertyIsEnumerable;
1088
+ var __defNormalProp$k = (obj, key, value) => key in obj ? __defProp$k(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1089
+ var __spreadValues$k = (a, b) => {
1090
1090
  for (var prop in b || (b = {}))
1091
- if (__hasOwnProp$k.call(b, prop))
1092
- __defNormalProp$j(a, prop, b[prop]);
1093
- if (__getOwnPropSymbols$k)
1094
- for (var prop of __getOwnPropSymbols$k(b)) {
1095
- if (__propIsEnum$k.call(b, prop))
1096
- __defNormalProp$j(a, prop, b[prop]);
1091
+ if (__hasOwnProp$l.call(b, prop))
1092
+ __defNormalProp$k(a, prop, b[prop]);
1093
+ if (__getOwnPropSymbols$l)
1094
+ for (var prop of __getOwnPropSymbols$l(b)) {
1095
+ if (__propIsEnum$l.call(b, prop))
1096
+ __defNormalProp$k(a, prop, b[prop]);
1097
1097
  }
1098
1098
  return a;
1099
1099
  };
1100
- var __spreadProps$a = (a, b) => __defProps$a(a, __getOwnPropDescs$a(b));
1100
+ var __spreadProps$b = (a, b) => __defProps$b(a, __getOwnPropDescs$b(b));
1101
1101
  class TextBaseColumn extends ColumnType {
1102
1102
  constructor(schema, schemaType = schema.stringSchema()) {
1103
1103
  super(schema, schemaType);
@@ -1151,7 +1151,7 @@ class StringColumn extends VarCharColumn {
1151
1151
  }
1152
1152
  }
1153
1153
  const textColumnToCode = (column, ctx, key) => {
1154
- const data = __spreadValues$j({}, column.data);
1154
+ const data = __spreadValues$k({}, column.data);
1155
1155
  let args = "";
1156
1156
  const hasMax = data.maxArg !== void 0 && data.max === data.maxArg;
1157
1157
  if (data.minArg !== void 0 && data.min === data.minArg || hasMax) {
@@ -1456,7 +1456,7 @@ class UUIDColumn extends ColumnType {
1456
1456
  key,
1457
1457
  `uuid()`,
1458
1458
  // don't output the default default
1459
- data.default instanceof orchidCore.RawSQLBase && data.default._sql === uuidDefaultSQL ? __spreadProps$a(__spreadValues$j({}, data), { default: void 0 }) : data
1459
+ data.default instanceof orchidCore.RawSQLBase && data.default._sql === uuidDefaultSQL ? __spreadProps$b(__spreadValues$k({}, data), { default: void 0 }) : data
1460
1460
  );
1461
1461
  }
1462
1462
  }
@@ -1747,7 +1747,7 @@ const columnWithDotToSql = (ctx, data, shape, column, index, quotedAs, select) =
1747
1747
  if (key === "*") {
1748
1748
  return ((_a = data.joinedShapes) == null ? void 0 : _a[table]) ? select ? `row_to_json("${table}".*)` : `"${table}".*` : column;
1749
1749
  }
1750
- const tableName = ((_b = data.joinOverrides) == null ? void 0 : _b[table]) || table;
1750
+ const tableName = ((_b = data.aliases) == null ? void 0 : _b[table]) || table;
1751
1751
  const quoted = `"${table}"`;
1752
1752
  const col = quoted === quotedAs ? shape[key] : (_d = (_c = data.joinedShapes) == null ? void 0 : _c[tableName]) == null ? void 0 : _d[key];
1753
1753
  if (col) {
@@ -1777,12 +1777,28 @@ const columnToSqlWithAs = (ctx, data, column, as, quotedAs, select) => {
1777
1777
  const tableColumnToSqlWithAs = (ctx, data, column, table, key, as, quotedAs, select) => {
1778
1778
  var _a, _b, _c;
1779
1779
  if (key === "*") {
1780
- if ((_a = data.joinedShapes) == null ? void 0 : _a[table]) {
1781
- return select ? `row_to_json("${table}".*) "${as}"` : `"${table}".r "${as}"`;
1780
+ const shape = (_a = data.joinedShapes) == null ? void 0 : _a[table];
1781
+ if (shape) {
1782
+ if (select) {
1783
+ let isSimple = true;
1784
+ const list = [];
1785
+ for (const key2 in shape) {
1786
+ const column2 = shape[key2];
1787
+ if (column2.data.explicitSelect || column2 instanceof VirtualColumn) {
1788
+ continue;
1789
+ }
1790
+ if (column2.data.name) {
1791
+ isSimple = false;
1792
+ }
1793
+ list.push(`'${key2}'`, `"${table}"."${column2.data.name || key2}"`);
1794
+ }
1795
+ return (isSimple ? `row_to_json("${table}".*)` : "json_build_object(" + list.join(", ") + ")") + ` "${as}"`;
1796
+ }
1797
+ return `"${table}".r "${as}"`;
1782
1798
  }
1783
1799
  return column;
1784
1800
  }
1785
- const tableName = ((_b = data.joinOverrides) == null ? void 0 : _b[table]) || table;
1801
+ const tableName = ((_b = data.aliases) == null ? void 0 : _b[table]) || table;
1786
1802
  const quoted = `"${table}"`;
1787
1803
  const col = quoted === quotedAs ? data.shape[key] : (_c = data.joinedShapes) == null ? void 0 : _c[tableName][key];
1788
1804
  if (col) {
@@ -1898,8 +1914,10 @@ class QueryError extends OrchidOrmInternalError {
1898
1914
  const list = (_a = this.detail.match(/\((.*)\)=/)) == null ? void 0 : _a[1];
1899
1915
  if (list) {
1900
1916
  list.split(", ").forEach((item) => {
1917
+ var _a2;
1901
1918
  const column = item.startsWith('"') ? item.slice(1, -1) : item;
1902
- columns[column] = true;
1919
+ const key = (_a2 = this.query.columnNameToKey(column)) != null ? _a2 : column;
1920
+ columns[key] = true;
1903
1921
  });
1904
1922
  }
1905
1923
  }
@@ -1949,6 +1967,17 @@ const throwIfNoWhere = (q, method) => {
1949
1967
  );
1950
1968
  }
1951
1969
  };
1970
+ const throwIfJoinLateral = (q, method) => {
1971
+ var _a;
1972
+ if ((_a = q.q.join) == null ? void 0 : _a.some(
1973
+ (x) => Array.isArray(x) || "s" in x.args && x.args.s
1974
+ )) {
1975
+ throw new OrchidOrmInternalError(
1976
+ q,
1977
+ `Cannot join a complex query in ${method}`
1978
+ );
1979
+ }
1980
+ };
1952
1981
  const saveSearchAlias = (q, as, key) => {
1953
1982
  const shapes = q.q[key];
1954
1983
  if (shapes == null ? void 0 : shapes[as]) {
@@ -2110,9 +2139,9 @@ const processWhere = (ands, ctx, table, query, data, quotedAs) => {
2110
2139
  const item = value;
2111
2140
  const joinAs = `"${getJoinItemSource(item.joinFrom)}"`;
2112
2141
  const { on } = item;
2113
- const q = item.useOuterJoinOverrides ? {
2142
+ const q = item.useOuterAliases ? {
2114
2143
  joinedShapes: query.joinedShapes,
2115
- joinOverrides: query.outerJoinOverrides,
2144
+ aliases: query.outerAliases,
2116
2145
  shape: query.shape
2117
2146
  } : query;
2118
2147
  ands.push(
@@ -2240,25 +2269,25 @@ const pushIn = (ctx, query, ands, quotedAs, arg) => {
2240
2269
  ands.push(`${multiple ? `(${columnsSql})` : columnsSql} IN ${value}`);
2241
2270
  };
2242
2271
 
2243
- var __defProp$i = Object.defineProperty;
2244
- var __defProps$9 = Object.defineProperties;
2245
- var __getOwnPropDescs$9 = Object.getOwnPropertyDescriptors;
2246
- var __getOwnPropSymbols$j = Object.getOwnPropertySymbols;
2247
- var __hasOwnProp$j = Object.prototype.hasOwnProperty;
2248
- var __propIsEnum$j = Object.prototype.propertyIsEnumerable;
2249
- var __defNormalProp$i = (obj, key, value) => key in obj ? __defProp$i(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2250
- var __spreadValues$i = (a, b) => {
2272
+ var __defProp$j = Object.defineProperty;
2273
+ var __defProps$a = Object.defineProperties;
2274
+ var __getOwnPropDescs$a = Object.getOwnPropertyDescriptors;
2275
+ var __getOwnPropSymbols$k = Object.getOwnPropertySymbols;
2276
+ var __hasOwnProp$k = Object.prototype.hasOwnProperty;
2277
+ var __propIsEnum$k = Object.prototype.propertyIsEnumerable;
2278
+ var __defNormalProp$j = (obj, key, value) => key in obj ? __defProp$j(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2279
+ var __spreadValues$j = (a, b) => {
2251
2280
  for (var prop in b || (b = {}))
2252
- if (__hasOwnProp$j.call(b, prop))
2253
- __defNormalProp$i(a, prop, b[prop]);
2254
- if (__getOwnPropSymbols$j)
2255
- for (var prop of __getOwnPropSymbols$j(b)) {
2256
- if (__propIsEnum$j.call(b, prop))
2257
- __defNormalProp$i(a, prop, b[prop]);
2281
+ if (__hasOwnProp$k.call(b, prop))
2282
+ __defNormalProp$j(a, prop, b[prop]);
2283
+ if (__getOwnPropSymbols$k)
2284
+ for (var prop of __getOwnPropSymbols$k(b)) {
2285
+ if (__propIsEnum$k.call(b, prop))
2286
+ __defNormalProp$j(a, prop, b[prop]);
2258
2287
  }
2259
2288
  return a;
2260
2289
  };
2261
- var __spreadProps$9 = (a, b) => __defProps$9(a, __getOwnPropDescs$9(b));
2290
+ var __spreadProps$a = (a, b) => __defProps$a(a, __getOwnPropDescs$a(b));
2262
2291
  const processJoinItem = (ctx, table, query, args, quotedAs) => {
2263
2292
  let target;
2264
2293
  let on;
@@ -2320,8 +2349,8 @@ const processJoinItem = (ctx, table, query, args, quotedAs) => {
2320
2349
  const whereSql = whereToSql(
2321
2350
  ctx,
2322
2351
  q,
2323
- __spreadProps$9(__spreadValues$i({}, q.q), {
2324
- joinedShapes: __spreadProps$9(__spreadValues$i(__spreadValues$i({}, query.joinedShapes), q.q.joinedShapes), {
2352
+ __spreadProps$a(__spreadValues$j({}, q.q), {
2353
+ joinedShapes: __spreadProps$a(__spreadValues$j(__spreadValues$j({}, query.joinedShapes), q.q.joinedShapes), {
2325
2354
  [table.q.as || table.table]: table.q.shape
2326
2355
  })
2327
2356
  }),
@@ -2424,7 +2453,7 @@ const pushJoinSql = (ctx, table, query, quotedAs) => {
2424
2453
  const { aliasValue } = ctx;
2425
2454
  ctx.aliasValue = true;
2426
2455
  const as = item[2];
2427
- sql = `${item[0]} LATERAL (${getSqlText(q.toSQL(ctx))}) "${((_a = query.joinOverrides) == null ? void 0 : _a[as]) || as}" ON true`;
2456
+ sql = `${item[0]} LATERAL (${getSqlText(q.toSQL(ctx))}) "${((_a = query.aliases) == null ? void 0 : _a[as]) || as}" ON true`;
2428
2457
  ctx.aliasValue = aliasValue;
2429
2458
  } else {
2430
2459
  const { target, on = "true" } = processJoinItem(
@@ -2453,7 +2482,8 @@ const skipQueryKeysForSubQuery = {
2453
2482
  or: true,
2454
2483
  returnType: true,
2455
2484
  joinedShapes: true,
2456
- returnsOne: true
2485
+ returnsOne: true,
2486
+ aliases: true
2457
2487
  };
2458
2488
  const getIsJoinSubQuery = (query) => {
2459
2489
  const {
@@ -2468,25 +2498,25 @@ const getIsJoinSubQuery = (query) => {
2468
2498
  return false;
2469
2499
  };
2470
2500
 
2471
- var __defProp$h = Object.defineProperty;
2472
- var __defProps$8 = Object.defineProperties;
2473
- var __getOwnPropDescs$8 = Object.getOwnPropertyDescriptors;
2474
- var __getOwnPropSymbols$i = Object.getOwnPropertySymbols;
2475
- var __hasOwnProp$i = Object.prototype.hasOwnProperty;
2476
- var __propIsEnum$i = Object.prototype.propertyIsEnumerable;
2477
- var __defNormalProp$h = (obj, key, value) => key in obj ? __defProp$h(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2478
- var __spreadValues$h = (a, b) => {
2501
+ var __defProp$i = Object.defineProperty;
2502
+ var __defProps$9 = Object.defineProperties;
2503
+ var __getOwnPropDescs$9 = Object.getOwnPropertyDescriptors;
2504
+ var __getOwnPropSymbols$j = Object.getOwnPropertySymbols;
2505
+ var __hasOwnProp$j = Object.prototype.hasOwnProperty;
2506
+ var __propIsEnum$j = Object.prototype.propertyIsEnumerable;
2507
+ var __defNormalProp$i = (obj, key, value) => key in obj ? __defProp$i(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2508
+ var __spreadValues$i = (a, b) => {
2479
2509
  for (var prop in b || (b = {}))
2480
- if (__hasOwnProp$i.call(b, prop))
2481
- __defNormalProp$h(a, prop, b[prop]);
2482
- if (__getOwnPropSymbols$i)
2483
- for (var prop of __getOwnPropSymbols$i(b)) {
2484
- if (__propIsEnum$i.call(b, prop))
2485
- __defNormalProp$h(a, prop, b[prop]);
2510
+ if (__hasOwnProp$j.call(b, prop))
2511
+ __defNormalProp$i(a, prop, b[prop]);
2512
+ if (__getOwnPropSymbols$j)
2513
+ for (var prop of __getOwnPropSymbols$j(b)) {
2514
+ if (__propIsEnum$j.call(b, prop))
2515
+ __defNormalProp$i(a, prop, b[prop]);
2486
2516
  }
2487
2517
  return a;
2488
2518
  };
2489
- var __spreadProps$8 = (a, b) => __defProps$8(a, __getOwnPropDescs$8(b));
2519
+ var __spreadProps$9 = (a, b) => __defProps$9(a, __getOwnPropDescs$9(b));
2490
2520
  const processJoinArgs = (joinTo, first, args, joinSubQuery, whereExists) => {
2491
2521
  var _a;
2492
2522
  if (typeof first === "string") {
@@ -2523,13 +2553,13 @@ const processJoinArgs = (joinTo, first, args, joinSubQuery, whereExists) => {
2523
2553
  logger: joinToQ.logger
2524
2554
  };
2525
2555
  j.baseQuery = j;
2526
- const joinedShapes = __spreadProps$8(__spreadValues$h({}, joinToQ.joinedShapes), {
2556
+ const joinedShapes = __spreadProps$9(__spreadValues$i({}, joinToQ.joinedShapes), {
2527
2557
  [joinToQ.as || joinTo.table]: joinTo.shape
2528
2558
  });
2529
2559
  const r = args[0](
2530
2560
  makeJoinQueryBuilder(
2531
2561
  j,
2532
- j.q.joinedShapes ? __spreadValues$h(__spreadValues$h({}, j.q.joinedShapes), joinedShapes) : joinedShapes,
2562
+ j.q.joinedShapes ? __spreadValues$i(__spreadValues$i({}, j.q.joinedShapes), joinedShapes) : joinedShapes,
2533
2563
  joinTo
2534
2564
  )
2535
2565
  );
@@ -2556,16 +2586,16 @@ const processJoinArgs = (joinTo, first, args, joinSubQuery, whereExists) => {
2556
2586
  pushQueryArray(q, "or", query.or);
2557
2587
  }
2558
2588
  if (query.scopes) {
2559
- q.q.scopes = __spreadValues$h(__spreadValues$h({}, q.q.scopes), query.scopes);
2589
+ q.q.scopes = __spreadValues$i(__spreadValues$i({}, q.q.scopes), query.scopes);
2560
2590
  }
2561
2591
  }
2562
- const joinedShapes = __spreadProps$8(__spreadValues$h({}, joinTo.q.joinedShapes), {
2592
+ const joinedShapes = __spreadProps$9(__spreadValues$i({}, joinTo.q.joinedShapes), {
2563
2593
  [joinTo.q.as || joinTo.table]: joinTo.shape
2564
2594
  });
2565
2595
  const r = args0(
2566
2596
  makeJoinQueryBuilder(
2567
2597
  q,
2568
- q.q.joinedShapes ? __spreadValues$h(__spreadValues$h({}, q.q.joinedShapes), joinedShapes) : joinedShapes,
2598
+ q.q.joinedShapes ? __spreadValues$i(__spreadValues$i({}, q.q.joinedShapes), joinedShapes) : joinedShapes,
2569
2599
  joinTo
2570
2600
  )
2571
2601
  );
@@ -2620,25 +2650,25 @@ const _queryNone = (q) => {
2620
2650
  };
2621
2651
  const isQueryNone = (q) => q.then === noneMethods.then;
2622
2652
 
2623
- var __defProp$g = Object.defineProperty;
2624
- var __defProps$7 = Object.defineProperties;
2625
- var __getOwnPropDescs$7 = Object.getOwnPropertyDescriptors;
2626
- var __getOwnPropSymbols$h = Object.getOwnPropertySymbols;
2627
- var __hasOwnProp$h = Object.prototype.hasOwnProperty;
2628
- var __propIsEnum$h = Object.prototype.propertyIsEnumerable;
2629
- var __defNormalProp$g = (obj, key, value) => key in obj ? __defProp$g(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2630
- var __spreadValues$g = (a, b) => {
2653
+ var __defProp$h = Object.defineProperty;
2654
+ var __defProps$8 = Object.defineProperties;
2655
+ var __getOwnPropDescs$8 = Object.getOwnPropertyDescriptors;
2656
+ var __getOwnPropSymbols$i = Object.getOwnPropertySymbols;
2657
+ var __hasOwnProp$i = Object.prototype.hasOwnProperty;
2658
+ var __propIsEnum$i = Object.prototype.propertyIsEnumerable;
2659
+ var __defNormalProp$h = (obj, key, value) => key in obj ? __defProp$h(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2660
+ var __spreadValues$h = (a, b) => {
2631
2661
  for (var prop in b || (b = {}))
2632
- if (__hasOwnProp$h.call(b, prop))
2633
- __defNormalProp$g(a, prop, b[prop]);
2634
- if (__getOwnPropSymbols$h)
2635
- for (var prop of __getOwnPropSymbols$h(b)) {
2636
- if (__propIsEnum$h.call(b, prop))
2637
- __defNormalProp$g(a, prop, b[prop]);
2662
+ if (__hasOwnProp$i.call(b, prop))
2663
+ __defNormalProp$h(a, prop, b[prop]);
2664
+ if (__getOwnPropSymbols$i)
2665
+ for (var prop of __getOwnPropSymbols$i(b)) {
2666
+ if (__propIsEnum$i.call(b, prop))
2667
+ __defNormalProp$h(a, prop, b[prop]);
2638
2668
  }
2639
2669
  return a;
2640
2670
  };
2641
- var __spreadProps$7 = (a, b) => __defProps$7(a, __getOwnPropDescs$7(b));
2671
+ var __spreadProps$8 = (a, b) => __defProps$8(a, __getOwnPropDescs$8(b));
2642
2672
  const _join = (query, require2, type, first, args) => {
2643
2673
  var _a, _b, _c, _d;
2644
2674
  let joinKey;
@@ -2652,16 +2682,16 @@ const _join = (query, require2, type, first, args) => {
2652
2682
  if (require2 && isQueryNone(first)) {
2653
2683
  return _queryNone(query);
2654
2684
  }
2655
- const q = first;
2656
- joinSubQuery = getIsJoinSubQuery(q);
2657
- joinKey = q.q.as || q.table;
2685
+ const q2 = first;
2686
+ joinSubQuery = getIsJoinSubQuery(q2);
2687
+ joinKey = q2.q.as || q2.table;
2658
2688
  if (joinKey) {
2659
- shape = getShapeFromSelect(q, joinSubQuery);
2660
- parsers = q.q.parsers;
2661
- batchParsers = q.q.batchParsers;
2662
- computeds = q.q.computeds;
2689
+ shape = getShapeFromSelect(q2, joinSubQuery && !!q2.q.select);
2690
+ parsers = q2.q.parsers;
2691
+ batchParsers = q2.q.batchParsers;
2692
+ computeds = q2.q.computeds;
2663
2693
  if (joinSubQuery) {
2664
- first = q.clone();
2694
+ first = q2.clone();
2665
2695
  first.shape = shape;
2666
2696
  }
2667
2697
  }
@@ -2680,7 +2710,7 @@ const _join = (query, require2, type, first, args) => {
2680
2710
  computeds = w == null ? void 0 : w.computeds;
2681
2711
  if (shape) {
2682
2712
  if (!require2)
2683
- shape = __spreadValues$g({}, shape);
2713
+ shape = __spreadValues$h({}, shape);
2684
2714
  parsers = {};
2685
2715
  for (const key in shape) {
2686
2716
  const parser = shape[key].parseFn;
@@ -2744,10 +2774,14 @@ const _join = (query, require2, type, first, args) => {
2744
2774
  computeds
2745
2775
  );
2746
2776
  }
2747
- return pushQueryValue(query, "join", {
2777
+ const q = pushQueryValue(query, "join", {
2748
2778
  type,
2749
2779
  args: joinArgs
2750
2780
  });
2781
+ if (query.q.type === "delete") {
2782
+ throwIfJoinLateral(q, query.q.type);
2783
+ }
2784
+ return q;
2751
2785
  };
2752
2786
  const addAllShapesAndParsers = (query, joinKey, shape, parsers, batchParsers, computeds) => {
2753
2787
  var _a, _b;
@@ -2780,7 +2814,7 @@ const _joinLateral = (self, type, arg, cb, as) => {
2780
2814
  t.table = arg;
2781
2815
  t.shape = w.shape;
2782
2816
  t.computeds = w.computeds;
2783
- t.q = __spreadProps$7(__spreadValues$g({}, t.q), {
2817
+ t.q = __spreadProps$8(__spreadValues$h({}, t.q), {
2784
2818
  shape: w.shape
2785
2819
  });
2786
2820
  t.baseQuery = t;
@@ -3269,25 +3303,25 @@ class QueryLog {
3269
3303
  }
3270
3304
  }
3271
3305
 
3272
- var __defProp$f = Object.defineProperty;
3273
- var __defProps$6 = Object.defineProperties;
3274
- var __getOwnPropDescs$6 = Object.getOwnPropertyDescriptors;
3275
- var __getOwnPropSymbols$g = Object.getOwnPropertySymbols;
3276
- var __hasOwnProp$g = Object.prototype.hasOwnProperty;
3277
- var __propIsEnum$g = Object.prototype.propertyIsEnumerable;
3278
- var __defNormalProp$f = (obj, key, value) => key in obj ? __defProp$f(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3279
- var __spreadValues$f = (a, b) => {
3306
+ var __defProp$g = Object.defineProperty;
3307
+ var __defProps$7 = Object.defineProperties;
3308
+ var __getOwnPropDescs$7 = Object.getOwnPropertyDescriptors;
3309
+ var __getOwnPropSymbols$h = Object.getOwnPropertySymbols;
3310
+ var __hasOwnProp$h = Object.prototype.hasOwnProperty;
3311
+ var __propIsEnum$h = Object.prototype.propertyIsEnumerable;
3312
+ var __defNormalProp$g = (obj, key, value) => key in obj ? __defProp$g(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3313
+ var __spreadValues$g = (a, b) => {
3280
3314
  for (var prop in b || (b = {}))
3281
- if (__hasOwnProp$g.call(b, prop))
3282
- __defNormalProp$f(a, prop, b[prop]);
3283
- if (__getOwnPropSymbols$g)
3284
- for (var prop of __getOwnPropSymbols$g(b)) {
3285
- if (__propIsEnum$g.call(b, prop))
3286
- __defNormalProp$f(a, prop, b[prop]);
3315
+ if (__hasOwnProp$h.call(b, prop))
3316
+ __defNormalProp$g(a, prop, b[prop]);
3317
+ if (__getOwnPropSymbols$h)
3318
+ for (var prop of __getOwnPropSymbols$h(b)) {
3319
+ if (__propIsEnum$h.call(b, prop))
3320
+ __defNormalProp$g(a, prop, b[prop]);
3287
3321
  }
3288
3322
  return a;
3289
3323
  };
3290
- var __spreadProps$6 = (a, b) => __defProps$6(a, __getOwnPropDescs$6(b));
3324
+ var __spreadProps$7 = (a, b) => __defProps$7(a, __getOwnPropDescs$7(b));
3291
3325
  const commitSql$1 = {
3292
3326
  text: "COMMIT"
3293
3327
  };
@@ -3452,7 +3486,7 @@ const runAfterCommit = async (afterCommit, result) => {
3452
3486
  let r = 0;
3453
3487
  for (let i = 0, len = afterCommit.length; i < len; i += 3) {
3454
3488
  for (const fn of afterCommit[i + 2]) {
3455
- resultsWithNames.push(__spreadProps$6(__spreadValues$f({}, hookResults[r++]), {
3489
+ resultsWithNames.push(__spreadProps$7(__spreadValues$g({}, hookResults[r++]), {
3456
3490
  name: fn.name
3457
3491
  }));
3458
3492
  }
@@ -3514,25 +3548,25 @@ const finalizeNestedHookSelect = (batches, returnType, tempColumns, renames, key
3514
3548
  }
3515
3549
  };
3516
3550
 
3517
- var __defProp$e = Object.defineProperty;
3518
- var __defProps$5 = Object.defineProperties;
3519
- var __getOwnPropDescs$5 = Object.getOwnPropertyDescriptors;
3520
- var __getOwnPropSymbols$f = Object.getOwnPropertySymbols;
3521
- var __hasOwnProp$f = Object.prototype.hasOwnProperty;
3522
- var __propIsEnum$f = Object.prototype.propertyIsEnumerable;
3523
- var __defNormalProp$e = (obj, key, value) => key in obj ? __defProp$e(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3524
- var __spreadValues$e = (a, b) => {
3551
+ var __defProp$f = Object.defineProperty;
3552
+ var __defProps$6 = Object.defineProperties;
3553
+ var __getOwnPropDescs$6 = Object.getOwnPropertyDescriptors;
3554
+ var __getOwnPropSymbols$g = Object.getOwnPropertySymbols;
3555
+ var __hasOwnProp$g = Object.prototype.hasOwnProperty;
3556
+ var __propIsEnum$g = Object.prototype.propertyIsEnumerable;
3557
+ var __defNormalProp$f = (obj, key, value) => key in obj ? __defProp$f(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3558
+ var __spreadValues$f = (a, b) => {
3525
3559
  for (var prop in b || (b = {}))
3526
- if (__hasOwnProp$f.call(b, prop))
3527
- __defNormalProp$e(a, prop, b[prop]);
3528
- if (__getOwnPropSymbols$f)
3529
- for (var prop of __getOwnPropSymbols$f(b)) {
3530
- if (__propIsEnum$f.call(b, prop))
3531
- __defNormalProp$e(a, prop, b[prop]);
3560
+ if (__hasOwnProp$g.call(b, prop))
3561
+ __defNormalProp$f(a, prop, b[prop]);
3562
+ if (__getOwnPropSymbols$g)
3563
+ for (var prop of __getOwnPropSymbols$g(b)) {
3564
+ if (__propIsEnum$g.call(b, prop))
3565
+ __defNormalProp$f(a, prop, b[prop]);
3532
3566
  }
3533
3567
  return a;
3534
3568
  };
3535
- var __spreadProps$5 = (a, b) => __defProps$5(a, __getOwnPropDescs$5(b));
3569
+ var __spreadProps$6 = (a, b) => __defProps$6(a, __getOwnPropDescs$6(b));
3536
3570
  class ComputedColumn {
3537
3571
  constructor(kind, deps, fn) {
3538
3572
  this.kind = kind;
@@ -3549,9 +3583,11 @@ const applyComputedColumns = (q, fn) => {
3549
3583
  for (const key in computed) {
3550
3584
  const item = computed[key];
3551
3585
  if (item instanceof ComputedColumn) {
3552
- q.q.computeds = __spreadProps$5(__spreadValues$e({}, q.q.computeds), { [key]: item });
3586
+ q.q.computeds = __spreadProps$6(__spreadValues$f({}, q.q.computeds), { [key]: item });
3553
3587
  } else {
3554
- (q.shape[key] = item.result.value || UnknownColumn.instance).data.computed = item;
3588
+ const data = (q.shape[key] = item.result.value || UnknownColumn.instance).data;
3589
+ data.computed = item;
3590
+ data.explicitSelect = true;
3555
3591
  }
3556
3592
  }
3557
3593
  q.computeAtRuntime = q.computeBatchAtRuntime = void 0;
@@ -3657,25 +3693,25 @@ const saveBatchComputed = (key, result, res, blanks) => {
3657
3693
  }
3658
3694
  };
3659
3695
 
3660
- var __defProp$d = Object.defineProperty;
3661
- var __defProps$4 = Object.defineProperties;
3662
- var __getOwnPropDescs$4 = Object.getOwnPropertyDescriptors;
3663
- var __getOwnPropSymbols$e = Object.getOwnPropertySymbols;
3664
- var __hasOwnProp$e = Object.prototype.hasOwnProperty;
3665
- var __propIsEnum$e = Object.prototype.propertyIsEnumerable;
3666
- var __defNormalProp$d = (obj, key, value) => key in obj ? __defProp$d(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3667
- var __spreadValues$d = (a, b) => {
3696
+ var __defProp$e = Object.defineProperty;
3697
+ var __defProps$5 = Object.defineProperties;
3698
+ var __getOwnPropDescs$5 = Object.getOwnPropertyDescriptors;
3699
+ var __getOwnPropSymbols$f = Object.getOwnPropertySymbols;
3700
+ var __hasOwnProp$f = Object.prototype.hasOwnProperty;
3701
+ var __propIsEnum$f = Object.prototype.propertyIsEnumerable;
3702
+ var __defNormalProp$e = (obj, key, value) => key in obj ? __defProp$e(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3703
+ var __spreadValues$e = (a, b) => {
3668
3704
  for (var prop in b || (b = {}))
3669
- if (__hasOwnProp$e.call(b, prop))
3670
- __defNormalProp$d(a, prop, b[prop]);
3671
- if (__getOwnPropSymbols$e)
3672
- for (var prop of __getOwnPropSymbols$e(b)) {
3673
- if (__propIsEnum$e.call(b, prop))
3674
- __defNormalProp$d(a, prop, b[prop]);
3705
+ if (__hasOwnProp$f.call(b, prop))
3706
+ __defNormalProp$e(a, prop, b[prop]);
3707
+ if (__getOwnPropSymbols$f)
3708
+ for (var prop of __getOwnPropSymbols$f(b)) {
3709
+ if (__propIsEnum$f.call(b, prop))
3710
+ __defNormalProp$e(a, prop, b[prop]);
3675
3711
  }
3676
3712
  return a;
3677
3713
  };
3678
- var __spreadProps$4 = (a, b) => __defProps$4(a, __getOwnPropDescs$4(b));
3714
+ var __spreadProps$5 = (a, b) => __defProps$5(a, __getOwnPropDescs$5(b));
3679
3715
  const queryMethodByReturnType = {
3680
3716
  undefined: "query",
3681
3717
  all: "query",
@@ -3919,7 +3955,7 @@ const then = async (q, adapter, trx, beforeHooks, afterHooks, afterCommitHooks,
3919
3955
  if (hookResults.some((result2) => result2.status === "rejected")) {
3920
3956
  _afterCommitError(
3921
3957
  result,
3922
- hookResults.map((result2, i) => __spreadProps$4(__spreadValues$d({}, result2), {
3958
+ hookResults.map((result2, i) => __spreadProps$5(__spreadValues$e({}, result2), {
3923
3959
  name: afterCommitHooks[i].name
3924
3960
  })),
3925
3961
  q.q.catchAfterCommitError
@@ -3966,6 +4002,16 @@ const then = async (q, adapter, trx, beforeHooks, afterHooks, afterCommitHooks,
3966
4002
  error.cause = localError;
3967
4003
  }
3968
4004
  }
4005
+ const stack = localError.stack;
4006
+ if (stack) {
4007
+ const from = stack.indexOf("\n");
4008
+ if (from !== -1) {
4009
+ const to = stack.indexOf("\n", from + 1);
4010
+ if (to !== -1) {
4011
+ localError.stack = stack.slice(0, from) + stack.slice(to);
4012
+ }
4013
+ }
4014
+ }
3969
4015
  if (log && sql) {
3970
4016
  log.onError(error, sql, logData);
3971
4017
  }
@@ -4151,7 +4197,7 @@ const filterResult = (q, returnType, queryResult, result, tempColumns, hasAfterH
4151
4197
  return row;
4152
4198
  } else {
4153
4199
  if (hasAfterHook)
4154
- row = __spreadValues$d({}, row);
4200
+ row = __spreadValues$e({}, row);
4155
4201
  for (const column of tempColumns) {
4156
4202
  delete row[column];
4157
4203
  }
@@ -4194,7 +4240,7 @@ const filterAllResult = (result, tempColumns, hasAfterHook) => {
4194
4240
  if (tempColumns == null ? void 0 : tempColumns.size) {
4195
4241
  if (hasAfterHook) {
4196
4242
  return result.map((data) => {
4197
- const record = __spreadValues$d({}, data);
4243
+ const record = __spreadValues$e({}, data);
4198
4244
  for (const key of tempColumns) {
4199
4245
  delete record[key];
4200
4246
  }
@@ -4211,25 +4257,25 @@ const filterAllResult = (result, tempColumns, hasAfterHook) => {
4211
4257
  return result;
4212
4258
  };
4213
4259
 
4214
- var __defProp$c = Object.defineProperty;
4215
- var __defProps$3 = Object.defineProperties;
4216
- var __getOwnPropDescs$3 = Object.getOwnPropertyDescriptors;
4217
- var __getOwnPropSymbols$d = Object.getOwnPropertySymbols;
4218
- var __hasOwnProp$d = Object.prototype.hasOwnProperty;
4219
- var __propIsEnum$d = Object.prototype.propertyIsEnumerable;
4220
- var __defNormalProp$c = (obj, key, value) => key in obj ? __defProp$c(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
4221
- var __spreadValues$c = (a, b) => {
4260
+ var __defProp$d = Object.defineProperty;
4261
+ var __defProps$4 = Object.defineProperties;
4262
+ var __getOwnPropDescs$4 = Object.getOwnPropertyDescriptors;
4263
+ var __getOwnPropSymbols$e = Object.getOwnPropertySymbols;
4264
+ var __hasOwnProp$e = Object.prototype.hasOwnProperty;
4265
+ var __propIsEnum$e = Object.prototype.propertyIsEnumerable;
4266
+ var __defNormalProp$d = (obj, key, value) => key in obj ? __defProp$d(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
4267
+ var __spreadValues$d = (a, b) => {
4222
4268
  for (var prop in b || (b = {}))
4223
- if (__hasOwnProp$d.call(b, prop))
4224
- __defNormalProp$c(a, prop, b[prop]);
4225
- if (__getOwnPropSymbols$d)
4226
- for (var prop of __getOwnPropSymbols$d(b)) {
4227
- if (__propIsEnum$d.call(b, prop))
4228
- __defNormalProp$c(a, prop, b[prop]);
4269
+ if (__hasOwnProp$e.call(b, prop))
4270
+ __defNormalProp$d(a, prop, b[prop]);
4271
+ if (__getOwnPropSymbols$e)
4272
+ for (var prop of __getOwnPropSymbols$e(b)) {
4273
+ if (__propIsEnum$e.call(b, prop))
4274
+ __defNormalProp$d(a, prop, b[prop]);
4229
4275
  }
4230
4276
  return a;
4231
4277
  };
4232
- var __spreadProps$3 = (a, b) => __defProps$3(a, __getOwnPropDescs$3(b));
4278
+ var __spreadProps$4 = (a, b) => __defProps$4(a, __getOwnPropDescs$4(b));
4233
4279
  const addParserForRawExpression = (q, key, raw) => {
4234
4280
  const type = raw.result.value;
4235
4281
  if (type == null ? void 0 : type.parseFn)
@@ -4451,11 +4497,12 @@ const collectNestedSelectBatches = (batches, rows, path, last) => {
4451
4497
  };
4452
4498
  const emptyArrSQL = new RawSQL("'[]'");
4453
4499
  const processSelectArg = (q, as, arg, columnAs) => {
4454
- var _a, _b, _c, _d;
4500
+ var _a, _b;
4455
4501
  if (typeof arg === "string") {
4456
4502
  return setParserForSelectedString(q, arg, as, columnAs);
4457
4503
  }
4458
4504
  const selectAs = {};
4505
+ let aliases;
4459
4506
  for (const key in arg) {
4460
4507
  let value = arg[key];
4461
4508
  if (typeof value === "function") {
@@ -4490,17 +4537,11 @@ const processSelectArg = (q, as, arg, columnAs) => {
4490
4537
  query = value;
4491
4538
  }
4492
4539
  }
4493
- let asOverride = key;
4494
- if ((_a = value.q.joinedShapes) == null ? void 0 : _a[key]) {
4495
- let suffix = 2;
4496
- const joinOverrides = (_c = (_b = q.q).joinOverrides) != null ? _c : _b.joinOverrides = {};
4497
- while (joinOverrides[asOverride = `${key}${suffix}`]) {
4498
- suffix++;
4499
- }
4500
- joinOverrides[asOverride] = asOverride;
4501
- joinOverrides[key] = asOverride;
4502
- }
4540
+ const asOverride = (_a = value.q.aliases[key]) != null ? _a : key;
4503
4541
  value.q.joinedForSelect = asOverride;
4542
+ if (asOverride !== key) {
4543
+ aliases = __spreadProps$4(__spreadValues$d({}, q.q.aliases), { [key]: asOverride });
4544
+ }
4504
4545
  _joinLateral(
4505
4546
  q,
4506
4547
  value.q.innerJoinLateral ? "JOIN" : "LEFT JOIN",
@@ -4508,10 +4549,12 @@ const processSelectArg = (q, as, arg, columnAs) => {
4508
4549
  (q2) => q2,
4509
4550
  key
4510
4551
  );
4511
- } else if (((_d = value.q) == null ? void 0 : _d.subQuery) && value.q.expr) {
4552
+ } else if (((_b = value.q) == null ? void 0 : _b.subQuery) && value.q.expr) {
4512
4553
  value = value.q.expr;
4513
4554
  }
4514
4555
  }
4556
+ if (aliases)
4557
+ q.q.aliases = aliases;
4515
4558
  selectAs[key] = addParserForSelectItem(
4516
4559
  q,
4517
4560
  as,
@@ -4556,7 +4599,7 @@ const setParserForSelectedString = (q, arg, as, columnAs) => {
4556
4599
  for (const column2 of computed.deps) {
4557
4600
  map.set(column2, { select: `${table}.${column2}` });
4558
4601
  }
4559
- q.q.selectedComputeds = __spreadProps$3(__spreadValues$c({}, q.q.selectedComputeds), {
4602
+ q.q.selectedComputeds = __spreadProps$4(__spreadValues$d({}, q.q.selectedComputeds), {
4560
4603
  [column]: computed
4561
4604
  });
4562
4605
  return;
@@ -4580,7 +4623,7 @@ const handleComputed = (q, computeds, column) => {
4580
4623
  for (const column2 of computed.deps) {
4581
4624
  map.set(column2, { select: column2 });
4582
4625
  }
4583
- q.q.selectedComputeds = __spreadProps$3(__spreadValues$c({}, q.q.selectedComputeds), { [column]: computed });
4626
+ q.q.selectedComputeds = __spreadProps$4(__spreadValues$d({}, q.q.selectedComputeds), { [column]: computed });
4584
4627
  return;
4585
4628
  }
4586
4629
  return column;
@@ -4778,10 +4821,43 @@ function _queryGetOptional(self, arg) {
4778
4821
  return _get(self, "value", arg);
4779
4822
  }
4780
4823
 
4824
+ var __defProp$c = Object.defineProperty;
4825
+ var __defProps$3 = Object.defineProperties;
4826
+ var __getOwnPropDescs$3 = Object.getOwnPropertyDescriptors;
4827
+ var __getOwnPropSymbols$d = Object.getOwnPropertySymbols;
4828
+ var __hasOwnProp$d = Object.prototype.hasOwnProperty;
4829
+ var __propIsEnum$d = Object.prototype.propertyIsEnumerable;
4830
+ var __defNormalProp$c = (obj, key, value) => key in obj ? __defProp$c(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
4831
+ var __spreadValues$c = (a, b) => {
4832
+ for (var prop in b || (b = {}))
4833
+ if (__hasOwnProp$d.call(b, prop))
4834
+ __defNormalProp$c(a, prop, b[prop]);
4835
+ if (__getOwnPropSymbols$d)
4836
+ for (var prop of __getOwnPropSymbols$d(b)) {
4837
+ if (__propIsEnum$d.call(b, prop))
4838
+ __defNormalProp$c(a, prop, b[prop]);
4839
+ }
4840
+ return a;
4841
+ };
4842
+ var __spreadProps$3 = (a, b) => __defProps$3(a, __getOwnPropDescs$3(b));
4781
4843
  const _queryAs = (self, as) => {
4782
- self.q.as = as;
4844
+ const { q } = self;
4845
+ q.as = as;
4846
+ q.aliases = __spreadProps$3(__spreadValues$c({}, q.aliases), {
4847
+ [as]: q.aliases ? _queryResolveAlias(q.aliases, as) : as
4848
+ });
4783
4849
  return self;
4784
4850
  };
4851
+ const _queryResolveAlias = (aliases, as) => {
4852
+ if (!aliases[as])
4853
+ return as;
4854
+ let suffix = 2;
4855
+ let privateAs;
4856
+ while (aliases[privateAs = as + suffix]) {
4857
+ suffix++;
4858
+ }
4859
+ return privateAs;
4860
+ };
4785
4861
  class AsMethods {
4786
4862
  /**
4787
4863
  * Sets table alias:
@@ -5777,7 +5853,7 @@ const processValue = (ctx, table, QueryClass, key, value, quotedAs) => {
5777
5853
  };
5778
5854
 
5779
5855
  const pushDeleteSql = (ctx, table, query, quotedAs) => {
5780
- var _a, _b, _c, _d;
5856
+ var _a, _b, _c;
5781
5857
  const from = `"${table.table}"`;
5782
5858
  ctx.sql.push(`DELETE FROM ${from}`);
5783
5859
  if (from !== quotedAs) {
@@ -5789,27 +5865,16 @@ const pushDeleteSql = (ctx, table, query, quotedAs) => {
5789
5865
  const ons = [];
5790
5866
  const joinSet = query.join.length > 1 ? /* @__PURE__ */ new Set() : null;
5791
5867
  for (const item of query.join) {
5792
- if (Array.isArray(item)) {
5793
- const q = item[1];
5794
- const { aliasValue } = ctx;
5795
- ctx.aliasValue = true;
5796
- const as = item[2];
5797
- targets.push(
5798
- `LATERAL (${getSqlText(q.toSQL(ctx))}) "${((_b = query.joinOverrides) == null ? void 0 : _b[as]) || as}"`
5799
- );
5800
- ctx.aliasValue = aliasValue;
5801
- } else {
5802
- const join = processJoinItem(ctx, table, query, item.args, quotedAs);
5803
- const key = `${join.target}${join.on}`;
5804
- if (joinSet) {
5805
- if (joinSet.has(key))
5806
- continue;
5807
- joinSet.add(key);
5808
- }
5809
- targets.push(join.target);
5810
- if (join.on)
5811
- ons.push(join.on);
5868
+ const join = processJoinItem(ctx, table, query, item.args, quotedAs);
5869
+ const key = `${join.target}${join.on}`;
5870
+ if (joinSet) {
5871
+ if (joinSet.has(key))
5872
+ continue;
5873
+ joinSet.add(key);
5812
5874
  }
5875
+ targets.push(join.target);
5876
+ if (join.on)
5877
+ ons.push(join.on);
5813
5878
  }
5814
5879
  if (targets.length) {
5815
5880
  ctx.sql.push(`USING ${targets.join(", ")}`);
@@ -5818,7 +5883,7 @@ const pushDeleteSql = (ctx, table, query, quotedAs) => {
5818
5883
  }
5819
5884
  pushWhereStatementSql(ctx, table, query, quotedAs);
5820
5885
  if (conditions) {
5821
- if (((_c = query.and) == null ? void 0 : _c.length) || ((_d = query.or) == null ? void 0 : _d.length) || query.scopes) {
5886
+ if (((_b = query.and) == null ? void 0 : _b.length) || ((_c = query.or) == null ? void 0 : _c.length) || query.scopes) {
5822
5887
  ctx.sql.push("AND", conditions);
5823
5888
  } else {
5824
5889
  ctx.sql.push("WHERE", conditions);
@@ -6158,14 +6223,14 @@ const makeRegexToFindInSql = (value) => {
6158
6223
  return new RegExp(`${value}(?=(?:[^']*'[^']*')*[^']*$)`, "g");
6159
6224
  };
6160
6225
  const resolveSubQueryCallback = (q, cb) => {
6161
- const { subQuery, relChain, outerJoinOverrides } = q.q;
6226
+ const { subQuery, relChain, outerAliases } = q.q;
6162
6227
  q.q.subQuery = 1;
6163
6228
  q.q.relChain = void 0;
6164
- q.q.outerJoinOverrides = q.q.joinOverrides;
6229
+ q.q.outerAliases = q.q.aliases;
6165
6230
  const result = cb(q);
6166
6231
  q.q.subQuery = subQuery;
6167
6232
  q.q.relChain = relChain;
6168
- q.q.outerJoinOverrides = outerJoinOverrides;
6233
+ q.q.outerAliases = outerAliases;
6169
6234
  return result;
6170
6235
  };
6171
6236
  const joinSubQuery = (q, sub) => {
@@ -8198,6 +8263,7 @@ const _queryDelete = (query) => {
8198
8263
  q.returnType = "rowCount";
8199
8264
  }
8200
8265
  throwIfNoWhere(query, "delete");
8266
+ throwIfJoinLateral(query, "delete");
8201
8267
  q.type = "delete";
8202
8268
  return query;
8203
8269
  };
@@ -9318,7 +9384,7 @@ const pushQueryOnForOuter = (q, joinFrom, joinTo, ...on) => {
9318
9384
  ON: {
9319
9385
  joinTo: joinFrom,
9320
9386
  joinFrom: joinTo,
9321
- useOuterJoinOverrides: true,
9387
+ useOuterAliases: true,
9322
9388
  on
9323
9389
  }
9324
9390
  });
@@ -9727,7 +9793,7 @@ const resolveCallbacksInArgs = (q, args) => {
9727
9793
  qb.q = getClonedQueryData(q.q);
9728
9794
  qb.q.and = qb.q.or = qb.q.scopes = void 0;
9729
9795
  qb.q.subQuery = 1;
9730
- qb.q.outerJoinOverrides = qb.q.joinOverrides;
9796
+ qb.q.outerAliases = qb.q.aliases;
9731
9797
  args[i] = resolveSubQueryCallback(qb, arg);
9732
9798
  }
9733
9799
  }
@@ -12786,16 +12852,18 @@ class Db {
12786
12852
  applyComputedColumns(this, options.computed);
12787
12853
  if (prepareSelectAll) {
12788
12854
  const list = [];
12855
+ const keys = {};
12789
12856
  for (const key in shape) {
12790
12857
  const column = shape[key];
12791
12858
  if (!column.data.explicitSelect) {
12792
12859
  list.push(
12793
12860
  column.data.name ? `"${column.data.name}" AS "${key}"` : `"${key}"`
12794
12861
  );
12862
+ keys[key] = column;
12795
12863
  }
12796
12864
  }
12797
12865
  this.q.selectAllColumns = list;
12798
- this.q.selectAllKeys = __spreadValues({}, shape);
12866
+ this.q.selectAllKeys = keys;
12799
12867
  }
12800
12868
  if (modifyQuery) {
12801
12869
  for (const cb of modifyQuery) {
@@ -12888,6 +12956,23 @@ class Db {
12888
12956
  queryArrays(...args) {
12889
12957
  return performQuery(this, args, "arrays");
12890
12958
  }
12959
+ /**
12960
+ * In snake case mode, or when columns have custom names,
12961
+ * use this method to exchange a db column name to its runtime key.
12962
+ */
12963
+ columnNameToKey(name) {
12964
+ var _a;
12965
+ let map = this.internal.columnNameToKeyMap;
12966
+ if (!map) {
12967
+ this.internal.columnNameToKeyMap = map = /* @__PURE__ */ new Map();
12968
+ const { shape } = this;
12969
+ for (const key in this.shape) {
12970
+ const column = shape[key];
12971
+ map.set((_a = column.data.name) != null ? _a : key, key);
12972
+ }
12973
+ }
12974
+ return map.get(name);
12975
+ }
12891
12976
  }
12892
12977
  const performQuery = async (q, args, method) => {
12893
12978
  var _a;
@@ -13295,6 +13380,7 @@ exports._queryJoinOnJsonPathEquals = _queryJoinOnJsonPathEquals;
13295
13380
  exports._queryJoinOrOn = _queryJoinOrOn;
13296
13381
  exports._queryOr = _queryOr;
13297
13382
  exports._queryOrNot = _queryOrNot;
13383
+ exports._queryResolveAlias = _queryResolveAlias;
13298
13384
  exports._queryRows = _queryRows;
13299
13385
  exports._querySelect = _querySelect;
13300
13386
  exports._queryTake = _queryTake;
@@ -13394,6 +13480,7 @@ exports.sqlQueryArgsToExpression = sqlQueryArgsToExpression;
13394
13480
  exports.tableDataMethods = tableDataMethods;
13395
13481
  exports.templateLiteralToSQL = templateLiteralToSQL;
13396
13482
  exports.testTransaction = testTransaction;
13483
+ exports.throwIfJoinLateral = throwIfJoinLateral;
13397
13484
  exports.throwIfNoWhere = throwIfNoWhere;
13398
13485
  exports.toSQL = toSQL;
13399
13486
  exports.toSQLCacheKey = toSQLCacheKey;