pqb 0.34.0 → 0.35.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { ExpressionTypeMethod, Expression, RawSQLBase, emptyObject, isTemplateLiteralArgs, ColumnTypeBase, setColumnData, pushColumnData, quoteObjectKey, toArray, singleQuote, addCode, singleQuoteArray, objectHasValues, columnDefaultArgumentToCode, columnErrorMessagesToCode, getValueKey, addValue, isExpression, joinTruthy, numberDataToCode, stringDataToCode, getDefaultLanguage, dateDataToCode, pushOrNewArrayToObject, returnArg as returnArg$1, noop, arrayDataToCode, emptyArray, callWithThis, applyTransforms, setParserToQuery, isRawSQL, pushOrNewArray, setDefaultNowFn, setDefaultLanguage, makeTimestampsHelpers, setCurrentColumnName, setAdapterConnectRetry, isObjectEmpty, ValExpression, applyMixins, toSnakeCase, snakeCaseKey } from 'orchid-core';
1
+ import { ExpressionTypeMethod, Expression, RawSQLBase, emptyObject, isTemplateLiteralArgs, ColumnTypeBase, setColumnData, pushColumnData, quoteObjectKey, toArray, singleQuote, addCode, singleQuoteArray, objectHasValues, columnDefaultArgumentToCode, columnErrorMessagesToCode, getValueKey, addValue, isExpression, joinTruthy, numberDataToCode, stringDataToCode, getDefaultLanguage, dateDataToCode, pushOrNewArrayToObject, returnArg as returnArg$1, noop, arrayDataToCode, emptyArray, applyTransforms, callWithThis, setParserToQuery, isRawSQL, pushOrNewArray, setDefaultNowFn, setDefaultLanguage, makeTimestampsHelpers, setCurrentColumnName, setAdapterConnectRetry, isObjectEmpty, ValExpression, applyMixins, toSnakeCase, snakeCaseKey } from 'orchid-core';
2
2
  import pg from 'pg';
3
3
  import { inspect } from 'node:util';
4
4
  import { AsyncLocalStorage } from 'node:async_hooks';
@@ -88,7 +88,7 @@ class DynamicRawSQL extends Expression {
88
88
  super();
89
89
  this.fn = fn;
90
90
  this.result = emptyObject;
91
- this.q = {};
91
+ this.q = { expr: this };
92
92
  }
93
93
  // Calls the given function to get SQL from it.
