pqb 0.39.1 → 0.39.3

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$l = Object.defineProperty;
123
- var __defProps$b = Object.defineProperties;
124
- var __getOwnPropDescs$b = Object.getOwnPropertyDescriptors;
125
- var __getOwnPropSymbols$m = Object.getOwnPropertySymbols;
126
- var __hasOwnProp$m = Object.prototype.hasOwnProperty;
127
- var __propIsEnum$m = Object.prototype.propertyIsEnumerable;
128
- var __defNormalProp$l = (obj, key, value) => key in obj ? __defProp$l(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
129
- var __spreadValues$l = (a, b) => {
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) => {
130
130
  for (var prop in b || (b = {}))
131
- if (__hasOwnProp$m.call(b, prop))
132
- __defNormalProp$l(a, prop, b[prop]);
133
- if (__getOwnPropSymbols$m)
134
- for (var prop of __getOwnPropSymbols$m(b)) {
135
- if (__propIsEnum$m.call(b, prop))
136
- __defNormalProp$l(a, prop, b[prop]);
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]);
137
137
  }
138
138
  return a;
139
139
  };
140
- var __spreadProps$b = (a, b) => __defProps$b(a, __getOwnPropDescs$b(b));
140
+ var __spreadProps$d = (a, b) => __defProps$d(a, __getOwnPropDescs$d(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$l(__spreadValues$l({}, typeof args[0] === "string" ? args[1] : args[0]), this.dataType === "tsvector" ? { using: "GIN" } : { tsVector: true }),
339
+ options: __spreadValues$m(__spreadValues$m({}, 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$b(__spreadValues$l({}, typeof args[0] === "string" ? args[1] : args[0]), {
345
+ options: __spreadProps$d(__spreadValues$m({}, 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$k = Object.defineProperty;
389
- var __defProps$a = Object.defineProperties;
390
- var __getOwnPropDescs$a = Object.getOwnPropertyDescriptors;
391
- var __getOwnPropSymbols$l = Object.getOwnPropertySymbols;
392
- var __hasOwnProp$l = Object.prototype.hasOwnProperty;
393
- var __propIsEnum$l = Object.prototype.propertyIsEnumerable;
394
- var __defNormalProp$k = (obj, key, value) => key in obj ? __defProp$k(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
395
- var __spreadValues$k = (a, b) => {
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) => {
396
396
  for (var prop in b || (b = {}))
397
- if (__hasOwnProp$l.call(b, prop))
398
- __defNormalProp$k(a, prop, b[prop]);
399
- if (__getOwnPropSymbols$l)
400
- for (var prop of __getOwnPropSymbols$l(b)) {
401
- if (__propIsEnum$l.call(b, prop))
402
- __defNormalProp$k(a, prop, b[prop]);
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]);
403
403
  }
404
404
  return a;
405
405
  };
406
- var __spreadProps$a = (a, b) => __defProps$a(a, __getOwnPropDescs$a(b));
406
+ var __spreadProps$c = (a, b) => __defProps$c(a, __getOwnPropDescs$c(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$a(__spreadValues$k({}, params), {
422
+ Object.assign(column.data, __spreadProps$c(__spreadValues$l({}, 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$j = Object.defineProperty;
862
- var __defProps$9 = Object.defineProperties;
863
- var __getOwnPropDescs$9 = Object.getOwnPropertyDescriptors;
864
- var __getOwnPropSymbols$k = Object.getOwnPropertySymbols;
865
- var __hasOwnProp$k = Object.prototype.hasOwnProperty;
866
- var __propIsEnum$k = Object.prototype.propertyIsEnumerable;
867
- var __defNormalProp$j = (obj, key, value) => key in obj ? __defProp$j(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
868
- var __spreadValues$j = (a, b) => {
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) => {
869
869
  for (var prop in b || (b = {}))
870
- if (__hasOwnProp$k.call(b, prop))
871
- __defNormalProp$j(a, prop, b[prop]);
872
- if (__getOwnPropSymbols$k)
873
- for (var prop of __getOwnPropSymbols$k(b)) {
874
- if (__propIsEnum$k.call(b, prop))
875
- __defNormalProp$j(a, prop, b[prop]);
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]);
876
876
  }
877
877
  return a;
878
878
  };
879
- var __spreadProps$9 = (a, b) => __defProps$9(a, __getOwnPropDescs$9(b));
879
+ var __spreadProps$b = (a, b) => __defProps$b(a, __getOwnPropDescs$b(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$1(value, ctx, quotedAs)}`
966
966
  )
967
967
  };
968
- const boolean = __spreadProps$9(__spreadValues$j({}, base), {
968
+ const boolean = __spreadProps$b(__spreadValues$k({}, 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$9(__spreadValues$j({}, base), {
973
973
  (key, value, ctx, quotedAs) => `(${key}) OR (${value.q.expr.toSQL(ctx, quotedAs)})`
974
974
  )
975
975
  });
976
- const numeric = __spreadProps$9(__spreadValues$j({}, base), {
976
+ const numeric = __spreadProps$b(__spreadValues$k({}, base), {
977
977
  lt: make(
978
978
  (key, value, ctx, quotedAs) => `${key} < ${quoteValue$1(value, ctx, quotedAs)}`
979
979
  ),
@@ -994,7 +994,7 @@ const numeric = __spreadProps$9(__spreadValues$j({}, base), {
994
994
  )}`
995
995
  )
996
996
  });
997
- const text = __spreadProps$9(__spreadValues$j({}, base), {
997
+ const text = __spreadProps$b(__spreadValues$k({}, 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$9(__spreadValues$j({}, 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$9(__spreadValues$j({}, base), {
1019
+ const json = __spreadProps$b(__spreadValues$k({}, base), {
1020
1020
  jsonPathQueryFirst: Object.assign(
1021
1021
  function(path, options) {
1022
1022
  var _a, _b, _c, _d, _e;
@@ -1266,25 +1266,25 @@ class BigSerialColumn extends NumberAsStringBaseColumn {
1266
1266
  }
1267
1267
  }
1268
1268
 
1269
- var __defProp$i = Object.defineProperty;
1270
- var __defProps$8 = Object.defineProperties;
1271
- var __getOwnPropDescs$8 = Object.getOwnPropertyDescriptors;
1272
- var __getOwnPropSymbols$j = Object.getOwnPropertySymbols;
1273
- var __hasOwnProp$j = Object.prototype.hasOwnProperty;
1274
- var __propIsEnum$j = Object.prototype.propertyIsEnumerable;
1275
- var __defNormalProp$i = (obj, key, value) => key in obj ? __defProp$i(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1276
- var __spreadValues$i = (a, b) => {
1269
+ var __defProp$j = Object.defineProperty;
1270
+ var __defProps$a = Object.defineProperties;
1271
+ var __getOwnPropDescs$a = Object.getOwnPropertyDescriptors;
1272
+ var __getOwnPropSymbols$k = Object.getOwnPropertySymbols;
1273
+ var __hasOwnProp$k = Object.prototype.hasOwnProperty;
1274
+ var __propIsEnum$k = Object.prototype.propertyIsEnumerable;
1275
+ var __defNormalProp$j = (obj, key, value) => key in obj ? __defProp$j(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1276
+ var __spreadValues$j = (a, b) => {
1277
1277
  for (var prop in b || (b = {}))
1278
- if (__hasOwnProp$j.call(b, prop))
1279
- __defNormalProp$i(a, prop, b[prop]);
1280
- if (__getOwnPropSymbols$j)
1281
- for (var prop of __getOwnPropSymbols$j(b)) {
1282
- if (__propIsEnum$j.call(b, prop))
1283
- __defNormalProp$i(a, prop, b[prop]);
1278
+ if (__hasOwnProp$k.call(b, prop))
1279
+ __defNormalProp$j(a, prop, b[prop]);
1280
+ if (__getOwnPropSymbols$k)
1281
+ for (var prop of __getOwnPropSymbols$k(b)) {
1282
+ if (__propIsEnum$k.call(b, prop))
1283
+ __defNormalProp$j(a, prop, b[prop]);
1284
1284
  }
1285
1285
  return a;
1286
1286
  };
1287
- var __spreadProps$8 = (a, b) => __defProps$8(a, __getOwnPropDescs$8(b));
1287
+ var __spreadProps$a = (a, b) => __defProps$a(a, __getOwnPropDescs$a(b));
1288
1288
  class TextBaseColumn extends ColumnType {
1289
1289
  constructor(schema, schemaType = schema.stringSchema()) {
1290
1290
  super(schema, schemaType);
@@ -1338,7 +1338,7 @@ class StringColumn extends VarCharColumn {
1338
1338
  }
1339
1339
  }
1340
1340
  const textColumnToCode = (column, ctx, key) => {
1341
- const data = __spreadValues$i({}, column.data);
1341
+ const data = __spreadValues$j({}, column.data);
1342
1342
  let args = "";
1343
1343
  const hasMax = data.maxArg !== void 0 && data.max === data.maxArg;
1344
1344
  if (data.minArg !== void 0 && data.min === data.minArg || hasMax) {
@@ -1642,7 +1642,7 @@ class UUIDColumn extends ColumnType {
1642
1642
  key,
1643
1643
  `uuid()`,
1644
1644
  // don't output the default default
1645
- data.default instanceof orchidCore.RawSQLBase && data.default._sql === uuidDefaultSQL ? __spreadProps$8(__spreadValues$i({}, data), { default: void 0 }) : data
1645
+ data.default instanceof orchidCore.RawSQLBase && data.default._sql === uuidDefaultSQL ? __spreadProps$a(__spreadValues$j({}, data), { default: void 0 }) : data
1646
1646
  );
1647
1647
  }
1648
1648
  }
@@ -1868,15 +1868,22 @@ const queryTypeWithLimitOne = {
1868
1868
  };
1869
1869
  const isQueryReturnsAll = (q) => !q.q.returnType || q.q.returnType === "all";
1870
1870
 
1871
- function simpleColumnToSQL(ctx, key, column, quotedAs) {
1871
+ const applySqlComputed = (ctx, q, computed, as, quotedAs) => {
1872
+ var _a;
1873
+ const parser = computed.result.value.parseFn;
1874
+ if (parser)
1875
+ ((_a = q.parsers) != null ? _a : q.parsers = {})[as] = parser;
1876
+ return computed.toSQL(ctx, quotedAs);
1877
+ };
1878
+ function simpleColumnToSQL(ctx, q, key, column, quotedAs) {
1872
1879
  if (!column)
1873
1880
  return `"${key}"`;
1874
1881
  const { data } = column;
1875
- return data.computed ? data.computed.toSQL(ctx, quotedAs) : `${quotedAs ? `${quotedAs}.` : ""}"${data.name || key}"`;
1882
+ return data.computed ? applySqlComputed(ctx, q, data.computed, key, quotedAs) : `${quotedAs ? `${quotedAs}.` : ""}"${data.name || key}"`;
1876
1883
  }
1877
- function simpleExistingColumnToSQL(ctx, key, column, quotedAs) {
1884
+ function simpleExistingColumnToSQL(ctx, q, key, column, quotedAs) {
1878
1885
  const { data } = column;
1879
- return data.computed ? data.computed.toSQL(ctx, quotedAs) : `${quotedAs ? `${quotedAs}.` : ""}"${data.name || key}"`;
1886
+ return data.computed ? applySqlComputed(ctx, q, data.computed, key, quotedAs) : `${quotedAs ? `${quotedAs}.` : ""}"${data.name || key}"`;
1880
1887
  }
1881
1888
  const columnToSql = (ctx, data, shape, column, quotedAs, select) => {
1882
1889
  var _a;
@@ -1895,7 +1902,7 @@ const columnToSql = (ctx, data, shape, column, quotedAs, select) => {
1895
1902
  if (!select && ((_a = data.joinedShapes) == null ? void 0 : _a[column])) {
1896
1903
  return `"${column}".r`;
1897
1904
  }
1898
- return simpleColumnToSQL(ctx, column, shape[column], quotedAs);
1905
+ return simpleColumnToSQL(ctx, data, column, shape[column], quotedAs);
1899
1906
  };
1900
1907
  const maybeSelectedColumnToSql = (ctx, data, column, quotedAs) => {
1901
1908
  var _a;
@@ -1910,12 +1917,12 @@ const maybeSelectedColumnToSql = (ctx, data, column, quotedAs) => {
1910
1917
  for (const s of data.select) {
1911
1918
  if (typeof s === "object" && "selectAs" in s) {
1912
1919
  if (column in s.selectAs) {
1913
- return simpleColumnToSQL(ctx, column, data.shape[column]);
1920
+ return simpleColumnToSQL(ctx, data, column, data.shape[column]);
1914
1921
  }
1915
1922
  }
1916
1923
  }
1917
1924
  }
1918
- return simpleColumnToSQL(ctx, column, data.shape[column], quotedAs);
1925
+ return simpleColumnToSQL(ctx, data, column, data.shape[column], quotedAs);
1919
1926
  }
1920
1927
  };
1921
1928
  const columnWithDotToSql = (ctx, data, shape, column, index, quotedAs, select) => {
@@ -1933,17 +1940,30 @@ const columnWithDotToSql = (ctx, data, shape, column, index, quotedAs, select) =
1933
1940
  return `"${tableName}"."${col.data.name}"`;
1934
1941
  }
1935
1942
  if (col.data.computed) {
1936
- return `${col.data.computed.toSQL(ctx, quoted)}`;
1943
+ return applySqlComputed(ctx, data, col.data.computed, column, quoted);
1937
1944
  }
1938
1945
  return `"${tableName}"."${key}"`;
1939
1946
  }
1940
1947
  return `"${tableName}"."${key}"`;
1941
1948
  };
1942
- const tableColumnToSqlWithAs = (ctx, data, column, table, key, quotedAs, select) => {
1949
+ const columnToSqlWithAs = (ctx, data, column, as, quotedAs, select) => {
1950
+ const index = column.indexOf(".");
1951
+ return index !== -1 ? tableColumnToSqlWithAs(
1952
+ ctx,
1953
+ data,
1954
+ column,
1955
+ column.slice(0, index),
1956
+ column.slice(index + 1),
1957
+ as,
1958
+ quotedAs,
1959
+ select
1960
+ ) : ownColumnToSqlWithAs(ctx, data, column, as, quotedAs, select);
1961
+ };
1962
+ const tableColumnToSqlWithAs = (ctx, data, column, table, key, as, quotedAs, select) => {
1943
1963
  var _a, _b, _c;
1944
1964
  if (key === "*") {
1945
1965
  if ((_a = data.joinedShapes) == null ? void 0 : _a[table]) {
1946
- return select ? `row_to_json("${table}".*) "${table}"` : `"${table}".r "${table}"`;
1966
+ return select ? `row_to_json("${table}".*) "${as}"` : `"${table}".r "${as}"`;
1947
1967
  }
1948
1968
  return column;
1949
1969
  }
@@ -1952,29 +1972,41 @@ const tableColumnToSqlWithAs = (ctx, data, column, table, key, quotedAs, select)
1952
1972
  const col = quoted === quotedAs ? data.shape[key] : (_c = data.joinedShapes) == null ? void 0 : _c[tableName][key];
1953
1973
  if (col) {
1954
1974
  if (col.data.name && col.data.name !== key) {
1955
- return `"${tableName}"."${col.data.name}" "${key}"`;
1975
+ return `"${tableName}"."${col.data.name}" "${as}"`;
1956
1976
  }
1957
1977
  if (col.data.computed) {
1958
- return `${col.data.computed.toSQL(ctx, quoted)} "${key}"`;
1978
+ return `${applySqlComputed(
1979
+ ctx,
1980
+ data,
1981
+ col.data.computed,
1982
+ as,
1983
+ quoted
1984
+ )} "${as}"`;
1959
1985
  }
1960
1986
  }
1961
- return `"${tableName}"."${key}"`;
1987
+ return `"${tableName}"."${key}"${key === as ? "" : ` "${as}"`}`;
1962
1988
  };
1963
- const ownColumnToSqlWithAs = (ctx, data, column, quotedAs, select) => {
1989
+ const ownColumnToSqlWithAs = (ctx, data, column, as, quotedAs, select) => {
1964
1990
  var _a;
1965
1991
  if (!select && ((_a = data.joinedShapes) == null ? void 0 : _a[column])) {
1966
- return select ? `row_to_json("${column}".*) "${column}"` : `"${column}".r "${column}"`;
1992
+ return select ? `row_to_json("${column}".*) "${as}"` : `"${column}".r "${as}"`;
1967
1993
  }
1968
1994
  const col = data.shape[column];
1969
1995
  if (col) {
1970
1996
  if (col.data.name && col.data.name !== column) {
1971
- return `${quotedAs ? `${quotedAs}.` : ""}"${col.data.name}" "${column}"`;
1997
+ return `${quotedAs ? `${quotedAs}.` : ""}"${col.data.name}"${col.data.name === as ? "" : ` "${as}"`}`;
1972
1998
  }
1973
1999
  if (col.data.computed) {
1974
- return `${col.data.computed.toSQL(ctx, quotedAs)} "${column}"`;
2000
+ return `${applySqlComputed(
2001
+ ctx,
2002
+ data,
2003
+ col.data.computed,
2004
+ as,
2005
+ quotedAs
2006
+ )} "${as}"`;
1975
2007
  }
1976
2008
  }
1977
- return `${quotedAs ? `${quotedAs}.` : ""}"${column}"`;
2009
+ return `${quotedAs ? `${quotedAs}.` : ""}"${column}"${column === as ? "" : ` "${as}"`}`;
1978
2010
  };
1979
2011
  const rawOrColumnToSql = (ctx, data, expr, quotedAs, shape = data.shape, select) => {
1980
2012
  return typeof expr === "string" ? columnToSql(ctx, data, shape, expr, quotedAs, select) : expr.toSQL(ctx, quotedAs);
@@ -2011,26 +2043,33 @@ var __privateSet = (obj, member, value, setter) => {
2011
2043
  setter ? setter.call(obj, value) : member.set(obj, value);
2012
2044
  return value;
2013
2045
  };
2014
- var _query;
2046
+ var _query, _query2;
2015
2047
  class OrchidOrmError extends Error {
2016
2048
  }
2017
2049
  class NotFoundError extends OrchidOrmError {
2018
2050
  constructor(query, message = "Record is not found") {
2019
2051
  super(message);
2020
- this.query = query;
2052
+ // `#query` is private to prevent it from serializing to not cause problems to test runner reports
2053
+ __privateAdd(this, _query, void 0);
2054
+ __privateSet(this, _query, query);
2055
+ }
2056
+ get query() {
2057
+ return __privateGet(this, _query);
2021
2058
  }
2022
2059
  }
2060
+ _query = new WeakMap();
2023
2061
  class OrchidOrmInternalError extends Error {
2024
2062
  constructor(query, message) {
2025
2063
  super(message);
2026
- __privateAdd(this, _query, void 0);
2027
- __privateSet(this, _query, query);
2064
+ // `#query` is private to prevent it from serializing to not cause problems to test runner reports
2065
+ __privateAdd(this, _query2, void 0);
2066
+ __privateSet(this, _query2, query);
2028
2067
  }
2029
2068
  get query() {
2030
- return __privateGet(this, _query);
2069
+ return __privateGet(this, _query2);
2031
2070
  }
2032
2071
  }
2033
- _query = new WeakMap();
2072
+ _query2 = new WeakMap();
2034
2073
  class QueryError extends OrchidOrmInternalError {
2035
2074
  get isUnique() {
2036
2075
  return this.code === "23505";
@@ -2306,7 +2345,13 @@ const processWhere = (ands, ctx, table, query, data, quotedAs) => {
2306
2345
  let column = query.shape[key];
2307
2346
  let quotedColumn;
2308
2347
  if (column) {
2309
- quotedColumn = simpleExistingColumnToSQL(ctx, key, column, quotedAs);
2348
+ quotedColumn = simpleExistingColumnToSQL(
2349
+ ctx,
2350
+ query,
2351
+ key,
2352
+ column,
2353
+ quotedAs
2354
+ );
2310
2355
  } else if (!column) {
2311
2356
  const index = key.indexOf(".");
2312
2357
  if (index !== -1) {
@@ -2314,7 +2359,7 @@ const processWhere = (ands, ctx, table, query, data, quotedAs) => {
2314
2359
  const quoted = `"${table2}"`;
2315
2360
  const name = key.slice(index + 1);
2316
2361
  column = quotedAs === quoted ? query.shape[name] : (_b = (_a = query.joinedShapes) == null ? void 0 : _a[table2]) == null ? void 0 : _b[name];
2317
- quotedColumn = simpleColumnToSQL(ctx, name, column, quoted);
2362
+ quotedColumn = simpleColumnToSQL(ctx, query, name, column, quoted);
2318
2363
  } else {
2319
2364
  column = (_d = (_c = query.joinedShapes) == null ? void 0 : _c[key]) == null ? void 0 : _d.value;
2320
2365
  quotedColumn = `"${key}".r`;
@@ -2380,25 +2425,25 @@ const pushIn = (ctx, query, ands, quotedAs, arg) => {
2380
2425
  ands.push(`${multiple ? `(${columnsSql})` : columnsSql} IN ${value}`);
2381
2426
  };
2382
2427
 
2383
- var __defProp$h = Object.defineProperty;
2384
- var __defProps$7 = Object.defineProperties;
2385
- var __getOwnPropDescs$7 = Object.getOwnPropertyDescriptors;
2386
- var __getOwnPropSymbols$i = Object.getOwnPropertySymbols;
2387
- var __hasOwnProp$i = Object.prototype.hasOwnProperty;
2388
- var __propIsEnum$i = Object.prototype.propertyIsEnumerable;
2389
- var __defNormalProp$h = (obj, key, value) => key in obj ? __defProp$h(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2390
- var __spreadValues$h = (a, b) => {
2428
+ var __defProp$i = Object.defineProperty;
2429
+ var __defProps$9 = Object.defineProperties;
2430
+ var __getOwnPropDescs$9 = Object.getOwnPropertyDescriptors;
2431
+ var __getOwnPropSymbols$j = Object.getOwnPropertySymbols;
2432
+ var __hasOwnProp$j = Object.prototype.hasOwnProperty;
2433
+ var __propIsEnum$j = Object.prototype.propertyIsEnumerable;
2434
+ var __defNormalProp$i = (obj, key, value) => key in obj ? __defProp$i(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2435
+ var __spreadValues$i = (a, b) => {
2391
2436
  for (var prop in b || (b = {}))
2392
- if (__hasOwnProp$i.call(b, prop))
2393
- __defNormalProp$h(a, prop, b[prop]);
2394
- if (__getOwnPropSymbols$i)
2395
- for (var prop of __getOwnPropSymbols$i(b)) {
2396
- if (__propIsEnum$i.call(b, prop))
2397
- __defNormalProp$h(a, prop, b[prop]);
2437
+ if (__hasOwnProp$j.call(b, prop))
2438
+ __defNormalProp$i(a, prop, b[prop]);
2439
+ if (__getOwnPropSymbols$j)
2440
+ for (var prop of __getOwnPropSymbols$j(b)) {
2441
+ if (__propIsEnum$j.call(b, prop))
2442
+ __defNormalProp$i(a, prop, b[prop]);
2398
2443
  }
2399
2444
  return a;
2400
2445
  };
2401
- var __spreadProps$7 = (a, b) => __defProps$7(a, __getOwnPropDescs$7(b));
2446
+ var __spreadProps$9 = (a, b) => __defProps$9(a, __getOwnPropDescs$9(b));
2402
2447
  const processJoinItem = (ctx, table, query, args, quotedAs) => {
2403
2448
  let target;
2404
2449
  let on;
@@ -2460,8 +2505,8 @@ const processJoinItem = (ctx, table, query, args, quotedAs) => {
2460
2505
  const whereSql = whereToSql(
2461
2506
  ctx,
2462
2507
  q,
2463
- __spreadProps$7(__spreadValues$h({}, q.q), {
2464
- joinedShapes: __spreadProps$7(__spreadValues$h(__spreadValues$h({}, query.joinedShapes), q.q.joinedShapes), {
2508
+ __spreadProps$9(__spreadValues$i({}, q.q), {
2509
+ joinedShapes: __spreadProps$9(__spreadValues$i(__spreadValues$i({}, query.joinedShapes), q.q.joinedShapes), {
2465
2510
  [table.q.as || table.table]: table.q.shape
2466
2511
  })
2467
2512
  }),
@@ -2608,25 +2653,25 @@ const getIsJoinSubQuery = (query) => {
2608
2653
  return false;
2609
2654
  };
2610
2655
 
2611
- var __defProp$g = Object.defineProperty;
2612
- var __defProps$6 = Object.defineProperties;
2613
- var __getOwnPropDescs$6 = Object.getOwnPropertyDescriptors;
2614
- var __getOwnPropSymbols$h = Object.getOwnPropertySymbols;
2615
- var __hasOwnProp$h = Object.prototype.hasOwnProperty;
2616
- var __propIsEnum$h = Object.prototype.propertyIsEnumerable;
2617
- var __defNormalProp$g = (obj, key, value) => key in obj ? __defProp$g(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2618
- var __spreadValues$g = (a, b) => {
2656
+ var __defProp$h = Object.defineProperty;
2657
+ var __defProps$8 = Object.defineProperties;
2658
+ var __getOwnPropDescs$8 = Object.getOwnPropertyDescriptors;
2659
+ var __getOwnPropSymbols$i = Object.getOwnPropertySymbols;
2660
+ var __hasOwnProp$i = Object.prototype.hasOwnProperty;
2661
+ var __propIsEnum$i = Object.prototype.propertyIsEnumerable;
2662
+ var __defNormalProp$h = (obj, key, value) => key in obj ? __defProp$h(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2663
+ var __spreadValues$h = (a, b) => {
2619
2664
  for (var prop in b || (b = {}))
2620
- if (__hasOwnProp$h.call(b, prop))
2621
- __defNormalProp$g(a, prop, b[prop]);
2622
- if (__getOwnPropSymbols$h)
2623
- for (var prop of __getOwnPropSymbols$h(b)) {
2624
- if (__propIsEnum$h.call(b, prop))
2625
- __defNormalProp$g(a, prop, b[prop]);
2665
+ if (__hasOwnProp$i.call(b, prop))
2666
+ __defNormalProp$h(a, prop, b[prop]);
2667
+ if (__getOwnPropSymbols$i)
2668
+ for (var prop of __getOwnPropSymbols$i(b)) {
2669
+ if (__propIsEnum$i.call(b, prop))
2670
+ __defNormalProp$h(a, prop, b[prop]);
2626
2671
  }
2627
2672
  return a;
2628
2673
  };
2629
- var __spreadProps$6 = (a, b) => __defProps$6(a, __getOwnPropDescs$6(b));
2674
+ var __spreadProps$8 = (a, b) => __defProps$8(a, __getOwnPropDescs$8(b));
2630
2675
  const processJoinArgs = (joinTo, first, args, joinSubQuery, whereExists) => {
2631
2676
  var _a;
2632
2677
  if (typeof first === "string") {
@@ -2663,13 +2708,13 @@ const processJoinArgs = (joinTo, first, args, joinSubQuery, whereExists) => {
2663
2708
  logger: joinToQ.logger
2664
2709
  };
2665
2710
  j.baseQuery = j;
2666
- const joinedShapes = __spreadProps$6(__spreadValues$g({}, joinToQ.joinedShapes), {
2711
+ const joinedShapes = __spreadProps$8(__spreadValues$h({}, joinToQ.joinedShapes), {
2667
2712
  [joinToQ.as || joinTo.table]: joinTo.shape
2668
2713
  });
2669
2714
  const r = args[0](
2670
2715
  makeJoinQueryBuilder(
2671
2716
  j,
2672
- j.q.joinedShapes ? __spreadValues$g(__spreadValues$g({}, j.q.joinedShapes), joinedShapes) : joinedShapes,
2717
+ j.q.joinedShapes ? __spreadValues$h(__spreadValues$h({}, j.q.joinedShapes), joinedShapes) : joinedShapes,
2673
2718
  joinTo
2674
2719
  )
2675
2720
  );
@@ -2696,16 +2741,16 @@ const processJoinArgs = (joinTo, first, args, joinSubQuery, whereExists) => {
2696
2741
  pushQueryArray(q, "or", query.or);
2697
2742
  }
2698
2743
  if (query.scopes) {
2699
- q.q.scopes = __spreadValues$g(__spreadValues$g({}, q.q.scopes), query.scopes);
2744
+ q.q.scopes = __spreadValues$h(__spreadValues$h({}, q.q.scopes), query.scopes);
2700
2745
  }
2701
2746
  }
2702
- const joinedShapes = __spreadProps$6(__spreadValues$g({}, joinTo.q.joinedShapes), {
2747
+ const joinedShapes = __spreadProps$8(__spreadValues$h({}, joinTo.q.joinedShapes), {
2703
2748
  [joinTo.q.as || joinTo.table]: joinTo.shape
2704
2749
  });
2705
2750
  const r = args0(
2706
2751
  makeJoinQueryBuilder(
2707
2752
  q,
2708
- q.q.joinedShapes ? __spreadValues$g(__spreadValues$g({}, q.q.joinedShapes), joinedShapes) : joinedShapes,
2753
+ q.q.joinedShapes ? __spreadValues$h(__spreadValues$h({}, q.q.joinedShapes), joinedShapes) : joinedShapes,
2709
2754
  joinTo
2710
2755
  )
2711
2756
  );
@@ -2753,25 +2798,25 @@ const _queryNone = (q) => {
2753
2798
  };
2754
2799
  const isQueryNone = (q) => q.then === noneMethods.then;
2755
2800
 
2756
- var __defProp$f = Object.defineProperty;
2757
- var __defProps$5 = Object.defineProperties;
2758
- var __getOwnPropDescs$5 = Object.getOwnPropertyDescriptors;
2759
- var __getOwnPropSymbols$g = Object.getOwnPropertySymbols;
2760
- var __hasOwnProp$g = Object.prototype.hasOwnProperty;
2761
- var __propIsEnum$g = Object.prototype.propertyIsEnumerable;
2762
- var __defNormalProp$f = (obj, key, value) => key in obj ? __defProp$f(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2763
- var __spreadValues$f = (a, b) => {
2801
+ var __defProp$g = Object.defineProperty;
2802
+ var __defProps$7 = Object.defineProperties;
2803
+ var __getOwnPropDescs$7 = Object.getOwnPropertyDescriptors;
2804
+ var __getOwnPropSymbols$h = Object.getOwnPropertySymbols;
2805
+ var __hasOwnProp$h = Object.prototype.hasOwnProperty;
2806
+ var __propIsEnum$h = Object.prototype.propertyIsEnumerable;
2807
+ var __defNormalProp$g = (obj, key, value) => key in obj ? __defProp$g(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2808
+ var __spreadValues$g = (a, b) => {
2764
2809
  for (var prop in b || (b = {}))
2765
- if (__hasOwnProp$g.call(b, prop))
2766
- __defNormalProp$f(a, prop, b[prop]);
2767
- if (__getOwnPropSymbols$g)
2768
- for (var prop of __getOwnPropSymbols$g(b)) {
2769
- if (__propIsEnum$g.call(b, prop))
2770
- __defNormalProp$f(a, prop, b[prop]);
2810
+ if (__hasOwnProp$h.call(b, prop))
2811
+ __defNormalProp$g(a, prop, b[prop]);
2812
+ if (__getOwnPropSymbols$h)
2813
+ for (var prop of __getOwnPropSymbols$h(b)) {
2814
+ if (__propIsEnum$h.call(b, prop))
2815
+ __defNormalProp$g(a, prop, b[prop]);
2771
2816
  }
2772
2817
  return a;
2773
2818
  };
2774
- var __spreadProps$5 = (a, b) => __defProps$5(a, __getOwnPropDescs$5(b));
2819
+ var __spreadProps$7 = (a, b) => __defProps$7(a, __getOwnPropDescs$7(b));
2775
2820
  const _join = (query, require2, type, first, args) => {
2776
2821
  var _a, _b, _c, _d;
2777
2822
  let joinKey;
@@ -2816,7 +2861,7 @@ const _join = (query, require2, type, first, args) => {
2816
2861
  computeds = w == null ? void 0 : w.computeds;
2817
2862
  if (shape) {
2818
2863
  if (!require2)
2819
- shape = __spreadValues$f({}, shape);
2864
+ shape = __spreadValues$g({}, shape);
2820
2865
  parsers = {};
2821
2866
  for (const key in shape) {
2822
2867
  const parser = shape[key].parseFn;
@@ -2916,7 +2961,7 @@ const _joinLateral = (self, type, arg, cb, as) => {
2916
2961
  t.table = arg;
2917
2962
  t.shape = w.shape;
2918
2963
  t.computeds = w.computeds;
2919
- t.q = __spreadProps$5(__spreadValues$f({}, t.q), {
2964
+ t.q = __spreadProps$7(__spreadValues$g({}, t.q), {
2920
2965
  shape: w.shape
2921
2966
  });
2922
2967
  t.baseQuery = t;
@@ -3235,12 +3280,46 @@ class QueryLog {
3235
3280
  }
3236
3281
  }
3237
3282
 
3283
+ var __defProp$f = Object.defineProperty;
3284
+ var __defProps$6 = Object.defineProperties;
3285
+ var __getOwnPropDescs$6 = Object.getOwnPropertyDescriptors;
3286
+ var __getOwnPropSymbols$g = Object.getOwnPropertySymbols;
3287
+ var __hasOwnProp$g = Object.prototype.hasOwnProperty;
3288
+ var __propIsEnum$g = Object.prototype.propertyIsEnumerable;
3289
+ var __defNormalProp$f = (obj, key, value) => key in obj ? __defProp$f(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3290
+ var __spreadValues$f = (a, b) => {
3291
+ for (var prop in b || (b = {}))
3292
+ if (__hasOwnProp$g.call(b, prop))
3293
+ __defNormalProp$f(a, prop, b[prop]);
3294
+ if (__getOwnPropSymbols$g)
3295
+ for (var prop of __getOwnPropSymbols$g(b)) {
3296
+ if (__propIsEnum$g.call(b, prop))
3297
+ __defNormalProp$f(a, prop, b[prop]);
3298
+ }
3299
+ return a;
3300
+ };
3301
+ var __spreadProps$6 = (a, b) => __defProps$6(a, __getOwnPropDescs$6(b));
3238
3302
  const commitSql$1 = {
3239
3303
  text: "COMMIT"
3240
3304
  };
3241
3305
  const rollbackSql$1 = {
3242
3306
  text: "ROLLBACK"
3243
3307
  };
3308
+ class AfterCommitError extends OrchidOrmError {
3309
+ constructor(result, hookResults) {
3310
+ super("After commit hooks have failed");
3311
+ this.result = result;
3312
+ this.hookResults = hookResults;
3313
+ }
3314
+ }
3315
+ const _afterCommitError = (result, hookResults, catchAfterCommitError) => {
3316
+ const err = new AfterCommitError(result, hookResults);
3317
+ if (catchAfterCommitError) {
3318
+ catchAfterCommitError(err);
3319
+ } else {
3320
+ throw err;
3321
+ }
3322
+ };
3244
3323
  class Transaction {
3245
3324
  async transaction(cbOrOptions, cb) {
3246
3325
  var _a;
@@ -3286,7 +3365,10 @@ class Transaction {
3286
3365
  const result = await this.q.adapter.transaction(sql, callback);
3287
3366
  if (log)
3288
3367
  log.afterQuery(commitSql$1, logData);
3289
- await runAfterCommit(trx.afterCommit);
3368
+ await runAfterCommit(
3369
+ trx.afterCommit,
3370
+ result
3371
+ );
3290
3372
  return result;
3291
3373
  } catch (err) {
3292
3374
  if (log)
@@ -3320,7 +3402,8 @@ class Transaction {
3320
3402
  log.afterQuery(sql, logData);
3321
3403
  if (transactionId === trx.testTransactionCount) {
3322
3404
  await runAfterCommit(
3323
- trx.afterCommit
3405
+ trx.afterCommit,
3406
+ result
3324
3407
  );
3325
3408
  }
3326
3409
  return result;
@@ -3330,17 +3413,37 @@ class Transaction {
3330
3413
  }
3331
3414
  }
3332
3415
  }
3333
- const runAfterCommit = async (afterCommit) => {
3416
+ const runAfterCommit = async (afterCommit, result) => {
3334
3417
  if (afterCommit) {
3335
3418
  const promises = [];
3419
+ let catchAfterCommitError;
3336
3420
  for (let i = 0, len = afterCommit.length; i < len; i += 3) {
3337
- const result = afterCommit[i];
3421
+ const result2 = afterCommit[i];
3338
3422
  const q = afterCommit[i + 1];
3423
+ if (q.q.catchAfterCommitError) {
3424
+ catchAfterCommitError = q.q.catchAfterCommitError;
3425
+ }
3339
3426
  for (const fn of afterCommit[i + 2]) {
3340
- promises.push(fn(result, q));
3427
+ try {
3428
+ promises.push(fn(result2, q));
3429
+ } catch (err) {
3430
+ promises.push(Promise.reject(err));
3431
+ }
3341
3432
  }
3342
3433
  }
3343
- await Promise.all(promises);
3434
+ const hookResults = await Promise.allSettled(promises);
3435
+ if (hookResults.some((result2) => result2.status === "rejected")) {
3436
+ const resultsWithNames = [];
3437
+ let r = 0;
3438
+ for (let i = 0, len = afterCommit.length; i < len; i += 3) {
3439
+ for (const fn of afterCommit[i + 2]) {
3440
+ resultsWithNames.push(__spreadProps$6(__spreadValues$f({}, hookResults[r++]), {
3441
+ name: fn.name
3442
+ }));
3443
+ }
3444
+ }
3445
+ _afterCommitError(result, resultsWithNames, catchAfterCommitError);
3446
+ }
3344
3447
  }
3345
3448
  };
3346
3449
 
@@ -3397,8 +3500,8 @@ const finalizeNestedHookSelect = (batches, returnType, tempColumns, renames, key
3397
3500
  };
3398
3501
 
3399
3502
  var __defProp$e = Object.defineProperty;
3400
- var __defProps$4 = Object.defineProperties;
3401
- var __getOwnPropDescs$4 = Object.getOwnPropertyDescriptors;
3503
+ var __defProps$5 = Object.defineProperties;
3504
+ var __getOwnPropDescs$5 = Object.getOwnPropertyDescriptors;
3402
3505
  var __getOwnPropSymbols$f = Object.getOwnPropertySymbols;
3403
3506
  var __hasOwnProp$f = Object.prototype.hasOwnProperty;
3404
3507
  var __propIsEnum$f = Object.prototype.propertyIsEnumerable;
@@ -3414,7 +3517,7 @@ var __spreadValues$e = (a, b) => {
3414
3517
  }
3415
3518
  return a;
3416
3519
  };
3417
- var __spreadProps$4 = (a, b) => __defProps$4(a, __getOwnPropDescs$4(b));
3520
+ var __spreadProps$5 = (a, b) => __defProps$5(a, __getOwnPropDescs$5(b));
3418
3521
  class ComputedColumn {
3419
3522
  constructor(kind, deps, fn) {
3420
3523
  this.kind = kind;
@@ -3431,7 +3534,7 @@ const applyComputedColumns = (q, fn) => {
3431
3534
  for (const key in computed) {
3432
3535
  const item = computed[key];
3433
3536
  if (item instanceof ComputedColumn) {
3434
- q.q.computeds = __spreadProps$4(__spreadValues$e({}, q.q.computeds), { [key]: item });
3537
+ q.q.computeds = __spreadProps$5(__spreadValues$e({}, q.q.computeds), { [key]: item });
3435
3538
  } else {
3436
3539
  (q.shape[key] = item.result.value || UnknownColumn.instance).data.computed = item;
3437
3540
  }
@@ -3540,6 +3643,8 @@ const saveBatchComputed = (key, result, res, blanks) => {
3540
3643
  };
3541
3644
 
3542
3645
  var __defProp$d = Object.defineProperty;
3646
+ var __defProps$4 = Object.defineProperties;
3647
+ var __getOwnPropDescs$4 = Object.getOwnPropertyDescriptors;
3543
3648
  var __getOwnPropSymbols$e = Object.getOwnPropertySymbols;
3544
3649
  var __hasOwnProp$e = Object.prototype.hasOwnProperty;
3545
3650
  var __propIsEnum$e = Object.prototype.propertyIsEnumerable;
@@ -3555,6 +3660,7 @@ var __spreadValues$d = (a, b) => {
3555
3660
  }
3556
3661
  return a;
3557
3662
  };
3663
+ var __spreadProps$4 = (a, b) => __defProps$4(a, __getOwnPropDescs$4(b));
3558
3664
  const queryMethodByReturnType = {
3559
3665
  undefined: "query",
3560
3666
  all: "query",
@@ -3775,15 +3881,35 @@ const then = async (q, adapter, trx, beforeHooks, afterHooks, afterCommitHooks,
3775
3881
  )
3776
3882
  );
3777
3883
  }
3778
- if (afterCommitHooks && trx) {
3779
- ((_c = trx.afterCommit) != null ? _c : trx.afterCommit = []).push(
3780
- result,
3781
- q,
3782
- afterCommitHooks
3783
- );
3784
- } else if (afterCommitHooks) {
3785
- const args = [result, q];
3786
- await Promise.all(afterCommitHooks.map(callAfterHook, args));
3884
+ if (afterCommitHooks) {
3885
+ if (trx) {
3886
+ ((_c = trx.afterCommit) != null ? _c : trx.afterCommit = []).push(
3887
+ result,
3888
+ q,
3889
+ afterCommitHooks
3890
+ );
3891
+ } else {
3892
+ const promises = [];
3893
+ for (const fn of afterCommitHooks) {
3894
+ try {
3895
+ promises.push(
3896
+ fn(result, q)
3897
+ );
3898
+ } catch (err) {
3899
+ promises.push(Promise.reject(err));
3900
+ }
3901
+ }
3902
+ const hookResults = await Promise.allSettled(promises);
3903
+ if (hookResults.some((result2) => result2.status === "rejected")) {
3904
+ _afterCommitError(
3905
+ result,
3906
+ hookResults.map((result2, i) => __spreadProps$4(__spreadValues$d({}, result2), {
3907
+ name: afterCommitHooks[i].name
3908
+ })),
3909
+ q.q.catchAfterCommitError
3910
+ );
3911
+ }
3912
+ }
3787
3913
  }
3788
3914
  } else if (query.after) {
3789
3915
  const args = [result, q];
@@ -4849,13 +4975,21 @@ const selectToSql = (ctx, table, query, quotedAs, hookSelect = query.hookSelect)
4849
4975
  item,
4850
4976
  tableName,
4851
4977
  key,
4978
+ key === "*" ? tableName : key,
4852
4979
  quotedAs,
4853
4980
  true
4854
4981
  );
4855
4982
  } else {
4856
4983
  if (hookSelect == null ? void 0 : hookSelect.get(item))
4857
4984
  (selected != null ? selected : selected = {})[item] = quotedAs;
4858
- sql = ownColumnToSqlWithAs(ctx, table.q, item, quotedAs, true);
4985
+ sql = ownColumnToSqlWithAs(
4986
+ ctx,
4987
+ table.q,
4988
+ item,
4989
+ item,
4990
+ quotedAs,
4991
+ true
4992
+ );
4859
4993
  }
4860
4994
  }
4861
4995
  list.push(sql);
@@ -4874,14 +5008,14 @@ const selectToSql = (ctx, table, query, quotedAs, hookSelect = query.hookSelect)
4874
5008
  }
4875
5009
  } else if (value) {
4876
5010
  list.push(
4877
- `${columnToSql(
5011
+ columnToSqlWithAs(
4878
5012
  ctx,
4879
5013
  table.q,
4880
- table.q.shape,
4881
5014
  value,
5015
+ as,
4882
5016
  quotedAs,
4883
5017
  true
4884
- )} "${as}"`
5018
+ )
4885
5019
  );
4886
5020
  }
4887
5021
  }
@@ -4910,7 +5044,7 @@ const selectToSql = (ctx, table, query, quotedAs, hookSelect = query.hookSelect)
4910
5044
  quotedTable = quotedAs;
4911
5045
  columnName = select;
4912
5046
  col = query.shape[select];
4913
- sql = simpleColumnToSQL(ctx, select, col, quotedAs);
5047
+ sql = simpleColumnToSQL(ctx, query, select, col, quotedAs);
4914
5048
  }
4915
5049
  if (selected == null ? void 0 : selected[columnName]) {
4916
5050
  if ((selected == null ? void 0 : selected[columnName]) === quotedTable) {
@@ -8391,6 +8525,32 @@ class QueryHooks {
8391
8525
  cb
8392
8526
  );
8393
8527
  }
8528
+ /**
8529
+ * Add `catchAfterCommitError` to the query to catch possible errors that are coming from after commit hooks.
8530
+ *
8531
+ * When it is used, the transaction will return its result disregarding of a failed hook.
8532
+ *
8533
+ * Without `catchAfterCommitError`, the transaction function throws and won't return result.
8534
+ * Result is still accessible from the error object [AfterCommitError](#AfterCommitError).
8535
+ *
8536
+ * ```ts
8537
+ * const result = await db
8538
+ * .$transaction(async () => {
8539
+ * return db.table.create(data);
8540
+ * })
8541
+ * .catchAfterCommitError((err) => {
8542
+ * // err is instance of AfterCommitError (see below)
8543
+ * });
8544
+ *
8545
+ * // result is available even if an after commit hook has failed
8546
+ * result.id;
8547
+ * ```
8548
+ */
8549
+ catchAfterCommitError(fn) {
8550
+ const q = this.clone();
8551
+ q.q.catchAfterCommitError = fn;
8552
+ return q;
8553
+ }
8394
8554
  }
8395
8555
 
8396
8556
  class Join {
@@ -11379,6 +11539,8 @@ class ColumnRefExpression extends orchidCore.Expression {
11379
11539
  makeSQL(ctx, quotedAs) {
11380
11540
  return simpleExistingColumnToSQL(
11381
11541
  ctx,
11542
+ // it's for parsers for computed SQL. In the column ref case, parsers should be set when selecting the column ref.
11543
+ {},
11382
11544
  this.name,
11383
11545
  this.result.value,
11384
11546
  quotedAs
@@ -12844,6 +13006,7 @@ function copyTableData(query, arg) {
12844
13006
  }
12845
13007
 
12846
13008
  exports.Adapter = Adapter;
13009
+ exports.AfterCommitError = AfterCommitError;
12847
13010
  exports.AggregateMethods = AggregateMethods;
12848
13011
  exports.ArrayColumn = ArrayColumn;
12849
13012
  exports.AsMethods = AsMethods;
@@ -12945,6 +13108,7 @@ exports.VirtualColumn = VirtualColumn;
12945
13108
  exports.Where = Where;
12946
13109
  exports.WithMethods = WithMethods;
12947
13110
  exports.XMLColumn = XMLColumn;
13111
+ exports._afterCommitError = _afterCommitError;
12948
13112
  exports._getSelectableColumn = _getSelectableColumn;
12949
13113
  exports._initQueryBuilder = _initQueryBuilder;
12950
13114
  exports._queryAfterSaveCommit = _queryAfterSaveCommit;