94
94
  makeSQL(ctx, quotedAs) {
@@ -117,25 +117,25 @@ const sqlFn = (...args) => {
117
117
  return (...args2) => new RawSQL(args2, arg);
118
118
  };
119
119
 
120
- var __defProp$h = Object.defineProperty;
121
- var __defProps$9 = Object.defineProperties;
122
- var __getOwnPropDescs$9 = Object.getOwnPropertyDescriptors;
123
- var __getOwnPropSymbols$i = Object.getOwnPropertySymbols;
124
- var __hasOwnProp$i = Object.prototype.hasOwnProperty;
125
- var __propIsEnum$i = Object.prototype.propertyIsEnumerable;
126
- var __defNormalProp$h = (obj, key, value) => key in obj ? __defProp$h(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
127
- var __spreadValues$h = (a, b) => {
120
+ var __defProp$l = Object.defineProperty;
121
+ var __defProps$b = Object.defineProperties;
122
+ var __getOwnPropDescs$b = Object.getOwnPropertyDescriptors;
123
+ var __getOwnPropSymbols$m = Object.getOwnPropertySymbols;
124
+ var __hasOwnProp$m = Object.prototype.hasOwnProperty;
125
+ var __propIsEnum$m = Object.prototype.propertyIsEnumerable;
126
+ var __defNormalProp$l = (obj, key, value) => key in obj ? __defProp$l(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
127
+ var __spreadValues$l = (a, b) => {
128
128
  for (var prop in b || (b = {}))
129
- if (__hasOwnProp$i.call(b, prop))
130
- __defNormalProp$h(a, prop, b[prop]);
131
- if (__getOwnPropSymbols$i)
132
- for (var prop of __getOwnPropSymbols$i(b)) {
133
- if (__propIsEnum$i.call(b, prop))
134
- __defNormalProp$h(a, prop, b[prop]);
129
+ if (__hasOwnProp$m.call(b, prop))
130
+ __defNormalProp$l(a, prop, b[prop]);
131
+ if (__getOwnPropSymbols$m)
132
+ for (var prop of __getOwnPropSymbols$m(b)) {
133
+ if (__propIsEnum$m.call(b, prop))
134
+ __defNormalProp$l(a, prop, b[prop]);
135
135
  }
136
136
  return a;
137
137
  };
138
- var __spreadProps$9 = (a, b) => __defProps$9(a, __getOwnPropDescs$9(b));
138
+ var __spreadProps$b = (a, b) => __defProps$b(a, __getOwnPropDescs$b(b));
139
139
  class ColumnType extends ColumnTypeBase {
140
140
  /**
141
141
  * Mark the column as a primary key.
@@ -334,13 +334,13 @@ class ColumnType extends ColumnTypeBase {
334
334
  */
335
335
  searchIndex(...args) {
336
336
  return pushColumnData(this, "indexes", {
337
- options: __spreadValues$h(__spreadValues$h({}, typeof args[0] === "string" ? args[1] : args[0]), this.dataType === "tsvector" ? { using: "GIN" } : { tsVector: true }),
337
+ options: __spreadValues$l(__spreadValues$l({}, typeof args[0] === "string" ? args[1] : args[0]), this.dataType === "tsvector" ? { using: "GIN" } : { tsVector: true }),
338
338
  name: typeof args[0] === "string" ? args[0] : void 0
339
339
  });
340
340
  }
341
341
  unique(...args) {
342
342
  return pushColumnData(this, "indexes", {
343
- options: __spreadProps$9(__spreadValues$h({}, typeof args[0] === "string" ? args[1] : args[0]), {
343
+ options: __spreadProps$b(__spreadValues$l({}, typeof args[0] === "string" ? args[1] : args[0]), {
344
344
  unique: true
345
345
  }),
346
346
  name: typeof args[0] === "string" ? args[0] : void 0
@@ -382,25 +382,25 @@ class ColumnType extends ColumnTypeBase {
382
382
  }
383
383
  }
384
384
 
385
- var __defProp$g = Object.defineProperty;
386
- var __defProps$8 = Object.defineProperties;
387
- var __getOwnPropDescs$8 = Object.getOwnPropertyDescriptors;
388
- var __getOwnPropSymbols$h = Object.getOwnPropertySymbols;
389
- var __hasOwnProp$h = Object.prototype.hasOwnProperty;
390
- var __propIsEnum$h = Object.prototype.propertyIsEnumerable;
391
- var __defNormalProp$g = (obj, key, value) => key in obj ? __defProp$g(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
392
- var __spreadValues$g = (a, b) => {
385
+ var __defProp$k = Object.defineProperty;
386
+ var __defProps$a = Object.defineProperties;
387
+ var __getOwnPropDescs$a = Object.getOwnPropertyDescriptors;
388
+ var __getOwnPropSymbols$l = Object.getOwnPropertySymbols;
389
+ var __hasOwnProp$l = Object.prototype.hasOwnProperty;
390
+ var __propIsEnum$l = Object.prototype.propertyIsEnumerable;
391
+ var __defNormalProp$k = (obj, key, value) => key in obj ? __defProp$k(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
392
+ var __spreadValues$k = (a, b) => {
393
393
  for (var prop in b || (b = {}))
394
- if (__hasOwnProp$h.call(b, prop))
395
- __defNormalProp$g(a, prop, b[prop]);
396
- if (__getOwnPropSymbols$h)
397
- for (var prop of __getOwnPropSymbols$h(b)) {
398
- if (__propIsEnum$h.call(b, prop))
399
- __defNormalProp$g(a, prop, b[prop]);
394
+ if (__hasOwnProp$l.call(b, prop))
395
+ __defNormalProp$k(a, prop, b[prop]);
396
+ if (__getOwnPropSymbols$l)
397
+ for (var prop of __getOwnPropSymbols$l(b)) {
398
+ if (__propIsEnum$l.call(b, prop))
399
+ __defNormalProp$k(a, prop, b[prop]);
400
400
  }
401
401
  return a;
402
402
  };
403
- var __spreadProps$8 = (a, b) => __defProps$8(a, __getOwnPropDescs$8(b));
403
+ var __spreadProps$a = (a, b) => __defProps$a(a, __getOwnPropDescs$a(b));
404
404
  const knownDefaults = {
405
405
  current_timestamp: "now()",
406
406
  "transaction_timestamp()": "now()"
@@ -416,7 +416,7 @@ const simplifyColumnDefault = (value) => {
416
416
  const instantiateColumn = (typeFn, params) => {
417
417
  const column = typeFn();
418
418
  const { dateTimePrecision } = params;
419
- Object.assign(column.data, __spreadProps$8(__spreadValues$g({}, params), {
419
+ Object.assign(column.data, __spreadProps$a(__spreadValues$k({}, params), {
420
420
  dateTimePrecision: (
421
421
  // 0 is default for date, 6 is default for timestamp
422
422
  dateTimePrecision && dateTimePrecision !== 6 ? dateTimePrecision : void 0
@@ -840,25 +840,25 @@ const getSqlText = (sql) => {
840
840
  throw new Error(`Batch SQL is not supported in this query`);
841
841
  };
842
842
 
843
- var __defProp$f = Object.defineProperty;
844
- var __defProps$7 = Object.defineProperties;
845
- var __getOwnPropDescs$7 = Object.getOwnPropertyDescriptors;
846
- var __getOwnPropSymbols$g = Object.getOwnPropertySymbols;
847
- var __hasOwnProp$g = Object.prototype.hasOwnProperty;
848
- var __propIsEnum$g = Object.prototype.propertyIsEnumerable;
849
- var __defNormalProp$f = (obj, key, value) => key in obj ? __defProp$f(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
850
- var __spreadValues$f = (a, b) => {
843
+ var __defProp$j = Object.defineProperty;
844
+ var __defProps$9 = Object.defineProperties;
845
+ var __getOwnPropDescs$9 = Object.getOwnPropertyDescriptors;
846
+ var __getOwnPropSymbols$k = Object.getOwnPropertySymbols;
847
+ var __hasOwnProp$k = Object.prototype.hasOwnProperty;
848
+ var __propIsEnum$k = Object.prototype.propertyIsEnumerable;
849
+ var __defNormalProp$j = (obj, key, value) => key in obj ? __defProp$j(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
850
+ var __spreadValues$j = (a, b) => {
851
851
  for (var prop in b || (b = {}))
852
- if (__hasOwnProp$g.call(b, prop))
853
- __defNormalProp$f(a, prop, b[prop]);
854
- if (__getOwnPropSymbols$g)
855
- for (var prop of __getOwnPropSymbols$g(b)) {
856
- if (__propIsEnum$g.call(b, prop))
857
- __defNormalProp$f(a, prop, b[prop]);
852
+ if (__hasOwnProp$k.call(b, prop))
853
+ __defNormalProp$j(a, prop, b[prop]);
854
+ if (__getOwnPropSymbols$k)
855
+ for (var prop of __getOwnPropSymbols$k(b)) {
856
+ if (__propIsEnum$k.call(b, prop))
857
+ __defNormalProp$j(a, prop, b[prop]);
858
858
  }
859
859
  return a;
860
860
  };
861
- var __spreadProps$7 = (a, b) => __defProps$7(a, __getOwnPropDescs$7(b));
861
+ var __spreadProps$9 = (a, b) => __defProps$9(a, __getOwnPropDescs$9(b));
862
862
  function setQueryOperators(query, operators) {
863
863
  const q = query.q;
864
864
  if (q.operators !== operators) {
@@ -931,7 +931,7 @@ const base = {
931
931
  (key, value, ctx, quotedAs) => `NOT ${key} IN ${quoteValue$1(value, ctx, quotedAs)}`
932
932
  )
933
933
  };
934
- const boolean = __spreadProps$7(__spreadValues$f({}, base), {
934
+ const boolean = __spreadProps$9(__spreadValues$j({}, base), {
935
935
  and: make(
936
936
  (key, value, ctx, quotedAs) => `${key} AND ${value.q.expr.toSQL(ctx, quotedAs)}`
937
937
  ),
@@ -939,7 +939,7 @@ const boolean = __spreadProps$7(__spreadValues$f({}, base), {
939
939
  (key, value, ctx, quotedAs) => `(${key}) OR (${value.q.expr.toSQL(ctx, quotedAs)})`
940
940
  )
941
941
  });
942
- const numeric = __spreadProps$7(__spreadValues$f({}, base), {
942
+ const numeric = __spreadProps$9(__spreadValues$j({}, base), {
943
943
  lt: make(
944
944
  (key, value, ctx, quotedAs) => `${key} < ${quoteValue$1(value, ctx, quotedAs)}`
945
945
  ),
@@ -960,7 +960,7 @@ const numeric = __spreadProps$7(__spreadValues$f({}, base), {
960
960
  )}`
961
961
  )
962
962
  });
963
- const text = __spreadProps$7(__spreadValues$f({}, base), {
963
+ const text = __spreadProps$9(__spreadValues$j({}, base), {
964
964
  contains: make(
965
965
  (key, value, ctx, quotedAs) => `${key} ILIKE '%' || ${quoteValue$1(value, ctx, quotedAs)} || '%'`
966
966
  ),
@@ -982,7 +982,7 @@ const text = __spreadProps$7(__spreadValues$f({}, base), {
982
982
  });
983
983
  const encodeJsonPath = (ctx, path) => addValue(ctx.values, `{${Array.isArray(path) ? path.join(", ") : path}}`);
984
984
  const jsonPathQueryOp = (key, [path, options], ctx) => `jsonb_path_query_first(${key}, ${addValue(ctx.values, path)}${(options == null ? void 0 : options.vars) ? `, ${addValue(ctx.values, JSON.stringify(options.vars))}${options.silent ? ", true" : ""}` : (options == null ? void 0 : options.silent) ? ", NULL, true" : ""})`;
985
- const json = __spreadProps$7(__spreadValues$f({}, base), {
985
+ const json = __spreadProps$9(__spreadValues$j({}, base), {
986
986
  jsonPathQueryFirst: Object.assign(
987
987
  function(path, options) {
988
988
  var _a, _b, _c, _d, _e;
@@ -1209,25 +1209,25 @@ class BigSerialColumn extends NumberAsStringBaseColumn {
1209
1209
  }
1210
1210
  }
1211
1211
 
1212
- var __defProp$e = Object.defineProperty;
1213
- var __defProps$6 = Object.defineProperties;
1214
- var __getOwnPropDescs$6 = Object.getOwnPropertyDescriptors;
1215
- var __getOwnPropSymbols$f = Object.getOwnPropertySymbols;
1216
- var __hasOwnProp$f = Object.prototype.hasOwnProperty;
1217
- var __propIsEnum$f = Object.prototype.propertyIsEnumerable;
1218
- var __defNormalProp$e = (obj, key, value) => key in obj ? __defProp$e(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1219
- var __spreadValues$e = (a, b) => {
1212
+ var __defProp$i = Object.defineProperty;
1213
+ var __defProps$8 = Object.defineProperties;
1214
+ var __getOwnPropDescs$8 = Object.getOwnPropertyDescriptors;
1215
+ var __getOwnPropSymbols$j = Object.getOwnPropertySymbols;
1216
+ var __hasOwnProp$j = Object.prototype.hasOwnProperty;
1217
+ var __propIsEnum$j = Object.prototype.propertyIsEnumerable;
1218
+ var __defNormalProp$i = (obj, key, value) => key in obj ? __defProp$i(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1219
+ var __spreadValues$i = (a, b) => {
1220
1220
  for (var prop in b || (b = {}))
1221
- if (__hasOwnProp$f.call(b, prop))
1222
- __defNormalProp$e(a, prop, b[prop]);
1223
- if (__getOwnPropSymbols$f)
1224
- for (var prop of __getOwnPropSymbols$f(b)) {
1225
- if (__propIsEnum$f.call(b, prop))
1226
- __defNormalProp$e(a, prop, b[prop]);
1221
+ if (__hasOwnProp$j.call(b, prop))
1222
+ __defNormalProp$i(a, prop, b[prop]);
1223
+ if (__getOwnPropSymbols$j)
1224
+ for (var prop of __getOwnPropSymbols$j(b)) {
1225
+ if (__propIsEnum$j.call(b, prop))
1226
+ __defNormalProp$i(a, prop, b[prop]);
1227
1227
  }
1228
1228
  return a;
1229
1229
  };
1230
- var __spreadProps$6 = (a, b) => __defProps$6(a, __getOwnPropDescs$6(b));
1230
+ var __spreadProps$8 = (a, b) => __defProps$8(a, __getOwnPropDescs$8(b));
1231
1231
  class TextBaseColumn extends ColumnType {
1232
1232
  constructor(schema, schemaType = schema.stringSchema()) {
1233
1233
  super(schema, schemaType);
@@ -1275,7 +1275,7 @@ class StringColumn extends VarCharColumn {
1275
1275
  }
1276
1276
  }
1277
1277
  const textColumnToCode = (column, t, m) => {
1278
- const data = __spreadValues$e({}, column.data);
1278
+ const data = __spreadValues$i({}, column.data);
1279
1279
  let args = "";
1280
1280
  const hasMax = data.maxArg !== void 0 && data.max === data.maxArg;
1281
1281
  if (data.minArg !== void 0 && data.min === data.minArg || hasMax) {
@@ -1572,7 +1572,7 @@ class UUIDColumn extends ColumnType {
1572
1572
  `uuid()`,
1573
1573
  m,
1574
1574
  // don't output the default default
1575
- data.default instanceof RawSQLBase && data.default._sql === uuidDefaultSQL ? __spreadProps$6(__spreadValues$e({}, data), { default: void 0 }) : data
1575
+ data.default instanceof RawSQLBase && data.default._sql === uuidDefaultSQL ? __spreadProps$8(__spreadValues$i({}, data), { default: void 0 }) : data
1576
1576
  );
1577
1577
  }
1578
1578
  }
@@ -1868,31 +1868,41 @@ const columnWithDotToSql = (ctx, data, shape, column, index, quotedAs, select) =
1868
1868
  return `"${tableName}"."${key}"`;
1869
1869
  };
1870
1870
  const columnToSqlWithAs = (ctx, data, column, quotedAs, select) => {
1871
- var _a, _b, _c, _d;
1872
1871
  const index = column.indexOf(".");
1873
- if (index !== -1) {
1874
- const table = column.slice(0, index);
1875
- const key = column.slice(index + 1);
1876
- if (key === "*") {
1877
- if ((_a = data.joinedShapes) == null ? void 0 : _a[table]) {
1878
- return select ? `row_to_json("${table}".*) "${table}"` : `"${table}".r "${table}"`;
1879
- }
1880
- return column;
1872
+ return index !== -1 ? tableColumnToSqlWithAs(
1873
+ ctx,
1874
+ data,
1875
+ column,
1876
+ column.slice(0, index),
1877
+ column.slice(index + 1),
1878
+ quotedAs,
1879
+ select
1880
+ ) : ownColumnToSqlWithAs(ctx, data, column, quotedAs, select);
1881
+ };
1882
+ const tableColumnToSqlWithAs = (ctx, data, column, table, key, quotedAs, select) => {
1883
+ var _a, _b, _c;
1884
+ if (key === "*") {
1885
+ if ((_a = data.joinedShapes) == null ? void 0 : _a[table]) {
1886
+ return select ? `row_to_json("${table}".*) "${table}"` : `"${table}".r "${table}"`;
1881
1887
  }
1882
- const tableName = ((_b = data.joinOverrides) == null ? void 0 : _b[table]) || table;
1883
- const quoted = `"${table}"`;
1884
- const col2 = quoted === quotedAs ? data.shape[key] : (_c = data.joinedShapes) == null ? void 0 : _c[tableName][key];
1885
- if (col2) {
1886
- if (col2.data.name && col2.data.name !== key) {
1887
- return `"${tableName}"."${col2.data.name}" "${key}"`;
1888
- }
1889
- if (col2.data.computed) {
1890
- return `${col2.data.computed.toSQL(ctx, quoted)} "${key}"`;
1891
- }
1888
+ return column;
1889
+ }
1890
+ const tableName = ((_b = data.joinOverrides) == null ? void 0 : _b[table]) || table;
1891
+ const quoted = `"${table}"`;
1892
+ const col = quoted === quotedAs ? data.shape[key] : (_c = data.joinedShapes) == null ? void 0 : _c[tableName][key];
1893
+ if (col) {
1894
+ if (col.data.name && col.data.name !== key) {
1895
+ return `"${tableName}"."${col.data.name}" "${key}"`;
1896
+ }
1897
+ if (col.data.computed) {
1898
+ return `${col.data.computed.toSQL(ctx, quoted)} "${key}"`;
1892
1899
  }
1893
- return `"${tableName}"."${key}"`;
1894
1900
  }
1895
- if (!select && ((_d = data.joinedShapes) == null ? void 0 : _d[column])) {
1901
+ return `"${tableName}"."${key}"`;
1902
+ };
1903
+ const ownColumnToSqlWithAs = (ctx, data, column, quotedAs, select) => {
1904
+ var _a;
1905
+ if (!select && ((_a = data.joinedShapes) == null ? void 0 : _a[column])) {
1896
1906
  return select ? `row_to_json("${column}".*) "${column}"` : `"${column}".r "${column}"`;
1897
1907
  }
1898
1908
  const col = data.shape[column];
@@ -1906,11 +1916,6 @@ const columnToSqlWithAs = (ctx, data, column, quotedAs, select) => {
1906
1916
  }
1907
1917
  return `${quotedAs ? `${quotedAs}.` : ""}"${column}"`;
1908
1918
  };
1909
- const ownColumnToSql = (data, column, quotedAs) => {
1910
- var _a;
1911
- const name = (_a = data.shape[column]) == null ? void 0 : _a.data.name;
1912
- return `${quotedAs ? `${quotedAs}.` : ""}"${name || column}"${name && name !== column ? ` "${column}"` : ""}`;
1913
- };
1914
1919
  const rawOrColumnToSql = (ctx, data, expr, quotedAs, shape = data.shape, select) => {
1915
1920
  return typeof expr === "string" ? columnToSql(ctx, data, shape, expr, quotedAs, select) : expr.toSQL(ctx, quotedAs);
1916
1921
  };
@@ -2312,25 +2317,25 @@ const pushIn = (ctx, query, ands, quotedAs, arg) => {
2312
2317
  ands.push(`${multiple ? `(${columnsSql})` : columnsSql} IN ${value}`);
2313
2318
  };
2314
2319
 
2315
- var __defProp$d = Object.defineProperty;
2316
- var __defProps$5 = Object.defineProperties;
2317
- var __getOwnPropDescs$5 = Object.getOwnPropertyDescriptors;
2318
- var __getOwnPropSymbols$e = Object.getOwnPropertySymbols;
2319
- var __hasOwnProp$e = Object.prototype.hasOwnProperty;
2320
- var __propIsEnum$e = Object.prototype.propertyIsEnumerable;
2321
- var __defNormalProp$d = (obj, key, value) => key in obj ? __defProp$d(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2322
- var __spreadValues$d = (a, b) => {
2320
+ var __defProp$h = Object.defineProperty;
2321
+ var __defProps$7 = Object.defineProperties;
2322
+ var __getOwnPropDescs$7 = Object.getOwnPropertyDescriptors;
2323
+ var __getOwnPropSymbols$i = Object.getOwnPropertySymbols;
2324
+ var __hasOwnProp$i = Object.prototype.hasOwnProperty;
2325
+ var __propIsEnum$i = Object.prototype.propertyIsEnumerable;
2326
+ var __defNormalProp$h = (obj, key, value) => key in obj ? __defProp$h(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2327
+ var __spreadValues$h = (a, b) => {
2323
2328
  for (var prop in b || (b = {}))
2324
- if (__hasOwnProp$e.call(b, prop))
2325
- __defNormalProp$d(a, prop, b[prop]);
2326
- if (__getOwnPropSymbols$e)
2327
- for (var prop of __getOwnPropSymbols$e(b)) {
2328
- if (__propIsEnum$e.call(b, prop))
2329
- __defNormalProp$d(a, prop, b[prop]);
2329
+ if (__hasOwnProp$i.call(b, prop))
2330
+ __defNormalProp$h(a, prop, b[prop]);
2331
+ if (__getOwnPropSymbols$i)
2332
+ for (var prop of __getOwnPropSymbols$i(b)) {
2333
+ if (__propIsEnum$i.call(b, prop))
2334
+ __defNormalProp$h(a, prop, b[prop]);
2330
2335
  }
2331
2336
  return a;
2332
2337
  };
2333
- var __spreadProps$5 = (a, b) => __defProps$5(a, __getOwnPropDescs$5(b));
2338
+ var __spreadProps$7 = (a, b) => __defProps$7(a, __getOwnPropDescs$7(b));
2334
2339
  const processJoinItem = (ctx, table, query, args, quotedAs) => {
2335
2340
  let target;
2336
2341
  let on;
@@ -2392,8 +2397,8 @@ const processJoinItem = (ctx, table, query, args, quotedAs) => {
2392
2397
  const whereSql = whereToSql(
2393
2398
  ctx,
2394
2399
  q,
2395
- __spreadProps$5(__spreadValues$d({}, q.q), {
2396
- joinedShapes: __spreadProps$5(__spreadValues$d(__spreadValues$d({}, query.joinedShapes), q.q.joinedShapes), {
2400
+ __spreadProps$7(__spreadValues$h({}, q.q), {
2401
+ joinedShapes: __spreadProps$7(__spreadValues$h(__spreadValues$h({}, query.joinedShapes), q.q.joinedShapes), {
2397
2402
  [table.q.as || table.table]: table.q.shape
2398
2403
  })
2399
2404
  }),
@@ -2540,25 +2545,25 @@ const getIsJoinSubQuery = (query) => {
2540
2545
  return false;
2541
2546
  };
2542
2547
 
2543
- var __defProp$c = Object.defineProperty;
2544
- var __defProps$4 = Object.defineProperties;
2545
- var __getOwnPropDescs$4 = Object.getOwnPropertyDescriptors;
2546
- var __getOwnPropSymbols$d = Object.getOwnPropertySymbols;
2547
- var __hasOwnProp$d = Object.prototype.hasOwnProperty;
2548
- var __propIsEnum$d = Object.prototype.propertyIsEnumerable;
2549
- var __defNormalProp$c = (obj, key, value) => key in obj ? __defProp$c(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2550
- var __spreadValues$c = (a, b) => {
2548
+ var __defProp$g = Object.defineProperty;
2549
+ var __defProps$6 = Object.defineProperties;
2550
+ var __getOwnPropDescs$6 = Object.getOwnPropertyDescriptors;
2551
+ var __getOwnPropSymbols$h = Object.getOwnPropertySymbols;
2552
+ var __hasOwnProp$h = Object.prototype.hasOwnProperty;
2553
+ var __propIsEnum$h = Object.prototype.propertyIsEnumerable;
2554
+ var __defNormalProp$g = (obj, key, value) => key in obj ? __defProp$g(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2555
+ var __spreadValues$g = (a, b) => {
2551
2556
  for (var prop in b || (b = {}))
2552
- if (__hasOwnProp$d.call(b, prop))
2553
- __defNormalProp$c(a, prop, b[prop]);
2554
- if (__getOwnPropSymbols$d)
2555
- for (var prop of __getOwnPropSymbols$d(b)) {
2556
- if (__propIsEnum$d.call(b, prop))
2557
- __defNormalProp$c(a, prop, b[prop]);
2557
+ if (__hasOwnProp$h.call(b, prop))
2558
+ __defNormalProp$g(a, prop, b[prop]);
2559
+ if (__getOwnPropSymbols$h)
2560
+ for (var prop of __getOwnPropSymbols$h(b)) {
2561
+ if (__propIsEnum$h.call(b, prop))
2562
+ __defNormalProp$g(a, prop, b[prop]);
2558
2563
  }
2559
2564
  return a;
2560
2565
  };
2561
- var __spreadProps$4 = (a, b) => __defProps$4(a, __getOwnPropDescs$4(b));
2566
+ var __spreadProps$6 = (a, b) => __defProps$6(a, __getOwnPropDescs$6(b));
2562
2567
  const processJoinArgs = (joinTo, first, args, joinSubQuery) => {
2563
2568
  var _a;
2564
2569
  if (typeof first === "string") {
@@ -2576,27 +2581,28 @@ const processJoinArgs = (joinTo, first, args, joinSubQuery) => {
2576
2581
  return { w: first, a: args };
2577
2582
  } else {
2578
2583
  const joinToQ = joinTo.q;
2579
- const shape = (_a = joinToQ.withShapes) == null ? void 0 : _a[first];
2580
- if (!shape) {
2581
- throw new Error("Cannot get shape of `with` statement");
2584
+ const w = (_a = joinToQ.withShapes) == null ? void 0 : _a[first];
2585
+ if (!w) {
2586
+ throw new Error("Cannot find a `with` statement");
2582
2587
  }
2583
2588
  const j = joinTo.queryBuilder.baseQuery.clone();
2584
2589
  j.table = first;
2585
2590
  j.q = {
2586
- shape,
2591
+ shape: w.shape,
2592
+ computeds: w.computeds,
2587
2593
  adapter: joinToQ.adapter,
2588
2594
  handleResult: joinToQ.handleResult,
2589
2595
  returnType: "all",
2590
2596
  logger: joinToQ.logger
2591
2597
  };
2592
2598
  j.baseQuery = j;
2593
- const joinedShapes = __spreadProps$4(__spreadValues$c({}, joinToQ.joinedShapes), {
2599
+ const joinedShapes = __spreadProps$6(__spreadValues$g({}, joinToQ.joinedShapes), {
2594
2600
  [joinToQ.as || joinTo.table]: joinTo.shape
2595
2601
  });
2596
2602
  const r = args[0](
2597
2603
  makeJoinQueryBuilder(
2598
2604
  j,
2599
- j.q.joinedShapes ? __spreadValues$c(__spreadValues$c({}, j.q.joinedShapes), joinedShapes) : joinedShapes,
2605
+ j.q.joinedShapes ? __spreadValues$g(__spreadValues$g({}, j.q.joinedShapes), joinedShapes) : joinedShapes,
2600
2606
  joinTo
2601
2607
  )
2602
2608
  );
@@ -2619,16 +2625,16 @@ const processJoinArgs = (joinTo, first, args, joinSubQuery) => {
2619
2625
  pushQueryArray(q, "or", query.or);
2620
2626
  }
2621
2627
  if (query.scopes) {
2622
- q.q.scopes = __spreadValues$c(__spreadValues$c({}, q.q.scopes), query.scopes);
2628
+ q.q.scopes = __spreadValues$g(__spreadValues$g({}, q.q.scopes), query.scopes);
2623
2629
  }
2624
2630
  }
2625
- const joinedShapes = __spreadProps$4(__spreadValues$c({}, joinTo.q.joinedShapes), {
2631
+ const joinedShapes = __spreadProps$6(__spreadValues$g({}, joinTo.q.joinedShapes), {
2626
2632
  [joinTo.q.as || joinTo.table]: joinTo.shape
2627
2633
  });
2628
2634
  const r = args0(
2629
2635
  makeJoinQueryBuilder(
2630
2636
  q,
2631
- q.q.joinedShapes ? __spreadValues$c(__spreadValues$c({}, q.q.joinedShapes), joinedShapes) : joinedShapes,
2637
+ q.q.joinedShapes ? __spreadValues$g(__spreadValues$g({}, q.q.joinedShapes), joinedShapes) : joinedShapes,
2632
2638
  joinTo
2633
2639
  )
2634
2640
  );
@@ -2676,30 +2682,32 @@ const _queryNone = (q) => {
2676
2682
  };
2677
2683
  const isQueryNone = (q) => q.then === noneMethods.then;
2678
2684
 
2679
- var __defProp$b = Object.defineProperty;
2680
- var __defProps$3 = Object.defineProperties;
2681
- var __getOwnPropDescs$3 = Object.getOwnPropertyDescriptors;
2682
- var __getOwnPropSymbols$c = Object.getOwnPropertySymbols;
2683
- var __hasOwnProp$c = Object.prototype.hasOwnProperty;
2684
- var __propIsEnum$c = Object.prototype.propertyIsEnumerable;
2685
- var __defNormalProp$b = (obj, key, value) => key in obj ? __defProp$b(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2686
- var __spreadValues$b = (a, b) => {
2685
+ var __defProp$f = Object.defineProperty;
2686
+ var __defProps$5 = Object.defineProperties;
2687
+ var __getOwnPropDescs$5 = Object.getOwnPropertyDescriptors;
2688
+ var __getOwnPropSymbols$g = Object.getOwnPropertySymbols;
2689
+ var __hasOwnProp$g = Object.prototype.hasOwnProperty;
2690
+ var __propIsEnum$g = Object.prototype.propertyIsEnumerable;
2691
+ var __defNormalProp$f = (obj, key, value) => key in obj ? __defProp$f(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2692
+ var __spreadValues$f = (a, b) => {
2687
2693
  for (var prop in b || (b = {}))
2688
- if (__hasOwnProp$c.call(b, prop))
2689
- __defNormalProp$b(a, prop, b[prop]);
2690
- if (__getOwnPropSymbols$c)
2691
- for (var prop of __getOwnPropSymbols$c(b)) {
2692
- if (__propIsEnum$c.call(b, prop))
2693
- __defNormalProp$b(a, prop, b[prop]);
2694
+ if (__hasOwnProp$g.call(b, prop))
2695
+ __defNormalProp$f(a, prop, b[prop]);
2696
+ if (__getOwnPropSymbols$g)
2697
+ for (var prop of __getOwnPropSymbols$g(b)) {
2698
+ if (__propIsEnum$g.call(b, prop))
2699
+ __defNormalProp$f(a, prop, b[prop]);
2694
2700
  }
2695
2701
  return a;
2696
2702
  };
2697
- var __spreadProps$3 = (a, b) => __defProps$3(a, __getOwnPropDescs$3(b));
2703
+ var __spreadProps$5 = (a, b) => __defProps$5(a, __getOwnPropDescs$5(b));
2698
2704
  const _join = (query, require2, type, first, args) => {
2699
- var _a, _b;
2705
+ var _a, _b, _c, _d;
2700
2706
  let joinKey;
2701
2707
  let shape;
2702
2708
  let parsers;
2709
+ let batchParsers;
2710
+ let computeds;
2703
2711
  let joinSubQuery = false;
2704
2712
  if (typeof first === "function") {
2705
2713
  first = first(query.relations);
@@ -2715,6 +2723,8 @@ const _join = (query, require2, type, first, args) => {
2715
2723
  if (joinKey) {
2716
2724
  shape = getShapeFromSelect(q, joinSubQuery);
2717
2725
  parsers = q.q.parsers;
2726
+ batchParsers = q.q.batchParsers;
2727
+ computeds = q.q.computeds;
2718
2728
  if (joinSubQuery) {
2719
2729
  first = q.clone();
2720
2730
  first.shape = shape;
@@ -2725,12 +2735,17 @@ const _join = (query, require2, type, first, args) => {
2725
2735
  const relation = query.relations[joinKey];
2726
2736
  if (relation) {
2727
2737
  shape = getShapeFromSelect(relation.relationConfig.query);
2728
- parsers = relation.relationConfig.query.q.parsers;
2738
+ const r = relation.relationConfig.query;
2739
+ parsers = r.q.parsers;
2740
+ batchParsers = r.q.batchParsers;
2741
+ computeds = r.q.computeds;
2729
2742
  } else {
2730
- shape = (_a = query.q.withShapes) == null ? void 0 : _a[joinKey];
2743
+ const w = (_a = query.q.withShapes) == null ? void 0 : _a[joinKey];
2744
+ shape = w == null ? void 0 : w.shape;
2745
+ computeds = w == null ? void 0 : w.computeds;
2731
2746
  if (shape) {
2732
2747
  if (!require2)
2733
- shape = __spreadValues$b({}, shape);
2748
+ shape = __spreadValues$f({}, shape);
2734
2749
  parsers = {};
2735
2750
  for (const key in shape) {
2736
2751
  const parser = shape[key].parseFn;
@@ -2741,20 +2756,6 @@ const _join = (query, require2, type, first, args) => {
2741
2756
  }
2742
2757
  }
2743
2758
  }
2744
- if (joinKey) {
2745
- setQueryObjectValue(
2746
- query,
2747
- "joinedShapes",
2748
- joinKey,
2749
- shape
2750
- );
2751
- setQueryObjectValue(
2752
- query,
2753
- "joinedParsers",
2754
- joinKey,
2755
- parsers
2756
- );
2757
- }
2758
2759
  const joinArgs = processJoinArgs(
2759
2760
  query,
2760
2761
  first,
@@ -2777,17 +2778,60 @@ const _join = (query, require2, type, first, args) => {
2777
2778
  joinKey,
2778
2779
  j.q.parsers
2779
2780
  );
2781
+ if (j.q.batchParsers) {
2782
+ ((_d = (_c = query.q).joinedBatchParsers) != null ? _d : _c.joinedBatchParsers = {})[joinKey] = j.q.batchParsers;
2783
+ }
2784
+ setQueryObjectValue(
2785
+ query,
2786
+ "joinedComputeds",
2787
+ joinKey,
2788
+ j.q.computeds
2789
+ );
2790
+ } else {
2791
+ addAllShapesAndParsers(
2792
+ query,
2793
+ joinKey,
2794
+ shape,
2795
+ parsers,
2796
+ batchParsers,
2797
+ computeds
2798
+ );
2780
2799
  }
2781
2800
  } else if (require2 && "r" in joinArgs && isQueryNone(joinArgs.r)) {
2782
2801
  return _queryNone(query);
2802
+ } else {
2803
+ addAllShapesAndParsers(
2804
+ query,
2805
+ joinKey,
2806
+ shape,
2807
+ parsers,
2808
+ batchParsers,
2809
+ computeds
2810
+ );
2783
2811
  }
2784
2812
  return pushQueryValue(query, "join", {
2785
2813
  type,
2786
2814
  args: joinArgs
2787
2815
  });
2788
2816
  };
2817
+ const addAllShapesAndParsers = (query, joinKey, shape, parsers, batchParsers, computeds) => {
2818
+ var _a, _b;
2819
+ if (!joinKey)
2820
+ return;
2821
+ setQueryObjectValue(query, "joinedShapes", joinKey, shape);
2822
+ setQueryObjectValue(query, "joinedParsers", joinKey, parsers);
2823
+ if (batchParsers) {
2824
+ ((_b = (_a = query.q).joinedBatchParsers) != null ? _b : _a.joinedBatchParsers = {})[joinKey] = batchParsers;
2825
+ }
2826
+ setQueryObjectValue(
2827
+ query,
2828
+ "joinedComputeds",
2829
+ joinKey,
2830
+ computeds
2831
+ );
2832
+ };
2789
2833
  const _joinLateral = (self, type, arg, cb, as) => {
2790
- var _a, _b, _c;
2834
+ var _a, _b, _c, _d, _e, _f, _g;
2791
2835
  const q = self;
2792
2836
  let relation;
2793
2837
  if (typeof arg === "string") {
@@ -2795,13 +2839,14 @@ const _joinLateral = (self, type, arg, cb, as) => {
2795
2839
  if (relation) {
2796
2840
  arg = relation.relationConfig.query.clone();
2797
2841
  } else {
2798
- const shape = (_a = q.q.withShapes) == null ? void 0 : _a[arg];
2799
- if (shape) {
2842
+ const w = (_a = q.q.withShapes) == null ? void 0 : _a[arg];
2843
+ if (w) {
2800
2844
  const t = Object.create(q.queryBuilder);
2801
2845
  t.table = arg;
2802
- t.shape = shape;
2803
- t.q = __spreadProps$3(__spreadValues$b({}, t.q), {
2804
- shape
2846
+ t.shape = w.shape;
2847
+ t.computeds = w.computeds;
2848
+ t.q = __spreadProps$5(__spreadValues$f({}, t.q), {
2849
+ shape: w.shape
2805
2850
  });
2806
2851
  t.baseQuery = t;
2807
2852
  arg = t;
@@ -2810,7 +2855,8 @@ const _joinLateral = (self, type, arg, cb, as) => {
2810
2855
  }
2811
2856
  const query = arg;
2812
2857
  query.q.joinTo = q;
2813
- ((_c = (_b = query.q).joinedShapes) != null ? _c : _b.joinedShapes = {})[getQueryAs(q)] = q.q.shape;
2858
+ const joinedAs = getQueryAs(q);
2859
+ ((_c = (_b = query.q).joinedShapes) != null ? _c : _b.joinedShapes = {})[joinedAs] = q.q.shape;
2814
2860
  let result = resolveSubQueryCallback(query, cb);
2815
2861
  if (relation) {
2816
2862
  result = relation.relationConfig.joinQuery(
@@ -2823,12 +2869,13 @@ const _joinLateral = (self, type, arg, cb, as) => {
2823
2869
  const shape = getShapeFromSelect(result, true);
2824
2870
  setQueryObjectValue(q, "joinedShapes", joinKey, shape);
2825
2871
  setQueryObjectValue(q, "joinedParsers", joinKey, result.q.parsers);
2872
+ if (result.q.batchParsers) {
2873
+ ((_e = (_d = q.q).joinedBatchParsers) != null ? _e : _d.joinedBatchParsers = {})[joinKey] = result.q.batchParsers;
2874
+ }
2826
2875
  }
2827
- return pushQueryValue(q, "join", [
2828
- type,
2829
- result,
2830
- as || getQueryAs(result)
2831
- ]);
2876
+ as || (as = getQueryAs(result));
2877
+ ((_g = (_f = q.q).joinedComputeds) != null ? _g : _f.joinedComputeds = {})[as] = result.q.computeds;
2878
+ return pushQueryValue(q, "join", [type, result, as]);
2832
2879
  };
2833
2880
 
2834
2881
  class EnumColumn extends ColumnType {
@@ -3117,9 +3164,221 @@ class Transaction {
3117
3164
  }
3118
3165
  }
3119
3166
  }
3120
- }
3167
+ }
3168
+
3169
+ const applyBatchTransforms = (query, batches) => {
3170
+ if (query.transform) {
3171
+ for (const item of batches) {
3172
+ item.parent[item.key] = applyTransforms(
3173
+ query.returnType,
3174
+ query.transform,
3175
+ item.data
3176
+ );
3177
+ }
3178
+ }
3179
+ };
3180
+ const finalizeNestedHookSelect = (batches, returnType, tempColumns, renames, key) => {
3181
+ var _a;
3182
+ if (renames) {
3183
+ for (const { data } of batches) {
3184
+ for (const record of data) {
3185
+ if (record) {
3186
+ for (const a in renames) {
3187
+ record[a] = record[renames[a]];
3188
+ }
3189
+ }
3190
+ }
3191
+ }
3192
+ }
3193
+ if (tempColumns == null ? void 0 : tempColumns.size) {
3194
+ for (const { data } of batches) {
3195
+ for (const record of data) {
3196
+ if (record) {
3197
+ for (const key2 of tempColumns) {
3198
+ delete record[key2];
3199
+ }
3200
+ }
3201
+ }
3202
+ }
3203
+ }
3204
+ if (returnType === "one" || returnType === "oneOrThrow") {
3205
+ for (const batch of batches) {
3206
+ batch.data = batch.data[0];
3207
+ }
3208
+ } else if (returnType === "pluck") {
3209
+ for (const { data } of batches) {
3210
+ for (let i = 0; i < data.length; i++) {
3211
+ data[i] = data[i][key];
3212
+ }
3213
+ }
3214
+ } else if (returnType === "value" || returnType === "valueOrThrow") {
3215
+ for (const item of batches) {
3216
+ item.parent[item.key] = (_a = item.data[0]) == null ? void 0 : _a[key];
3217
+ }
3218
+ }
3219
+ };
3220
+
3221
+ var __defProp$e = Object.defineProperty;
3222
+ var __defProps$4 = Object.defineProperties;
3223
+ var __getOwnPropDescs$4 = Object.getOwnPropertyDescriptors;
3224
+ var __getOwnPropSymbols$f = Object.getOwnPropertySymbols;
3225
+ var __hasOwnProp$f = Object.prototype.hasOwnProperty;
3226
+ var __propIsEnum$f = Object.prototype.propertyIsEnumerable;
3227
+ var __defNormalProp$e = (obj, key, value) => key in obj ? __defProp$e(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3228
+ var __spreadValues$e = (a, b) => {
3229
+ for (var prop in b || (b = {}))
3230
+ if (__hasOwnProp$f.call(b, prop))
3231
+ __defNormalProp$e(a, prop, b[prop]);
3232
+ if (__getOwnPropSymbols$f)
3233
+ for (var prop of __getOwnPropSymbols$f(b)) {
3234
+ if (__propIsEnum$f.call(b, prop))
3235
+ __defNormalProp$e(a, prop, b[prop]);
3236
+ }
3237
+ return a;
3238
+ };
3239
+ var __spreadProps$4 = (a, b) => __defProps$4(a, __getOwnPropDescs$4(b));
3240
+ class ComputedColumn {
3241
+ constructor(kind, deps, fn) {
3242
+ this.kind = kind;
3243
+ this.deps = deps;
3244
+ this.fn = fn;
3245
+ }
3246
+ }
3247
+ const computeAtRuntime = (deps, fn) => new ComputedColumn("one", deps, fn);
3248
+ const computeBatchAtRuntime = (deps, fn) => new ComputedColumn("many", deps, fn);
3249
+ const applyComputedColumns = (q, fn) => {
3250
+ q.computeAtRuntime = computeAtRuntime;
3251
+ q.computeBatchAtRuntime = computeBatchAtRuntime;
3252
+ const computed = fn(q);
3253
+ for (const key in computed) {
3254
+ const item = computed[key];
3255
+ if (item instanceof ComputedColumn) {
3256
+ q.q.computeds = __spreadProps$4(__spreadValues$e({}, q.q.computeds), { [key]: item });
3257
+ } else {
3258
+ (q.shape[key] = item.result.value || UnknownColumn.instance).data.computed = item;
3259
+ }
3260
+ }
3261
+ q.computeAtRuntime = q.computeBatchAtRuntime = void 0;
3262
+ };
3263
+ const processComputedResult = (query, result) => {
3264
+ let promises;
3265
+ for (const key in query.selectedComputeds) {
3266
+ const computed = query.selectedComputeds[key];
3267
+ if (computed.kind === "one") {
3268
+ for (const record of result) {
3269
+ record[key] = computed.fn(record);
3270
+ }
3271
+ } else {
3272
+ const res = computed.fn(result);
3273
+ if (Array.isArray(res)) {
3274
+ saveBatchComputed(key, result, res);
3275
+ } else {
3276
+ (promises != null ? promises : promises = []).push(
3277
+ res.then(
3278
+ (res2) => saveBatchComputed(key, result, res2)
3279
+ )
3280
+ );
3281
+ }
3282
+ }
3283
+ }
3284
+ if (!promises)
3285
+ return;
3286
+ return Promise.all(promises);
3287
+ };
3288
+ const processComputedBatches = (query, batches, originalReturnType, returnType, tempColumns, renames, key) => {
3289
+ let promises;
3290
+ for (const key2 in query.selectedComputeds) {
3291
+ const computed = query.selectedComputeds[key2];
3292
+ if (computed.kind === "one") {
3293
+ for (const { data } of batches) {
3294
+ for (const record of data) {
3295
+ if (record) {
3296
+ record[key2] = computed.fn(record);
3297
+ }
3298
+ }
3299
+ }
3300
+ } else {
3301
+ for (const { data } of batches) {
3302
+ let present;
3303
+ let blanks;
3304
+ if (!returnType || returnType === "all") {
3305
+ present = data;
3306
+ } else {
3307
+ present = [];
3308
+ blanks = /* @__PURE__ */ new Set();
3309
+ for (let i = 0; i < data.length; i++) {
3310
+ if (data[i]) {
3311
+ present.push(data[i]);
3312
+ } else {
3313
+ blanks.add(i);
3314
+ }
3315
+ }
3316
+ }
3317
+ const res = computed.fn(present);
3318
+ if (Array.isArray(res)) {
3319
+ saveBatchComputed(key2, data, res, blanks);
3320
+ } else {
3321
+ (promises != null ? promises : promises = []).push(
3322
+ res.then(
3323
+ (res2) => saveBatchComputed(key2, data, res2, blanks)
3324
+ )
3325
+ );
3326
+ }
3327
+ }
3328
+ }
3329
+ }
3330
+ if (!promises)
3331
+ return;
3332
+ return Promise.all(promises).then(() => {
3333
+ finalizeNestedHookSelect(
3334
+ batches,
3335
+ originalReturnType,
3336
+ tempColumns,
3337
+ renames,
3338
+ key
3339
+ );
3340
+ applyBatchTransforms(query, batches);
3341
+ });
3342
+ };
3343
+ const saveBatchComputed = (key, result, res, blanks) => {
3344
+ const len = result.length;
3345
+ const actual = res.length + ((blanks == null ? void 0 : blanks.size) || 0);
3346
+ if (len !== actual) {
3347
+ throw new Error(
3348
+ `Incorrect length of batch computed result for column ${key}. Expected ${len}, received ${actual}.`
3349
+ );
3350
+ }
3351
+ if (blanks) {
3352
+ for (let i = 0, r = 0; i < len; i++) {
3353
+ if (!blanks.has(i)) {
3354
+ result[i][key] = res[r++];
3355
+ }
3356
+ }
3357
+ } else {
3358
+ for (let i = 0; i < len; i++) {
3359
+ result[i][key] = res[i];
3360
+ }
3361
+ }
3362
+ };
3121
3363
 
3364
+ var __defProp$d = Object.defineProperty;
3365
+ var __getOwnPropSymbols$e = Object.getOwnPropertySymbols;
3366
+ var __hasOwnProp$e = Object.prototype.hasOwnProperty;
3367
+ var __propIsEnum$e = Object.prototype.propertyIsEnumerable;
3368
+ var __defNormalProp$d = (obj, key, value) => key in obj ? __defProp$d(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3369
+ var __spreadValues$d = (a, b) => {
3370
+ for (var prop in b || (b = {}))
3371
+ if (__hasOwnProp$e.call(b, prop))
3372
+ __defNormalProp$d(a, prop, b[prop]);
3373
+ if (__getOwnPropSymbols$e)
3374
+ for (var prop of __getOwnPropSymbols$e(b)) {
3375
+ if (__propIsEnum$e.call(b, prop))
3376
+ __defNormalProp$d(a, prop, b[prop]);
3377
+ }
3378
+ return a;
3379
+ };
3122
3380
  const queryMethodByReturnType = {
3381
+ undefined: "query",
3123
3382
  all: "query",
3124
3383
  rows: "arrays",
3125
3384
  pluck: "arrays",
@@ -3167,9 +3426,6 @@ Object.defineProperty(Then.prototype, "then", {
3167
3426
  });
3168
3427
  }
3169
3428
  });
3170
- const handleResult = (q, returnType, result, isSubQuery) => {
3171
- return parseResult(q, q.q.parsers, returnType, result, isSubQuery);
3172
- };
3173
3429
  function maybeWrappedThen(resolve, reject) {
3174
3430
  const { q } = this;
3175
3431
  let beforeHooks;
@@ -3227,7 +3483,7 @@ const callAfterHook = function(cb) {
3227
3483
  };
3228
3484
  const beginSql = { text: "BEGIN" };
3229
3485
  const then = async (q, adapter, trx, beforeHooks, afterHooks, afterCommitHooks, resolve, reject) => {
3230
- var _a;
3486
+ var _a, _b;
3231
3487
  const { q: query } = q;
3232
3488
  let sql;
3233
3489
  let logData;
@@ -3244,7 +3500,7 @@ const then = async (q, adapter, trx, beforeHooks, afterHooks, afterCommitHooks,
3244
3500
  sql = q.toSQL();
3245
3501
  const { hookSelect } = sql;
3246
3502
  const { returnType = "all" } = query;
3247
- const returns = hookSelect ? "all" : returnType;
3503
+ const tempReturnType = hookSelect || returnType === "rows" && q.q.batchParsers ? "all" : returnType;
3248
3504
  let result;
3249
3505
  let queryResult;
3250
3506
  if ("text" in sql) {
@@ -3254,7 +3510,7 @@ const then = async (q, adapter, trx, beforeHooks, afterHooks, afterCommitHooks,
3254
3510
  if (query.log) {
3255
3511
  logData = query.log.beforeQuery(sql);
3256
3512
  }
3257
- queryResult = await adapter[hookSelect ? "query" : queryMethodByReturnType[returnType]](sql);
3513
+ queryResult = await adapter[queryMethodByReturnType[tempReturnType]](sql);
3258
3514
  if (query.patchResult) {
3259
3515
  await query.patchResult(q, queryResult);
3260
3516
  }
@@ -3262,9 +3518,9 @@ const then = async (q, adapter, trx, beforeHooks, afterHooks, afterCommitHooks,
3262
3518
  query.log.afterQuery(sql, logData);
3263
3519
  sql = void 0;
3264
3520
  }
3265
- result = query.handleResult(q, returns, queryResult);
3521
+ result = query.handleResult(q, tempReturnType, queryResult);
3266
3522
  } else {
3267
- const queryMethod = hookSelect ? "query" : queryMethodByReturnType[returnType];
3523
+ const queryMethod = queryMethodByReturnType[tempReturnType];
3268
3524
  if (!trx) {
3269
3525
  if (query.log)
3270
3526
  logData = query.log.beforeQuery(beginSql);
@@ -3299,9 +3555,37 @@ const then = async (q, adapter, trx, beforeHooks, afterHooks, afterCommitHooks,
3299
3555
  if (query.patchResult) {
3300
3556
  await query.patchResult(q, queryResult);
3301
3557
  }
3302
- result = query.handleResult(q, returns, queryResult);
3558
+ result = query.handleResult(q, tempReturnType, queryResult);
3559
+ }
3560
+ if (result && typeof result === "object" && typeof result.then === "function") {
3561
+ result = await result;
3562
+ }
3563
+ let tempColumns;
3564
+ let renames;
3565
+ if (hookSelect) {
3566
+ for (const column of hookSelect.keys()) {
3567
+ const as = hookSelect.get(column).as;
3568
+ if (as)
3569
+ (renames != null ? renames : renames = {})[column] = as;
3570
+ (_a = tempColumns != null ? tempColumns : tempColumns = /* @__PURE__ */ new Set()) == null ? void 0 : _a.add(as || column);
3571
+ }
3572
+ if (renames) {
3573
+ for (const record of result) {
3574
+ for (const a in renames) {
3575
+ const value = record[renames[a]];
3576
+ record[renames[a]] = record[a];
3577
+ record[a] = value;
3578
+ }
3579
+ }
3580
+ }
3581
+ if (query.selectedComputeds) {
3582
+ const promise = processComputedResult(query, result);
3583
+ if (promise)
3584
+ await promise;
3585
+ }
3303
3586
  }
3304
- if (afterHooks || afterCommitHooks || query.after) {
3587
+ const hasAfterHook = afterHooks || afterCommitHooks || query.after;
3588
+ if (hasAfterHook) {
3305
3589
  if (queryResult.rowCount) {
3306
3590
  if (afterHooks || query.after) {
3307
3591
  const args = [result, q];
@@ -3313,7 +3597,7 @@ const then = async (q, adapter, trx, beforeHooks, afterHooks, afterCommitHooks,
3313
3597
  );
3314
3598
  }
3315
3599
  if (afterCommitHooks && trx) {
3316
- ((_a = trx.afterCommit) != null ? _a : trx.afterCommit = []).push(
3600
+ ((_b = trx.afterCommit) != null ? _b : trx.afterCommit = []).push(
3317
3601
  result,
3318
3602
  q,
3319
3603
  afterCommitHooks
@@ -3326,8 +3610,24 @@ const then = async (q, adapter, trx, beforeHooks, afterHooks, afterCommitHooks,
3326
3610
  const args = [result, q];
3327
3611
  await Promise.all(query.after.map(callAfterHook, args));
3328
3612
  }
3329
- if (hookSelect)
3330
- result = filterResult(q, returnType, queryResult, hookSelect, result);
3613
+ }
3614
+ if (hookSelect || tempReturnType !== returnType) {
3615
+ if (renames) {
3616
+ for (const record of result) {
3617
+ for (const a in renames) {
3618
+ record[a] = record[renames[a]];
3619
+ }
3620
+ }
3621
+ }
3622
+ result = filterResult(
3623
+ q,
3624
+ returnType,
3625
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
3626
+ queryResult,
3627
+ result,
3628
+ tempColumns,
3629
+ hasAfterHook
3630
+ );
3331
3631
  }
3332
3632
  if (query.transform) {
3333
3633
  result = applyTransforms(returnType, query.transform, result);
@@ -3373,57 +3673,91 @@ const assignError = (to, from) => {
3373
3673
  to.routine = from.routine;
3374
3674
  return to;
3375
3675
  };
3376
- const parseResult = (q, parsers, returnType = "all", result, isSubQuery) => {
3676
+ const handleResult = (q, returnType, result, isSubQuery) => {
3377
3677
  var _a, _b;
3678
+ const { parsers } = q.q;
3378
3679
  switch (returnType) {
3379
3680
  case "all": {
3380
3681
  if (q.q.throwOnNotFound && result.rows.length === 0)
3381
3682
  throw new NotFoundError(q);
3683
+ const promise = parseBatch(q, result);
3382
3684
  const { rows } = result;
3383
3685
  if (parsers) {
3384
3686
  for (const row of rows) {
3385
3687
  parseRecord(parsers, row);
3386
3688
  }
3387
3689
  }
3388
- return rows;
3690
+ return promise ? promise.then(() => rows) : rows;
3389
3691
  }
3390
3692
  case "one": {
3391
- const row = result.rows[0];
3392
- if (!row)
3693
+ const { rows } = result;
3694
+ if (!rows.length)
3393
3695
  return;
3394
- return parsers ? parseRecord(parsers, row) : row;
3696
+ const promise = parseBatch(q, result);
3697
+ if (parsers)
3698
+ parseRecord(parsers, rows[0]);
3699
+ return promise ? promise.then(() => rows[0]) : rows[0];
3395
3700
  }
3396
3701
  case "oneOrThrow": {
3397
- const row = result.rows[0];
3398
- if (!row)
3702
+ const { rows } = result;
3703
+ if (!rows.length)
3399
3704
  throw new NotFoundError(q);
3400
- return parsers ? parseRecord(parsers, row) : row;
3705
+ const promise = parseBatch(q, result);
3706
+ if (parsers)
3707
+ parseRecord(parsers, rows[0]);
3708
+ return promise ? promise.then(() => rows[0]) : rows[0];
3401
3709
  }
3402
3710
  case "rows": {
3403
- return parsers ? parseRows(
3404
- parsers,
3405
- result.fields,
3406
- result.rows
3407
- ) : result.rows;
3711
+ const { rows } = result;
3712
+ const promise = parseBatch(q, result);
3713
+ if (promise) {
3714
+ return promise.then(() => {
3715
+ if (parsers)
3716
+ parseRows(parsers, result.fields, rows);
3717
+ return rows;
3718
+ });
3719
+ } else if (parsers) {
3720
+ parseRows(parsers, result.fields, rows);
3721
+ }
3722
+ return rows;
3408
3723
  }
3409
3724
  case "pluck": {
3410
- const pluck = parsers == null ? void 0 : parsers.pluck;
3411
- if (pluck) {
3412
- return result.rows.map(isSubQuery ? pluck : (row) => pluck(row[0]));
3413
- } else if (isSubQuery) {
3414
- return result.rows;
3725
+ const { rows } = result;
3726
+ const promise = parseBatch(q, result);
3727
+ if (promise) {
3728
+ return promise.then(() => {
3729
+ parsePluck(parsers, isSubQuery, rows);
3730
+ return rows;
3731
+ });
3415
3732
  }
3416
- return result.rows.map((row) => row[0]);
3733
+ parsePluck(parsers, isSubQuery, rows);
3734
+ return rows;
3417
3735
  }
3418
3736
  case "value": {
3419
- const value = (_a = result.rows[0]) == null ? void 0 : _a[0];
3420
- return value !== void 0 ? parseValue(value, parsers) : q.q.notFoundDefault;
3737
+ const { rows } = result;
3738
+ const promise = parseBatch(q, result);
3739
+ if (promise) {
3740
+ return promise.then(() => {
3741
+ var _a2;
3742
+ return ((_a2 = rows[0]) == null ? void 0 : _a2[0]) !== void 0 ? parseValue(rows[0][0], parsers) : q.q.notFoundDefault;
3743
+ });
3744
+ }
3745
+ return ((_a = rows[0]) == null ? void 0 : _a[0]) !== void 0 ? parseValue(rows[0][0], parsers) : q.q.notFoundDefault;
3421
3746
  }
3422
3747
  case "valueOrThrow": {
3423
- const value = (_b = result.rows[0]) == null ? void 0 : _b[0];
3424
- if (value === void 0)
3748
+ const { rows } = result;
3749
+ const promise = parseBatch(q, result);
3750
+ if (promise) {
3751
+ return promise.then(() => {
3752
+ var _a2;
3753
+ if (((_a2 = rows[0]) == null ? void 0 : _a2[0]) === void 0)
3754
+ throw new NotFoundError(q);
3755
+ return parseValue(rows[0][0], parsers);
3756
+ });
3757
+ }
3758
+ if (((_b = rows[0]) == null ? void 0 : _b[0]) === void 0)
3425
3759
  throw new NotFoundError(q);
3426
- return parseValue(value, parsers);
3760
+ return parseValue(rows[0][0], parsers);
3427
3761
  }
3428
3762
  case "rowCount": {
3429
3763
  if (q.q.throwOnNotFound && result.rowCount === 0) {
@@ -3436,6 +3770,17 @@ const parseResult = (q, parsers, returnType = "all", result, isSubQuery) => {
3436
3770
  }
3437
3771
  }
3438
3772
  };
3773
+ const parseBatch = (q, queryResult) => {
3774
+ let promises;
3775
+ if (q.q.batchParsers) {
3776
+ for (const parser of q.q.batchParsers) {
3777
+ const res = parser.fn(parser.path, queryResult);
3778
+ if (res)
3779
+ (promises != null ? promises : promises = []).push(res);
3780
+ }
3781
+ }
3782
+ return promises && Promise.all(promises);
3783
+ };
3439
3784
  const parseRecord = (parsers, row) => {
3440
3785
  for (const key in parsers) {
3441
3786
  if (key in row) {
@@ -3453,38 +3798,43 @@ const parseRows = (parsers, fields, rows) => {
3453
3798
  }
3454
3799
  }
3455
3800
  }
3456
- return rows;
3801
+ };
3802
+ const parsePluck = (parsers, isSubQuery, rows) => {
3803
+ const pluck = parsers == null ? void 0 : parsers.pluck;
3804
+ if (pluck) {
3805
+ for (let i = 0; i < rows.length; i++) {
3806
+ rows[i] = pluck(isSubQuery ? rows[i] : rows[i][0]);
3807
+ }
3808
+ } else if (!isSubQuery) {
3809
+ for (let i = 0; i < rows.length; i++) {
3810
+ rows[i] = rows[i][0];
3811
+ }
3812
+ }
3457
3813
  };
3458
3814
  const parseValue = (value, parsers) => {
3459
3815
  const parser = parsers == null ? void 0 : parsers[getValueKey];
3460
3816
  return parser ? parser(value) : value;
3461
3817
  };
3462
- const filterResult = (q, returnType, queryResult, hookSelect, result) => {
3818
+ const filterResult = (q, returnType, queryResult, result, tempColumns, hasAfterHook) => {
3463
3819
  var _a;
3464
3820
  if (returnType === "all") {
3465
- const pick = getSelectPick(queryResult, hookSelect);
3466
- return result.map((full) => {
3467
- const filtered = {};
3468
- for (const key of pick) {
3469
- filtered[key] = full[key];
3470
- }
3471
- return filtered;
3472
- });
3821
+ return filterAllResult(result, tempColumns, hasAfterHook);
3473
3822
  }
3474
3823
  if (returnType === "oneOrThrow" || returnType === "one") {
3475
- const row = result[0];
3824
+ let row = result[0];
3476
3825
  if (!row) {
3477
3826
  if (returnType === "oneOrThrow")
3478
3827
  throw new NotFoundError(q);
3479
3828
  return void 0;
3829
+ } else if (!(tempColumns == null ? void 0 : tempColumns.size)) {
3830
+ return row;
3480
3831
  } else {
3481
- result = {};
3482
- for (const key in row) {
3483
- if (!hookSelect.includes(key)) {
3484
- result[key] = row[key];
3485
- }
3832
+ if (hasAfterHook)
3833
+ row = __spreadValues$d({}, row);
3834
+ for (const column of tempColumns) {
3835
+ delete row[column];
3486
3836
  }
3487
- return result;
3837
+ return row;
3488
3838
  }
3489
3839
  }
3490
3840
  if (returnType === "value") {
@@ -3504,79 +3854,270 @@ const filterResult = (q, returnType, queryResult, hookSelect, result) => {
3504
3854
  return result.map((row) => row[key]);
3505
3855
  }
3506
3856
  if (returnType === "rows") {
3507
- const pick = getSelectPick(queryResult, hookSelect);
3508
- return result.map(
3509
- (full) => pick.map((key) => full[key])
3510
- );
3857
+ result = filterAllResult(result, tempColumns, hasAfterHook);
3858
+ return result.map((record) => Object.values(record));
3511
3859
  }
3512
3860
  return;
3513
3861
  };
3514
- const getSelectPick = (queryResult, hookSelect) => {
3515
- const pick = [];
3516
- for (const field of queryResult.fields) {
3517
- if (!hookSelect.includes(field.name))
3518
- pick.push(field.name);
3862
+ const filterAllResult = (result, tempColumns, hasAfterHook) => {
3863
+ if (tempColumns == null ? void 0 : tempColumns.size) {
3864
+ if (hasAfterHook) {
3865
+ return result.map((data) => {
3866
+ const record = __spreadValues$d({}, data);
3867
+ for (const key of tempColumns) {
3868
+ delete record[key];
3869
+ }
3870
+ return record;
3871
+ });
3872
+ } else {
3873
+ for (const record of result) {
3874
+ for (const key of tempColumns) {
3875
+ delete record[key];
3876
+ }
3877
+ }
3878
+ }
3519
3879
  }
3520
- return pick;
3880
+ return result;
3521
3881
  };
3522
3882
 
3883
+ var __defProp$c = Object.defineProperty;
3884
+ var __defProps$3 = Object.defineProperties;
3885
+ var __getOwnPropDescs$3 = Object.getOwnPropertyDescriptors;
3886
+ var __getOwnPropSymbols$d = Object.getOwnPropertySymbols;
3887
+ var __hasOwnProp$d = Object.prototype.hasOwnProperty;
3888
+ var __propIsEnum$d = Object.prototype.propertyIsEnumerable;
3889
+ var __defNormalProp$c = (obj, key, value) => key in obj ? __defProp$c(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3890
+ var __spreadValues$c = (a, b) => {
3891
+ for (var prop in b || (b = {}))
3892
+ if (__hasOwnProp$d.call(b, prop))
3893
+ __defNormalProp$c(a, prop, b[prop]);
3894
+ if (__getOwnPropSymbols$d)
3895
+ for (var prop of __getOwnPropSymbols$d(b)) {
3896
+ if (__propIsEnum$d.call(b, prop))
3897
+ __defNormalProp$c(a, prop, b[prop]);
3898
+ }
3899
+ return a;
3900
+ };
3901
+ var __spreadProps$3 = (a, b) => __defProps$3(a, __getOwnPropDescs$3(b));
3523
3902
  const addParserForRawExpression = (q, key, raw) => {
3524
3903
  const type = raw.result.value;
3525
3904
  if (type == null ? void 0 : type.parseFn)
3526
3905
  setParserToQuery(q.q, key, type.parseFn);
3527
3906
  };
3528
- const subQueryResult = {
3529
- // sub query can't return a rowCount, use -1 as for impossible case
3530
- rowCount: -1,
3531
- rows: emptyArray,
3532
- fields: emptyArray
3533
- };
3534
3907
  const addParsersForSelectJoined = (q, arg, as = arg) => {
3535
- var _a;
3908
+ var _a, _b, _c, _d;
3536
3909
  const parsers = (_a = q.q.joinedParsers) == null ? void 0 : _a[arg];
3537
3910
  if (parsers) {
3538
3911
  setParserToQuery(q.q, as, (row) => parseRecord(parsers, row));
3539
3912
  }
3913
+ const batchParsers = (_b = q.q.joinedBatchParsers) == null ? void 0 : _b[arg];
3914
+ if (batchParsers) {
3915
+ ((_d = (_c = q.q).batchParsers) != null ? _d : _c.batchParsers = []).push(
3916
+ ...batchParsers.map((x) => ({
3917
+ path: [as, ...x.path],
3918
+ fn: x.fn
3919
+ }))
3920
+ );
3921
+ }
3540
3922
  };
3541
3923
  const addParserForSelectItem = (q, as, key, arg) => {
3924
+ var _a, _b, _c, _d;
3542
3925
  if (typeof arg === "object" || typeof arg === "function") {
3543
3926
  if (isExpression(arg)) {
3544
3927
  addParserForRawExpression(q, key, arg);
3545
3928
  } else {
3546
3929
  const { q: query } = arg;
3547
- if (query.parsers || query.transform) {
3548
- setParserToQuery(q.q, key, (item) => {
3549
- const t = query.returnType || "all";
3550
- subQueryResult.rows = t === "value" || t === "valueOrThrow" ? [[item]] : t === "one" || t === "oneOrThrow" ? [item] : item;
3551
- const result = query.handleResult(arg, t, subQueryResult, true);
3552
- return query.transform ? applyTransforms(t, query.transform, result) : result;
3553
- });
3930
+ if (query.batchParsers) {
3931
+ const batchParsers = (_b = (_a = q.q).batchParsers) != null ? _b : _a.batchParsers = [];
3932
+ for (const bp of query.batchParsers) {
3933
+ batchParsers.push({ path: [key, ...bp.path], fn: bp.fn });
3934
+ }
3554
3935
  }
3555
- if (query.returnType === "valueOrThrow" || query.returnType === "oneOrThrow") {
3556
- pushQueryValue(
3557
- q,
3558
- "transform",
3559
- (data) => {
3560
- if (Array.isArray(data)) {
3561
- for (const item of data) {
3562
- if (item[key] === void 0) {
3563
- throw new NotFoundError(q);
3936
+ if (query.hookSelect || query.parsers || query.transform) {
3937
+ const batchParsers = (_d = (_c = q.q).batchParsers) != null ? _d : _c.batchParsers = [];
3938
+ batchParsers.push({
3939
+ path: [key],
3940
+ fn: (path, queryResult) => {
3941
+ var _a2, _b2, _c2;
3942
+ const { rows } = queryResult;
3943
+ const originalReturnType = query.returnType || "all";
3944
+ let returnType = originalReturnType;
3945
+ const { hookSelect } = query;
3946
+ const batches = [];
3947
+ let last = path.length;
3948
+ if (returnType === "value" || returnType === "valueOrThrow") {
3949
+ if (hookSelect) {
3950
+ batches.push = (item) => {
3951
+ if (!(key in item)) {
3952
+ returnType = returnType === "value" ? "one" : "oneOrThrow";
3953
+ }
3954
+ batches.push = Array.prototype.push;
3955
+ return batches.push(item);
3956
+ };
3957
+ } else {
3958
+ last--;
3959
+ }
3960
+ }
3961
+ collectNestedSelectBatches(batches, rows, path, last);
3962
+ switch (returnType) {
3963
+ case "all": {
3964
+ const { parsers } = query;
3965
+ if (parsers) {
3966
+ for (const { data } of batches) {
3967
+ for (const one of data) {
3968
+ parseRecord(parsers, one);
3969
+ }
3970
+ }
3564
3971
  }
3972
+ break;
3565
3973
  }
3566
- } else {
3567
- if (data[key] === void 0) {
3568
- throw new NotFoundError(q);
3974
+ case "one":
3975
+ case "oneOrThrow": {
3976
+ const { parsers } = query;
3977
+ if (parsers) {
3978
+ if (returnType === "one") {
3979
+ for (const { data } of batches) {
3980
+ if (data)
3981
+ parseRecord(parsers, data);
3982
+ }
3983
+ } else {
3984
+ for (const { data } of batches) {
3985
+ if (!data)
3986
+ throw new NotFoundError(arg);
3987
+ parseRecord(parsers, data);
3988
+ }
3989
+ }
3990
+ } else if (returnType !== "one") {
3991
+ for (const { data } of batches) {
3992
+ if (!data)
3993
+ throw new NotFoundError(arg);
3994
+ }
3995
+ }
3996
+ if (hookSelect) {
3997
+ for (const batch of batches) {
3998
+ batch.data = [batch.data];
3999
+ }
4000
+ }
4001
+ break;
4002
+ }
4003
+ case "pluck": {
4004
+ const parse = (_a2 = query.parsers) == null ? void 0 : _a2.pluck;
4005
+ if (parse) {
4006
+ for (const { data } of batches) {
4007
+ for (let i = 0; i < data.length; i++) {
4008
+ data[i] = parse(data[i]);
4009
+ }
4010
+ }
4011
+ }
4012
+ break;
4013
+ }
4014
+ case "value":
4015
+ case "valueOrThrow": {
4016
+ const parse = (_b2 = query.parsers) == null ? void 0 : _b2[getValueKey];
4017
+ if (parse) {
4018
+ if (returnType === "value") {
4019
+ for (const { data } of batches) {
4020
+ data[key] = data[key] === void 0 ? arg.q.notFoundDefault : parse(data[key]);
4021
+ }
4022
+ } else {
4023
+ for (const { data } of batches) {
4024
+ if (data[key] === void 0)
4025
+ throw new NotFoundError(arg);
4026
+ data[key] = parse(data[key]);
4027
+ }
4028
+ }
4029
+ } else if (returnType !== "value") {
4030
+ for (const { data } of batches) {
4031
+ if (data[key] === void 0)
4032
+ throw new NotFoundError(arg);
4033
+ }
4034
+ }
4035
+ if (hookSelect) {
4036
+ for (const batch of batches) {
4037
+ batch.data = [batch.data];
4038
+ }
4039
+ }
4040
+ break;
4041
+ }
4042
+ }
4043
+ if (hookSelect) {
4044
+ let tempColumns;
4045
+ let renames;
4046
+ for (const column of hookSelect.keys()) {
4047
+ const as2 = hookSelect.get(column).as;
4048
+ if (as2)
4049
+ (renames != null ? renames : renames = {})[column] = as2;
4050
+ (_c2 = tempColumns != null ? tempColumns : tempColumns = /* @__PURE__ */ new Set()) == null ? void 0 : _c2.add(as2 || column);
4051
+ }
4052
+ if (renames) {
4053
+ for (const { data } of batches) {
4054
+ for (const record of data) {
4055
+ if (record) {
4056
+ for (const a in renames) {
4057
+ const value = record[renames[a]];
4058
+ record[renames[a]] = record[a];
4059
+ record[a] = value;
4060
+ }
4061
+ }
4062
+ }
4063
+ }
4064
+ }
4065
+ if (query.selectedComputeds) {
4066
+ const maybePromise = processComputedBatches(
4067
+ query,
4068
+ batches,
4069
+ originalReturnType,
4070
+ returnType,
4071
+ tempColumns,
4072
+ renames,
4073
+ key
4074
+ );
4075
+ if (maybePromise)
4076
+ return maybePromise;
3569
4077
  }
4078
+ finalizeNestedHookSelect(
4079
+ batches,
4080
+ originalReturnType,
4081
+ tempColumns,
4082
+ renames,
4083
+ key
4084
+ );
3570
4085
  }
3571
- return data;
4086
+ applyBatchTransforms(query, batches);
4087
+ return;
3572
4088
  }
3573
- );
4089
+ });
3574
4090
  }
3575
4091
  }
3576
4092
  return arg;
3577
4093
  }
3578
4094
  return setParserForSelectedString(q, arg, as, key);
3579
4095
  };
4096
+ const collectNestedSelectBatches = (batches, rows, path, last) => {
4097
+ const stack = rows.map(
4098
+ (row) => ({
4099
+ data: row,
4100
+ i: 0
4101
+ })
4102
+ );
4103
+ while (stack.length > 0) {
4104
+ const item = stack.pop();
4105
+ const { i } = item;
4106
+ if (i === last) {
4107
+ batches.push(item);
4108
+ continue;
4109
+ }
4110
+ const { data } = item;
4111
+ const key = path[i];
4112
+ if (Array.isArray(data)) {
4113
+ for (let key2 = 0; key2 < data.length; key2++) {
4114
+ stack.push({ data: data[key2], parent: data, key: key2, i });
4115
+ }
4116
+ } else if (data && typeof data === "object") {
4117
+ stack.push({ data: data[key], parent: data, key, i: i + 1 });
4118
+ }
4119
+ }
4120
+ };
3580
4121
  const emptyArrSQL = new RawSQL("'[]'");
3581
4122
  const processSelectArg = (q, as, arg, columnAs) => {
3582
4123
  var _a, _b, _c, _d;
@@ -3590,7 +4131,7 @@ const processSelectArg = (q, as, arg, columnAs) => {
3590
4131
  value = resolveSubQueryCallback(q, value);
3591
4132
  if (isQueryNone(value)) {
3592
4133
  if (value.q.innerJoinLateral) {
3593
- return;
4134
+ return false;
3594
4135
  }
3595
4136
  } else if (!isExpression(value) && value.joinQuery) {
3596
4137
  value = value.joinQuery(value, q);
@@ -3600,17 +4141,23 @@ const processSelectArg = (q, as, arg, columnAs) => {
3600
4141
  query = value.json(false);
3601
4142
  value.q.coalesceValue = emptyArrSQL;
3602
4143
  } else if (returnType === "pluck") {
3603
- query = value.wrap(value.baseQuery.clone()).jsonAgg(value.q.select[0]);
4144
+ query = value.q.select ? value.wrap(value.baseQuery.clone()).jsonAgg(value.q.select[0]) : value.json(false);
3604
4145
  value.q.coalesceValue = emptyArrSQL;
3605
4146
  } else {
3606
- if ((returnType === "value" || returnType === "valueOrThrow") && value.q.select) {
3607
- if (typeof value.q.select[0] === "string") {
3608
- value.q.select[0] = {
3609
- selectAs: { r: value.q.select[0] }
3610
- };
4147
+ if (returnType === "value" || returnType === "valueOrThrow") {
4148
+ if (value.q.select) {
4149
+ if (typeof value.q.select[0] === "string") {
4150
+ value.q.select[0] = {
4151
+ selectAs: { r: value.q.select[0] }
4152
+ };
4153
+ }
4154
+ query = value;
4155
+ } else {
4156
+ query = value.json(false);
3611
4157
  }
4158
+ } else {
4159
+ query = value;
3612
4160
  }
3613
- query = value;
3614
4161
  }
3615
4162
  let asOverride = key;
3616
4163
  if ((_a = value.q.joinedShapes) == null ? void 0 : _a[key]) {
@@ -3644,7 +4191,7 @@ const processSelectArg = (q, as, arg, columnAs) => {
3644
4191
  return { selectAs };
3645
4192
  };
3646
4193
  const setParserForSelectedString = (q, arg, as, columnAs) => {
3647
- var _a, _b, _c, _d;
4194
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
3648
4195
  const index = arg.indexOf(".");
3649
4196
  if (index !== -1) {
3650
4197
  const table = arg.slice(0, index);
@@ -3652,25 +4199,60 @@ const setParserForSelectedString = (q, arg, as, columnAs) => {
3652
4199
  if (column === "*") {
3653
4200
  addParsersForSelectJoined(q, table, columnAs);
3654
4201
  return table === as ? column : arg;
3655
- } else {
3656
- if (table === as) {
4202
+ } else if (table === as) {
4203
+ if (columnAs) {
3657
4204
  const parser = (_a = q.q.parsers) == null ? void 0 : _a[column];
3658
4205
  if (parser)
3659
- setParserToQuery(q.q, columnAs || column, parser);
3660
- return column;
3661
- } else {
3662
- const parser = (_c = (_b = q.q.joinedParsers) == null ? void 0 : _b[table]) == null ? void 0 : _c[column];
3663
- if (parser)
3664
- setParserToQuery(q.q, columnAs || column, parser);
3665
- return arg;
4206
+ q.q.parsers[columnAs] = parser;
3666
4207
  }
4208
+ return handleComputed(q, q.q.computeds, column);
4209
+ } else {
4210
+ const parser = (_c = (_b = q.q.joinedParsers) == null ? void 0 : _b[table]) == null ? void 0 : _c[column];
4211
+ if (parser)
4212
+ setParserToQuery(q.q, columnAs || column, parser);
4213
+ const batchParsers = (_d = q.q.joinedBatchParsers) == null ? void 0 : _d[table];
4214
+ if (batchParsers) {
4215
+ for (const bp of batchParsers) {
4216
+ if (bp.path[0] === column) {
4217
+ ((_f = (_e = q.q).batchParsers) != null ? _f : _e.batchParsers = []).push(bp);
4218
+ }
4219
+ }
4220
+ }
4221
+ const computeds = (_g = q.q.joinedComputeds) == null ? void 0 : _g[table];
4222
+ if (computeds == null ? void 0 : computeds[column]) {
4223
+ const computed = computeds[column];
4224
+ const map = (_i = (_h = q.q).hookSelect) != null ? _i : _h.hookSelect = /* @__PURE__ */ new Map();
4225
+ for (const column2 of computed.deps) {
4226
+ map.set(column2, { select: `${table}.${column2}` });
4227
+ }
4228
+ q.q.selectedComputeds = __spreadProps$3(__spreadValues$c({}, q.q.selectedComputeds), {
4229
+ [column]: computed
4230
+ });
4231
+ return;
4232
+ }
4233
+ return arg;
3667
4234
  }
3668
4235
  } else {
3669
- const parser = (_d = q.q.parsers) == null ? void 0 : _d[arg];
3670
- if (parser)
3671
- setParserToQuery(q.q, columnAs || arg, parser);
3672
- return arg;
4236
+ if (columnAs) {
4237
+ const parser = (_j = q.q.parsers) == null ? void 0 : _j[arg];
4238
+ if (parser)
4239
+ q.q.parsers[columnAs] = parser;
4240
+ }
4241
+ return handleComputed(q, q.q.computeds, arg);
4242
+ }
4243
+ };
4244
+ const handleComputed = (q, computeds, column) => {
4245
+ var _a, _b;
4246
+ if (computeds == null ? void 0 : computeds[column]) {
4247
+ const computed = computeds[column];
4248
+ const map = (_b = (_a = q.q).hookSelect) != null ? _b : _a.hookSelect = /* @__PURE__ */ new Map();
4249
+ for (const column2 of computed.deps) {
4250
+ map.set(column2, { select: column2 });
4251
+ }
4252
+ q.q.selectedComputeds = __spreadProps$3(__spreadValues$c({}, q.q.selectedComputeds), { [column]: computed });
4253
+ return;
3673
4254
  }
4255
+ return column;
3674
4256
  };
3675
4257
  const getShapeFromSelect = (q, isSubQuery) => {
3676
4258
  const query = q.q;
@@ -3691,7 +4273,9 @@ const getShapeFromSelect = (q, isSubQuery) => {
3691
4273
  for (const item of select) {
3692
4274
  if (typeof item === "string") {
3693
4275
  addColumnToShapeFromSelect(q, item, shape, query, result, isSubQuery);
3694
- } else if ("selectAs" in item) {
4276
+ } else if (isExpression(item)) {
4277
+ result.value = item.result.value;
4278
+ } else if (item && "selectAs" in item) {
3695
4279
  for (const key in item.selectAs) {
3696
4280
  const it = item.selectAs[key];
3697
4281
  if (typeof it === "string") {
@@ -3706,7 +4290,7 @@ const getShapeFromSelect = (q, isSubQuery) => {
3706
4290
  );
3707
4291
  } else if (isExpression(it)) {
3708
4292
  result[key] = it.result.value;
3709
- } else {
4293
+ } else if (it) {
3710
4294
  const { returnType } = it.q;
3711
4295
  if (returnType === "value" || returnType === "valueOrThrow") {
3712
4296
  const type = it.q[getValueKey];
@@ -3717,8 +4301,6 @@ const getShapeFromSelect = (q, isSubQuery) => {
3717
4301
  }
3718
4302
  }
3719
4303
  }
3720
- } else if (isExpression(item)) {
3721
- result.value = item.result.value;
3722
4304
  }
3723
4305
  }
3724
4306
  }
@@ -3754,12 +4336,13 @@ function _querySelect(q, args) {
3754
4336
  return q;
3755
4337
  }
3756
4338
  const as = q.q.as || q.table;
3757
- const selectArgs = new Array(len);
3758
- for (let i = 0; i < len; i++) {
3759
- selectArgs[i] = processSelectArg(q, as, args[i]);
3760
- if (!selectArgs[i]) {
4339
+ const selectArgs = [];
4340
+ for (const arg of args) {
4341
+ const item = processSelectArg(q, as, arg);
4342
+ if (item)
4343
+ selectArgs.push(item);
4344
+ else if (item === false)
3761
4345
  return _queryNone(q);
3762
- }
3763
4346
  }
3764
4347
  return pushQueryArray(q, "select", selectArgs);
3765
4348
  }
@@ -3829,20 +4412,25 @@ const _get = (query, returnType, arg) => {
3829
4412
  }
3830
4413
  }
3831
4414
  q[getValueKey] = type;
3832
- setParserForSelectedString(
4415
+ const selected = setParserForSelectedString(
3833
4416
  query,
3834
4417
  arg,
3835
4418
  getQueryAs(query),
3836
4419
  getValueKey
3837
4420
  );
3838
- q.expr = new SelectItemExpression(query, arg, type);
4421
+ q.select = selected ? [
4422
+ q.expr = new SelectItemExpression(
4423
+ query,
4424
+ selected,
4425
+ type
4426
+ )
4427
+ ] : void 0;
3839
4428
  } else {
3840
4429
  type = arg.result.value;
3841
4430
  q[getValueKey] = type;
3842
4431
  addParserForRawExpression(query, getValueKey, arg);
3843
- q.expr = arg;
4432
+ q.select = [q.expr = arg];
3844
4433
  }
3845
- q.select = [q.expr];
3846
4434
  return setQueryOperators(
3847
4435
  query,
3848
4436
  (type == null ? void 0 : type.operators) || Operators.any
@@ -3877,24 +4465,44 @@ class AsMethods {
3877
4465
  }
3878
4466
  }
3879
4467
 
4468
+ var __defProp$b = Object.defineProperty;
4469
+ var __getOwnPropSymbols$c = Object.getOwnPropertySymbols;
4470
+ var __hasOwnProp$c = Object.prototype.hasOwnProperty;
4471
+ var __propIsEnum$c = Object.prototype.propertyIsEnumerable;
4472
+ var __defNormalProp$b = (obj, key, value) => key in obj ? __defProp$b(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
4473
+ var __spreadValues$b = (a, b) => {
4474
+ for (var prop in b || (b = {}))
4475
+ if (__hasOwnProp$c.call(b, prop))
4476
+ __defNormalProp$b(a, prop, b[prop]);
4477
+ if (__getOwnPropSymbols$c)
4478
+ for (var prop of __getOwnPropSymbols$c(b)) {
4479
+ if (__propIsEnum$c.call(b, prop))
4480
+ __defNormalProp$b(a, prop, b[prop]);
4481
+ }
4482
+ return a;
4483
+ };
3880
4484
  function queryFrom(self, arg) {
3881
- var _a, _b;
4485
+ var _a, _b, _c;
3882
4486
  const data = self.q;
3883
4487
  if (typeof arg === "string") {
3884
4488
  data.as || (data.as = arg);
3885
- data.shape = (_a = data.withShapes) == null ? void 0 : _a[arg];
4489
+ const w = (_a = data.withShapes) == null ? void 0 : _a[arg];
4490
+ data.shape = (_b = w == null ? void 0 : w.shape) != null ? _b : emptyObject;
4491
+ data.computeds = w == null ? void 0 : w.computeds;
3886
4492
  } else if (isExpression(arg)) {
3887
4493
  data.as || (data.as = "t");
3888
4494
  } else if (Array.isArray(arg)) {
3889
4495
  const { shape } = data;
3890
- const parsers = (_b = data.parsers) != null ? _b : data.parsers = {};
4496
+ const parsers = (_c = data.parsers) != null ? _c : data.parsers = {};
3891
4497
  for (const item of arg) {
3892
4498
  if (typeof item === "string") {
3893
- const withShape = data.withShapes[item];
3894
- Object.assign(shape, withShape);
3895
- for (const key in withShape) {
3896
- if (withShape[key].parseFn) {
3897
- parsers[key] = withShape[key].parseFn;
4499
+ const w = data.withShapes[item];
4500
+ Object.assign(shape, w.shape);
4501
+ if (w.computeds)
4502
+ data.computeds = __spreadValues$b(__spreadValues$b({}, data.computeds), w.computeds);
4503
+ for (const key in w.shape) {
4504
+ if (w.shape[key].parseFn) {
4505
+ parsers[key] = w.shape[key].parseFn;
3898
4506
  }
3899
4507
  }
3900
4508
  } else if (!isExpression(item)) {
@@ -3907,6 +4515,7 @@ function queryFrom(self, arg) {
3907
4515
  data.as || (data.as = q.q.as || q.table || "t");
3908
4516
  data.shape = getShapeFromSelect(arg, true);
3909
4517
  data.parsers = q.q.parsers;
4518
+ data.batchParsers = q.q.batchParsers;
3910
4519
  }
3911
4520
  data.from = arg;
3912
4521
  return self;
@@ -4016,44 +4625,117 @@ function queryJson(self, coalesce) {
4016
4625
  const pushSelectSql = (ctx, table, query, quotedAs) => {
4017
4626
  ctx.sql.push(selectToSql(ctx, table, query, quotedAs));
4018
4627
  };
4019
- const selectToSql = (ctx, table, query, quotedAs) => {
4628
+ const selectToSql = (ctx, table, query, quotedAs, hookSelect = query.hookSelect) => {
4629
+ var _a, _b;
4630
+ let selected;
4631
+ const list = [];
4020
4632
  if (query.select) {
4021
- const list = [];
4022
4633
  for (const item of query.select) {
4023
4634
  if (typeof item === "string") {
4024
- list.push(selectedStringToSQL(ctx, table, query, quotedAs, item));
4025
- } else if ("selectAs" in item) {
4026
- const obj = item.selectAs;
4027
- for (const as in obj) {
4028
- const value = obj[as];
4029
- if (typeof value === "object" || typeof value === "function") {
4030
- if (isExpression(value)) {
4031
- list.push(`${value.toSQL(ctx, quotedAs)} "${as}"`);
4032
- } else {
4033
- pushSubQuerySql(ctx, value, as, list, quotedAs);
4635
+ let sql;
4636
+ if (item === "*") {
4637
+ if (hookSelect) {
4638
+ selected != null ? selected : selected = {};
4639
+ for (const key in table.internal.columnsKeysForSelectAll || query.shape) {
4640
+ selected[key] = quotedAs;
4034
4641
  }
4035
- } else {
4036
- list.push(
4037
- `${columnToSql(
4038
- ctx,
4039
- table.q,
4040
- table.q.shape,
4041
- value,
4042
- quotedAs,
4043
- true
4044
- )} "${as}"`
4642
+ }
4643
+ sql = selectAllSql(table, query, quotedAs);
4644
+ } else {
4645
+ const index = item.indexOf(".");
4646
+ if (index !== -1) {
4647
+ const tableName = item.slice(0, index);
4648
+ const key = item.slice(index + 1);
4649
+ if (hookSelect == null ? void 0 : hookSelect.get(key))
4650
+ (selected != null ? selected : selected = {})[key] = `"${tableName}"`;
4651
+ sql = tableColumnToSqlWithAs(
4652
+ ctx,
4653
+ table.q,
4654
+ item,
4655
+ tableName,
4656
+ key,
4657
+ quotedAs,
4658
+ true
4045
4659
  );
4660
+ } else {
4661
+ if (hookSelect == null ? void 0 : hookSelect.get(item))
4662
+ (selected != null ? selected : selected = {})[item] = quotedAs;
4663
+ sql = ownColumnToSqlWithAs(ctx, table.q, item, quotedAs, true);
4664
+ }
4665
+ }
4666
+ list.push(sql);
4667
+ } else if (item) {
4668
+ if ("selectAs" in item) {
4669
+ const obj = item.selectAs;
4670
+ for (const as in obj) {
4671
+ if (hookSelect)
4672
+ (selected != null ? selected : selected = {})[as] = true;
4673
+ const value = obj[as];
4674
+ if (typeof value === "object") {
4675
+ if (isExpression(value)) {
4676
+ list.push(`${value.toSQL(ctx, quotedAs)} "${as}"`);
4677
+ } else {
4678
+ pushSubQuerySql(ctx, value, as, list, quotedAs);
4679
+ }
4680
+ } else if (value) {
4681
+ list.push(
4682
+ `${columnToSql(
4683
+ ctx,
4684
+ table.q,
4685
+ table.q.shape,
4686
+ value,
4687
+ quotedAs,
4688
+ true
4689
+ )} "${as}"`
4690
+ );
4691
+ }
4046
4692
  }
4693
+ } else {
4694
+ list.push(selectedObjectToSQL(ctx, quotedAs, item));
4047
4695
  }
4696
+ }
4697
+ }
4698
+ }
4699
+ if (hookSelect) {
4700
+ for (const column of hookSelect.keys()) {
4701
+ const item = hookSelect.get(column);
4702
+ const { select } = item;
4703
+ let sql;
4704
+ let quotedTable;
4705
+ let columnName;
4706
+ let col;
4707
+ const index = select.indexOf(".");
4708
+ if (index !== -1) {
4709
+ const tableName = select.slice(0, index);
4710
+ quotedTable = `"${tableName}"`;
4711
+ columnName = select.slice(index + 1);
4712
+ col = (_b = (_a = table.q.joinedShapes) == null ? void 0 : _a[tableName]) == null ? void 0 : _b[columnName];
4713
+ sql = (col == null ? void 0 : col.data.computed) ? col.data.computed.toSQL(ctx, `"${tableName}"`) : `"${tableName}"."${(col == null ? void 0 : col.data.name) || columnName}"`;
4048
4714
  } else {
4049
- list.push(selectedObjectToSQL(ctx, quotedAs, item));
4715
+ quotedTable = quotedAs;
4716
+ columnName = select;
4717
+ col = query.shape[select];
4718
+ sql = simpleColumnToSQL(ctx, select, col, quotedAs);
4719
+ }
4720
+ if (selected == null ? void 0 : selected[columnName]) {
4721
+ if ((selected == null ? void 0 : selected[columnName]) === quotedTable) {
4722
+ hookSelect.delete(column);
4723
+ continue;
4724
+ }
4725
+ let i = 2;
4726
+ let name;
4727
+ while (selected[name = `${column}${i}`])
4728
+ i++;
4729
+ item.as = name;
4730
+ sql += ` "${name}"`;
4731
+ } else if (col == null ? void 0 : col.data.name) {
4732
+ sql += ` "${columnName}"`;
4050
4733
  }
4734
+ list.push(sql);
4051
4735
  }
4052
- return list.join(", ");
4053
4736
  }
4054
- return selectAllSql(table, query, quotedAs);
4737
+ return list.length ? list.join(", ") : selectAllSql(table, query, quotedAs);
4055
4738
  };
4056
- const selectedStringToSQL = (ctx, table, query, quotedAs, item) => item === "*" ? selectAllSql(table, query, quotedAs) : columnToSqlWithAs(ctx, table.q, item, quotedAs, true);
4057
4739
  function selectedObjectToSQL(ctx, quotedAs, item) {
4058
4740
  const sql = item.toSQL(ctx, quotedAs);
4059
4741
  return ctx.aliasValue ? `${sql} r` : sql;
@@ -4063,7 +4745,7 @@ const selectAllSql = (table, query, quotedAs) => {
4063
4745
  return ((_a = query.join) == null ? void 0 : _a.length) ? ((_b = table.internal.columnsForSelectAll) == null ? void 0 : _b.map((item) => `${quotedAs}.${item}`).join(", ")) || `${quotedAs}.*` : ((_c = table.internal.columnsForSelectAll) == null ? void 0 : _c.join(", ")) || "*";
4064
4746
  };
4065
4747
  const pushSubQuerySql = (ctx, query, as, list, quotedAs) => {
4066
- var _a;
4748
+ var _a, _b, _c;
4067
4749
  const { returnType = "all" } = query.q;
4068
4750
  if (isQueryNone(query)) {
4069
4751
  let sql;
@@ -4127,20 +4809,27 @@ const pushSubQuerySql = (ctx, query, as, list, quotedAs) => {
4127
4809
  case "pluck": {
4128
4810
  const { select } = query.q;
4129
4811
  const first = select == null ? void 0 : select[0];
4130
- if (!select || !first) {
4812
+ if (!first && ((_b = query.q.computeds) == null ? void 0 : _b[as])) {
4813
+ query = queryJson(query);
4814
+ } else if (!first) {
4131
4815
  throw new OrchidOrmInternalError(
4132
4816
  query,
4133
4817
  `Nothing was selected for pluck`
4134
4818
  );
4819
+ } else {
4820
+ const cloned = query.clone();
4821
+ cloned.q.select = [{ selectAs: { c: first } }];
4822
+ query = queryWrap(cloned, cloned.baseQuery.clone());
4823
+ _queryGetOptional(query, new RawSQL(`COALESCE(json_agg("c"), '[]')`));
4135
4824
  }
4136
- const cloned = query.clone();
4137
- cloned.q.select = [{ selectAs: { c: first } }];
4138
- query = queryWrap(cloned, cloned.baseQuery.clone());
4139
- _queryGetOptional(query, new RawSQL(`COALESCE(json_agg("c"), '[]')`));
4140
4825
  break;
4141
4826
  }
4142
4827
  case "value":
4143
4828
  case "valueOrThrow":
4829
+ if ((_c = query.q.computeds) == null ? void 0 : _c[as]) {
4830
+ query = queryJson(query);
4831
+ }
4832
+ break;
4144
4833
  case "rows":
4145
4834
  case "rowCount":
4146
4835
  case "void":
@@ -4642,42 +5331,22 @@ const encodeRow = (ctx, values, q, QueryClass, row, runtimeDefaults, quotedAs) =
4642
5331
  };
4643
5332
  const pushReturningSql = (ctx, q, data, quotedAs, hookSelect, keyword = "RETURNING") => {
4644
5333
  const { select } = data;
4645
- if (!(hookSelect == null ? void 0 : hookSelect.length) && !select)
4646
- return hookSelect;
4647
- let selected;
4648
- let hookFiltered;
4649
- if (select) {
4650
- selected = selectToSql(ctx, q, data, quotedAs);
5334
+ if (!(hookSelect == null ? void 0 : hookSelect.size) && !select)
5335
+ return hookSelect && /* @__PURE__ */ new Map();
5336
+ ctx.sql.push(keyword);
5337
+ if (q.q.hookSelect || hookSelect) {
5338
+ const tempSelect = new Map(q.q.hookSelect);
4651
5339
  if (hookSelect) {
4652
- if (select.includes("*")) {
4653
- hookFiltered = emptyArray;
4654
- } else {
4655
- hookFiltered = [];
4656
- for (const column of hookSelect) {
4657
- if (!hookFiltered.includes(column) && !(select == null ? void 0 : select.includes(column)) && !(select == null ? void 0 : select.includes(`${quotedAs}.${column}`))) {
4658
- hookFiltered.push(column);
4659
- }
4660
- }
5340
+ for (const column of hookSelect) {
5341
+ tempSelect.set(column, { select: column });
4661
5342
  }
4662
5343
  }
4663
- } else {
4664
- hookFiltered = [];
4665
- for (const column of hookSelect) {
4666
- if (!hookFiltered.includes(column))
4667
- hookFiltered.push(column);
4668
- }
4669
- }
4670
- ctx.sql.push(keyword);
4671
- if (hookFiltered == null ? void 0 : hookFiltered.length) {
4672
- if (selected)
4673
- ctx.sql.push(`${selected},`);
4674
- ctx.sql.push(
4675
- hookFiltered.map((column) => ownColumnToSql(data, column, quotedAs)).join(", ")
4676
- );
4677
- } else {
4678
- ctx.sql.push(selected);
5344
+ ctx.sql.push(selectToSql(ctx, q, data, quotedAs, tempSelect));
5345
+ return tempSelect;
5346
+ } else if (select) {
5347
+ ctx.sql.push(selectToSql(ctx, q, data, quotedAs));
4679
5348
  }
4680
- return hookFiltered;
5349
+ return;
4681
5350
  };
4682
5351
 
4683
5352
  const pushUpdateSql = (ctx, table, query, quotedAs) => {
@@ -5043,7 +5712,7 @@ const makeSQL = (table, options) => {
5043
5712
  if (query.for.mode)
5044
5713
  sql.push(query.for.mode);
5045
5714
  }
5046
- return { text: sql.join(" "), values };
5715
+ return { text: sql.join(" "), values, hookSelect: query.hookSelect };
5047
5716
  };
5048
5717
  function pushLimitSQL(sql, values, q) {
5049
5718
  if (!q.returnsOne) {
@@ -5076,6 +5745,8 @@ const cloneQuery = (q) => {
5076
5745
  q.with = q.with.slice(0);
5077
5746
  if (q.select)
5078
5747
  q.select = q.select.slice(0);
5748
+ if (q.hookSelect)
5749
+ q.hookSelect = new Map(q.hookSelect);
5079
5750
  if (q.and)
5080
5751
  q.and = q.and.slice(0);
5081
5752
  if (q.or)
@@ -5086,8 +5757,16 @@ const cloneQuery = (q) => {
5086
5757
  q.after = q.after.slice(0);
5087
5758
  if (q.joinedShapes)
5088
5759
  q.joinedShapes = __spreadValues$a({}, q.joinedShapes);
5760
+ if (q.joinedComputeds)
5761
+ q.joinedComputeds = __spreadValues$a({}, q.joinedComputeds);
5762
+ if (q.batchParsers)
5763
+ q.batchParsers = [...q.batchParsers];
5764
+ if (q.joinedBatchParsers)
5765
+ q.joinedBatchParsers = __spreadValues$a({}, q.joinedBatchParsers);
5089
5766
  if (q.scopes)
5090
5767
  q.scopes = __spreadValues$a({}, q.scopes);
5768
+ if (q.parsers)
5769
+ q.parsers = __spreadValues$a({}, q.parsers);
5091
5770
  if (q.updateData) {
5092
5771
  q.updateData = q.updateData.slice(
5093
5772
  0
@@ -5120,7 +5799,7 @@ const cloneQuery = (q) => {
5120
5799
  if (q.afterCreate) {
5121
5800
  q.afterCreate = q.afterCreate.slice(0);
5122
5801
  if (q.afterCreateSelect) {
5123
- q.afterCreateSelect = q.afterCreateSelect.slice(0);
5802
+ q.afterCreateSelect = new Set(q.afterCreateSelect);
5124
5803
  }
5125
5804
  }
5126
5805
  } else if (q.type === "update") {
@@ -5129,7 +5808,7 @@ const cloneQuery = (q) => {
5129
5808
  if (q.afterUpdate) {
5130
5809
  q.afterUpdate = q.afterUpdate.slice(0);
5131
5810
  if (q.afterUpdateSelect) {
5132
- q.afterUpdateSelect = q.afterUpdateSelect.slice(0);
5811
+ q.afterUpdateSelect = new Set(q.afterUpdateSelect);
5133
5812
  }
5134
5813
  }
5135
5814
  } else if (q.type === "delete") {
@@ -5138,7 +5817,7 @@ const cloneQuery = (q) => {
5138
5817
  if (q.afterDelete) {
5139
5818
  q.afterDelete = q.afterDelete.slice(0);
5140
5819
  if (q.afterDeleteSelect) {
5141
- q.afterDeleteSelect = q.afterDeleteSelect.slice(0);
5820
+ q.afterDeleteSelect = new Set(q.afterDeleteSelect);
5142
5821
  }
5143
5822
  }
5144
5823
  }
@@ -5163,8 +5842,6 @@ var __spreadValues$9 = (a, b) => {
5163
5842
  const getClonedQueryData = (query) => {
5164
5843
  const cloned = __spreadValues$9({}, query);
5165
5844
  delete cloned[toSQLCacheKey];
5166
- if (cloned.parsers)
5167
- cloned.parsers = __spreadValues$9({}, cloned.parsers);
5168
5845
  cloneQuery(cloned);
5169
5846
  return cloned;
5170
5847
  };
@@ -5369,12 +6046,14 @@ class VirtualColumn extends ColumnType {
5369
6046
  }
5370
6047
  }
5371
6048
 
5372
- class UnknownColumn extends VirtualColumn {
6049
+ const _UnknownColumn = class extends VirtualColumn {
5373
6050
  constructor(schema) {
5374
6051
  super(schema, schema.unknown());
5375
6052
  }
5376
- }
5377
- RawSQL.prototype.result = { value: new UnknownColumn(defaultSchemaConfig) };
6053
+ };
6054
+ let UnknownColumn = _UnknownColumn;
6055
+ UnknownColumn.instance = new _UnknownColumn(defaultSchemaConfig);
6056
+ RawSQL.prototype.result = { value: UnknownColumn.instance };
5378
6057
 
5379
6058
  const makeColumnsByType = (schema) => {
5380
6059
  const t = makeColumnTypes(schema);
@@ -6423,7 +7102,7 @@ const insert = (self, {
6423
7102
  q.values = values;
6424
7103
  if (!q.kind)
6425
7104
  q.kind = kind;
6426
- const { select, returnType = "all" } = q;
7105
+ const { select, returnType } = q;
6427
7106
  if (!select) {
6428
7107
  if (returnType !== "void")
6429
7108
  q.returnType = "rowCount";
@@ -6433,7 +7112,7 @@ const insert = (self, {
6433
7112
  } else if (returnType === "value" || returnType === "valueOrThrow") {
6434
7113
  q.returnType = "pluck";
6435
7114
  }
6436
- } else if (returnType === "all") {
7115
+ } else if (!returnType || returnType === "all") {
6437
7116
  q.returnType = "from" in values ? values.from.q.returnType : "one";
6438
7117
  } else if (returnType === "pluck") {
6439
7118
  q.returnType = "valueOrThrow";
@@ -6452,7 +7131,7 @@ const getFromSelectColumns = (from, obj, many) => {
6452
7131
  if (typeof item === "string") {
6453
7132
  const index = item.indexOf(".");
6454
7133
  queryColumns.push(index === -1 ? item : item.slice(index + 1));
6455
- } else if ("selectAs" in item) {
7134
+ } else if (item && "selectAs" in item) {
6456
7135
  queryColumns.push(...Object.keys(item.selectAs));
6457
7136
  }
6458
7137
  });
@@ -6496,12 +7175,7 @@ const _queryCreateMany = (q, data) => {
6496
7175
  };
6497
7176
  const _queryInsertMany = (q, data) => {
6498
7177
  const ctx = createCtx();
6499
- let result = insert(
6500
- q,
6501
- handleManyData(q, data, ctx),
6502
- "object",
6503
- true
6504
- );
7178
+ let result = insert(q, handleManyData(q, data, ctx), "object", true);
6505
7179
  if (!data.length)
6506
7180
  result = result.none();
6507
7181
  return result;
@@ -7314,11 +7988,15 @@ class Having {
7314
7988
  }
7315
7989
 
7316
7990
  const before = (q, key, cb) => pushQueryValue(q, `before${key}`, cb);
7317
- const after = (q, key, select, cb, commit) => pushQueryArray(
7318
- pushQueryValue(q, `after${key}${commit ? "Commit" : ""}`, cb),
7319
- `after${key}Select`,
7320
- select
7321
- );
7991
+ const after = (q, key, select, cb, commit) => {
7992
+ var _a, _b, _c;
7993
+ pushQueryValue(q, `after${key}${commit ? "Commit" : ""}`, cb);
7994
+ const set = (_c = (_a = q.q)[_b = `after${key}Select`]) != null ? _c : _a[_b] = /* @__PURE__ */ new Set();
7995
+ for (const column of select) {
7996
+ set.add(column);
7997
+ }
7998
+ return q;
7999
+ };
7322
8000
  const _queryHookBeforeQuery = (q, cb) => {
7323
8001
  return pushQueryValue(q, "before", cb);
7324
8002
  };
@@ -8379,7 +9057,9 @@ const mergableObjects = {
8379
9057
  parsers: true,
8380
9058
  defaults: true,
8381
9059
  joinedShapes: true,
8382
- joinedParsers: true
9060
+ joinedParsers: true,
9061
+ joinedBatchParsers: true,
9062
+ selectedComputeds: true
8383
9063
  };
8384
9064
  class MergeQueryMethods {
8385
9065
  merge(q) {
@@ -8404,6 +9084,8 @@ class MergeQueryMethods {
8404
9084
  b: a[key].b,
8405
9085
  u: [...a[key].u, ...value.u]
8406
9086
  } : value;
9087
+ } else if (value instanceof Set) {
9088
+ a[key] = a[key] ? /* @__PURE__ */ new Set([...a[key], ...value]) : value;
8407
9089
  } else {
8408
9090
  a[key] = value;
8409
9091
  }
@@ -8598,7 +9280,10 @@ class WithMethods {
8598
9280
  }
8599
9281
  pushQueryValue(q, "with", { n: name, o: options, q: query });
8600
9282
  const shape = getShapeFromSelect(query, true);
8601
- return setQueryObjectValue(q, "withShapes", name, shape);
9283
+ return setQueryObjectValue(q, "withShapes", name, {
9284
+ shape,
9285
+ computeds: query.q.computeds
9286
+ });
8602
9287
  }
8603
9288
  withRecursive(name, ...args) {
8604
9289
  var _a, _b, _c;
@@ -8607,10 +9292,9 @@ class WithMethods {
8607
9292
  const arg = q.queryBuilder.clone();
8608
9293
  arg.q.withShapes = q.q.withShapes;
8609
9294
  let query = typeof baseFn === "function" ? baseFn(arg) : baseFn;
8610
- const shape = ((_b = (_a = arg.q).withShapes) != null ? _b : _a.withShapes = {})[name] = getShapeFromSelect(
8611
- query,
8612
- true
8613
- );
9295
+ const shape = getShapeFromSelect(query, true);
9296
+ const withConfig = { shape, computeds: query.q.computeds };
9297
+ ((_b = (_a = arg.q).withShapes) != null ? _b : _a.withShapes = {})[name] = withConfig;
8614
9298
  const recursive = recursiveFn(arg);
8615
9299
  query = _queryUnion(query, [recursive], (_c = options.union) != null ? _c : "UNION ALL");
8616
9300
  options.recursive = true;
@@ -8620,7 +9304,7 @@ class WithMethods {
8620
9304
  });
8621
9305
  }
8622
9306
  pushQueryValue(q, "with", { n: name, o: options, q: query });
8623
- return setQueryObjectValue(q, "withShapes", name, shape);
9307
+ return setQueryObjectValue(q, "withShapes", name, withConfig);
8624
9308
  }
8625
9309
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
8626
9310
  withSql(name, ...args) {
@@ -8631,12 +9315,9 @@ class WithMethods {
8631
9315
  o: options,
8632
9316
  s: sql(q)
8633
9317
  });
8634
- return setQueryObjectValue(
8635
- q,
8636
- "withShapes",
8637
- name,
8638
- shape(this.columnTypes)
8639
- );
9318
+ return setQueryObjectValue(q, "withShapes", name, {
9319
+ shape: shape(this.columnTypes)
9320
+ });
8640
9321
  }
8641
9322
  }
8642
9323
 
@@ -10154,12 +10835,9 @@ function orCreate(q, data, updateData, mergeData) {
10154
10835
  if (mergeData)
10155
10836
  data = __spreadValues$1(__spreadValues$1({}, mergeData), data);
10156
10837
  const inner = q2.create(data);
10157
- const { handleResult: handleResult2 } = inner.q;
10158
10838
  inner.q.handleResult = (q3, t, r, s) => {
10159
- queryResult = r;
10160
- const res = handleResult2(q3, t, r, s);
10161
- result = res;
10162
- return res;
10839
+ result = handleResult(q3, t, r, s);
10840
+ return inner.q.hookSelect ? result.map((row) => __spreadValues$1({}, row)) : result;
10163
10841
  };
10164
10842
  await inner;
10165
10843
  created = true;
@@ -10807,8 +11485,13 @@ class QueryMethods {
10807
11485
  pluck(select) {
10808
11486
  const q = this.clone();
10809
11487
  q.q.returnType = "pluck";
10810
- q.q.select = [select];
10811
- addParserForSelectItem(q, q.q.as || q.table, "pluck", select);
11488
+ const selected = addParserForSelectItem(
11489
+ q,
11490
+ q.q.as || q.table,
11491
+ "pluck",
11492
+ select
11493
+ );
11494
+ q.q.select = selected ? [selected] : void 0;
10812
11495
  return q;
10813
11496
  }
10814
11497
  /**
@@ -11560,6 +12243,7 @@ class Db {
11560
12243
  tableData
11561
12244
  };
11562
12245
  this.baseQuery = this;
12246
+ this.relations = {};
11563
12247
  const logger = options.logger || console;
11564
12248
  const parsers = {};
11565
12249
  let hasParsers = false;
@@ -11610,6 +12294,7 @@ class Db {
11610
12294
  );
11611
12295
  }
11612
12296
  this.internal.columnsForSelectAll = list;
12297
+ this.internal.columnsKeysForSelectAll = __spreadValues({}, shape);
11613
12298
  }
11614
12299
  this.q = {
11615
12300
  adapter,
@@ -11648,6 +12333,8 @@ class Db {
11648
12333
  this.defaultSelectColumns = columns.filter(
11649
12334
  (column) => !shape[column].data.isHidden
11650
12335
  );
12336
+ if (options.computed)
12337
+ applyComputedColumns(this, options.computed);
11651
12338
  const defaultSelect = this.defaultSelectColumns.length === columns.length ? void 0 : this.defaultSelectColumns;
11652
12339
  this.toSQL = defaultSelect ? function(options2) {
11653
12340
  const q = this.clone();
@@ -11656,7 +12343,6 @@ class Db {
11656
12343
  }
11657
12344
  return toSQL.call(q, options2);
11658
12345
  } : toSQL;
11659
- this.relations = {};
11660
12346
  if (modifyQuery) {
11661
12347
  for (const cb of modifyQuery) {
11662
12348
  cb(this);
@@ -11954,16 +12640,6 @@ const testTransaction = {
11954
12640
  }
11955
12641
  };
11956
12642
 
11957
- function addComputedColumns(q, computed) {
11958
- const { shape } = q;
11959
- for (const key in computed) {
11960
- const expr = computed[key](q);
11961
- shape[key] = expr.result.value;
11962
- expr.result.value.data.computed = expr;
11963
- }
11964
- return q;
11965
- }
11966
-
11967
12643
  const rowToColumnInfo = (row) => {
11968
12644
  const typed = row;
11969
12645
  return {
@@ -12003,5 +12679,5 @@ function copyTableData(query, arg) {
12003
12679
  return q;
12004
12680
  }
12005
12681
 
12006
- export { Adapter, AggregateMethods, ArrayColumn, AsMethods, BigIntColumn, BigSerialColumn, BitColumn, BitVaryingColumn, BooleanColumn, BoxColumn, ByteaColumn, CidrColumn, CircleColumn, CitextColumn, Clear, ColumnRefExpression, ColumnType, Create, CustomTypeColumn, DateBaseColumn, DateColumn, DateTimeBaseClass, DateTimeTzBaseClass, Db, DecimalColumn, Delete, DomainColumn, DoublePrecisionColumn, DynamicRawSQL, EnumColumn, ExpressionMethods, FnExpression, For, FromMethods, Having, InetColumn, IntegerBaseColumn, IntegerColumn, IntervalColumn, JSONColumn, JSONTextColumn, Join, JsonMethods, LimitedTextBaseColumn, LineColumn, LsegColumn, MacAddr8Column, MacAddrColumn, MergeQueryMethods, MoneyColumn, MoreThanOneRowError, NotFoundError, NumberAsStringBaseColumn, NumberBaseColumn, OnConflictQueryBuilder, OnMethods, Operators, OrExpression, OrchidOrmError, OrchidOrmInternalError, PathColumn, PointColumn, PolygonColumn, QueryBase, QueryError, QueryGet, QueryHooks, QueryLog, QueryMethods, QueryUpsertOrCreate, RawSQL, RealColumn, RefExpression, SearchMethods, Select, SerialColumn, SmallIntColumn, SmallSerialColumn, SqlMethod, StringColumn, TextBaseColumn, TextColumn, Then, TimeColumn, TimestampColumn, TimestampTZColumn, Transaction, TransactionAdapter, TransformMethods, TsQueryColumn, TsVectorColumn, UUIDColumn, UnhandledTypeError, Union, UnknownColumn, Update, VarCharColumn, VirtualColumn, Where, WithMethods, XMLColumn, _initQueryBuilder, _queryAfterSaveCommit, _queryAll, _queryAs, _queryChangeCounter, _queryCreate, _queryCreateFrom, _queryCreateMany, _queryCreateManyFrom, _queryCreateManyRaw, _queryCreateRaw, _queryDefaults, _queryDelete, _queryExec, _queryFindBy, _queryFindByOptional, _queryGet, _queryGetOptional, _queryHookAfterCreate, _queryHookAfterCreateCommit, _queryHookAfterDelete, _queryHookAfterDeleteCommit, _queryHookAfterQuery, _queryHookAfterSave, _queryHookAfterUpdate, _queryHookAfterUpdateCommit, _queryHookBeforeCreate, _queryHookBeforeDelete, _queryHookBeforeQuery, _queryHookBeforeSave, _queryHookBeforeUpdate, _queryInsert, _queryInsertFrom, _queryInsertMany, _queryInsertManyFrom, _queryInsertManyRaw, _queryInsertRaw, _queryJoinOn, _queryJoinOnJsonPathEquals, _queryJoinOrOn, _queryOr, _queryOrNot, _queryRows, _querySelect, _queryTake, _queryTakeOptional, _queryUnion, _queryUpdate, _queryUpdateOrThrow, _queryUpdateRaw, _queryWhere, _queryWhereExists, _queryWhereIn, _queryWhereNot, _queryWhereNotSql, _queryWhereSql, addComputedColumns, addParserForRawExpression, addParserForSelectItem, addQueryOn, anyShape, checkIfASimpleQuery, cloneQuery, cloneQueryBaseUnscoped, columnCheckToCode, columnCode, columnForeignKeysToCode, columnIndexesToCode, columnsShapeToCode, commitSql$1 as commitSql, constraintInnerToCode, constraintToCode, copyTableData, countSelect, createDb, defaultSchemaConfig, extendQuery, foreignKeyArgumentToCode, getClonedQueryData, getColumnInfo, getColumnTypes, getPrimaryKeys, getQueryAs, getShapeFromSelect, getSqlText, handleResult, identityToCode, indexInnerToCode, indexToCode, instantiateColumn, isDefaultTimeStamp, isQueryReturnsAll, isSelectingCount, joinSubQuery, logColors, logParamToLogObject, makeColumnTypes, makeColumnsByType, makeFnExpression, makeRegexToFindInSql, makeSQL, parseRecord, parseResult, parseTableData, parseTableDataInput, primaryKeyInnerToCode, processSelectArg, pushLimitSQL, pushQueryArray, pushQueryOn, pushQueryOrOn, pushQueryValue, pushTableDataCode, queryFrom, queryFromSql, queryJson, queryMethodByReturnType, queryTypeWithLimitOne, queryWrap, quote, quoteString, raw, referencesArgsToCode, resolveSubQueryCallback, rollbackSql$1 as rollbackSql, saveSearchAlias, setParserForSelectedString, setQueryObjectValue, setQueryOperators, simplifyColumnDefault, sqlFn, sqlQueryArgsToExpression, tableDataMethods, templateLiteralToSQL, testTransaction, throwIfNoWhere, toSQL, toSQLCacheKey };
12682
+ export { Adapter, AggregateMethods, ArrayColumn, AsMethods, BigIntColumn, BigSerialColumn, BitColumn, BitVaryingColumn, BooleanColumn, BoxColumn, ByteaColumn, CidrColumn, CircleColumn, CitextColumn, Clear, ColumnRefExpression, ColumnType, ComputedColumn, Create, CustomTypeColumn, DateBaseColumn, DateColumn, DateTimeBaseClass, DateTimeTzBaseClass, Db, DecimalColumn, Delete, DomainColumn, DoublePrecisionColumn, DynamicRawSQL, EnumColumn, ExpressionMethods, FnExpression, For, FromMethods, Having, InetColumn, IntegerBaseColumn, IntegerColumn, IntervalColumn, JSONColumn, JSONTextColumn, Join, JsonMethods, LimitedTextBaseColumn, LineColumn, LsegColumn, MacAddr8Column, MacAddrColumn, MergeQueryMethods, MoneyColumn, MoreThanOneRowError, NotFoundError, NumberAsStringBaseColumn, NumberBaseColumn, OnConflictQueryBuilder, OnMethods, Operators, OrExpression, OrchidOrmError, OrchidOrmInternalError, PathColumn, PointColumn, PolygonColumn, QueryBase, QueryError, QueryGet, QueryHooks, QueryLog, QueryMethods, QueryUpsertOrCreate, RawSQL, RealColumn, RefExpression, SearchMethods, Select, SerialColumn, SmallIntColumn, SmallSerialColumn, SqlMethod, StringColumn, TextBaseColumn, TextColumn, Then, TimeColumn, TimestampColumn, TimestampTZColumn, Transaction, TransactionAdapter, TransformMethods, TsQueryColumn, TsVectorColumn, UUIDColumn, UnhandledTypeError, Union, UnknownColumn, Update, VarCharColumn, VirtualColumn, Where, WithMethods, XMLColumn, _initQueryBuilder, _queryAfterSaveCommit, _queryAll, _queryAs, _queryChangeCounter, _queryCreate, _queryCreateFrom, _queryCreateMany, _queryCreateManyFrom, _queryCreateManyRaw, _queryCreateRaw, _queryDefaults, _queryDelete, _queryExec, _queryFindBy, _queryFindByOptional, _queryGet, _queryGetOptional, _queryHookAfterCreate, _queryHookAfterCreateCommit, _queryHookAfterDelete, _queryHookAfterDeleteCommit, _queryHookAfterQuery, _queryHookAfterSave, _queryHookAfterUpdate, _queryHookAfterUpdateCommit, _queryHookBeforeCreate, _queryHookBeforeDelete, _queryHookBeforeQuery, _queryHookBeforeSave, _queryHookBeforeUpdate, _queryInsert, _queryInsertFrom, _queryInsertMany, _queryInsertManyFrom, _queryInsertManyRaw, _queryInsertRaw, _queryJoinOn, _queryJoinOnJsonPathEquals, _queryJoinOrOn, _queryOr, _queryOrNot, _queryRows, _querySelect, _queryTake, _queryTakeOptional, _queryUnion, _queryUpdate, _queryUpdateOrThrow, _queryUpdateRaw, _queryWhere, _queryWhereExists, _queryWhereIn, _queryWhereNot, _queryWhereNotSql, _queryWhereSql, addParserForRawExpression, addParserForSelectItem, addQueryOn, anyShape, applyComputedColumns, checkIfASimpleQuery, cloneQuery, cloneQueryBaseUnscoped, columnCheckToCode, columnCode, columnForeignKeysToCode, columnIndexesToCode, columnsShapeToCode, commitSql$1 as commitSql, constraintInnerToCode, constraintToCode, copyTableData, countSelect, createDb, defaultSchemaConfig, extendQuery, filterResult, foreignKeyArgumentToCode, getClonedQueryData, getColumnInfo, getColumnTypes, getPrimaryKeys, getQueryAs, getShapeFromSelect, getSqlText, handleResult, identityToCode, indexInnerToCode, indexToCode, instantiateColumn, isDefaultTimeStamp, isQueryReturnsAll, isSelectingCount, joinSubQuery, logColors, logParamToLogObject, makeColumnTypes, makeColumnsByType, makeFnExpression, makeRegexToFindInSql, makeSQL, parseRecord, parseTableData, parseTableDataInput, primaryKeyInnerToCode, processComputedBatches, processComputedResult, processSelectArg, pushLimitSQL, pushQueryArray, pushQueryOn, pushQueryOrOn, pushQueryValue, pushTableDataCode, queryFrom, queryFromSql, queryJson, queryMethodByReturnType, queryTypeWithLimitOne, queryWrap, quote, quoteString, raw, referencesArgsToCode, resolveSubQueryCallback, rollbackSql$1 as rollbackSql, saveSearchAlias, setParserForSelectedString, setQueryObjectValue, setQueryOperators, simplifyColumnDefault, sqlFn, sqlQueryArgsToExpression, tableDataMethods, templateLiteralToSQL, testTransaction, throwIfNoWhere, toSQL, toSQLCacheKey };
12007
12683
  //# sourceMappingURL=index.mjs.map