pqb 0.11.19 → 0.11.21

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
@@ -3,21 +3,21 @@ import pg from 'pg';
3
3
  import { inspect } from 'util';
4
4
  import { AsyncLocalStorage } from 'node:async_hooks';
5
5
 
6
- var __defProp$g = Object.defineProperty;
6
+ var __defProp$f = Object.defineProperty;
7
7
  var __defProps$a = Object.defineProperties;
8
8
  var __getOwnPropDescs$a = Object.getOwnPropertyDescriptors;
9
- var __getOwnPropSymbols$h = Object.getOwnPropertySymbols;
10
- var __hasOwnProp$h = Object.prototype.hasOwnProperty;
11
- var __propIsEnum$h = Object.prototype.propertyIsEnumerable;
12
- var __defNormalProp$g = (obj, key, value) => key in obj ? __defProp$g(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
13
- var __spreadValues$g = (a, b) => {
9
+ var __getOwnPropSymbols$g = Object.getOwnPropertySymbols;
10
+ var __hasOwnProp$g = Object.prototype.hasOwnProperty;
11
+ var __propIsEnum$g = Object.prototype.propertyIsEnumerable;
12
+ var __defNormalProp$f = (obj, key, value) => key in obj ? __defProp$f(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
13
+ var __spreadValues$f = (a, b) => {
14
14
  for (var prop in b || (b = {}))
15
- if (__hasOwnProp$h.call(b, prop))
16
- __defNormalProp$g(a, prop, b[prop]);
17
- if (__getOwnPropSymbols$h)
18
- for (var prop of __getOwnPropSymbols$h(b)) {
19
- if (__propIsEnum$h.call(b, prop))
20
- __defNormalProp$g(a, prop, b[prop]);
15
+ if (__hasOwnProp$g.call(b, prop))
16
+ __defNormalProp$f(a, prop, b[prop]);
17
+ if (__getOwnPropSymbols$g)
18
+ for (var prop of __getOwnPropSymbols$g(b)) {
19
+ if (__propIsEnum$g.call(b, prop))
20
+ __defNormalProp$f(a, prop, b[prop]);
21
21
  }
22
22
  return a;
23
23
  };
@@ -35,7 +35,7 @@ const simplifyColumnDefault = (value) => {
35
35
  };
36
36
  const instantiateColumn = (klass, params) => {
37
37
  const column = new klass();
38
- Object.assign(column.data, __spreadProps$a(__spreadValues$g({}, params), {
38
+ Object.assign(column.data, __spreadProps$a(__spreadValues$f({}, params), {
39
39
  default: simplifyColumnDefault(params.default)
40
40
  }));
41
41
  return column;
@@ -49,7 +49,7 @@ class ColumnType extends ColumnTypeBase {
49
49
  );
50
50
  }
51
51
  foreignKey(fnOrTable, column, options = {}) {
52
- const item = typeof fnOrTable === "string" ? __spreadValues$g({ table: fnOrTable, columns: [column] }, options) : __spreadValues$g({ fn: fnOrTable, columns: [column] }, options);
52
+ const item = typeof fnOrTable === "string" ? __spreadValues$f({ table: fnOrTable, columns: [column] }, options) : __spreadValues$f({ fn: fnOrTable, columns: [column] }, options);
53
53
  return pushColumnData(this, "foreignKeys", item);
54
54
  }
55
55
  hidden() {
@@ -76,7 +76,7 @@ class ColumnType extends ColumnTypeBase {
76
76
  return pushColumnData(this, "indexes", options);
77
77
  }
78
78
  unique(options = {}) {
79
- return pushColumnData(this, "indexes", __spreadProps$a(__spreadValues$g({}, options), { unique: true }));
79
+ return pushColumnData(this, "indexes", __spreadProps$a(__spreadValues$f({}, options), { unique: true }));
80
80
  }
81
81
  comment(comment) {
82
82
  return setColumnData(this, "comment", comment);
@@ -107,8 +107,8 @@ class ColumnType extends ColumnTypeBase {
107
107
  const cloned = Object.create(this);
108
108
  cloned.chain = [...this.chain, ["refine", check, cloned]];
109
109
  if (typeof params === "string" || (params == null ? void 0 : params.message)) {
110
- cloned.data = __spreadProps$a(__spreadValues$g({}, this.data), {
111
- errors: __spreadProps$a(__spreadValues$g({}, this.data.errors), {
110
+ cloned.data = __spreadProps$a(__spreadValues$f({}, this.data), {
111
+ errors: __spreadProps$a(__spreadValues$f({}, this.data.errors), {
112
112
  refine: typeof params === "string" ? params : params.message
113
113
  })
114
114
  });
@@ -209,21 +209,21 @@ const addValue = (values, value) => {
209
209
  return `$${values.length}`;
210
210
  };
211
211
 
212
- var __defProp$f = Object.defineProperty;
212
+ var __defProp$e = Object.defineProperty;
213
213
  var __defProps$9 = Object.defineProperties;
214
214
  var __getOwnPropDescs$9 = Object.getOwnPropertyDescriptors;
215
- var __getOwnPropSymbols$g = Object.getOwnPropertySymbols;
216
- var __hasOwnProp$g = Object.prototype.hasOwnProperty;
217
- var __propIsEnum$g = Object.prototype.propertyIsEnumerable;
218
- var __defNormalProp$f = (obj, key, value) => key in obj ? __defProp$f(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
219
- var __spreadValues$f = (a, b) => {
215
+ var __getOwnPropSymbols$f = Object.getOwnPropertySymbols;
216
+ var __hasOwnProp$f = Object.prototype.hasOwnProperty;
217
+ var __propIsEnum$f = Object.prototype.propertyIsEnumerable;
218
+ var __defNormalProp$e = (obj, key, value) => key in obj ? __defProp$e(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
219
+ var __spreadValues$e = (a, b) => {
220
220
  for (var prop in b || (b = {}))
221
- if (__hasOwnProp$g.call(b, prop))
222
- __defNormalProp$f(a, prop, b[prop]);
223
- if (__getOwnPropSymbols$g)
224
- for (var prop of __getOwnPropSymbols$g(b)) {
225
- if (__propIsEnum$g.call(b, prop))
226
- __defNormalProp$f(a, prop, b[prop]);
221
+ if (__hasOwnProp$f.call(b, prop))
222
+ __defNormalProp$e(a, prop, b[prop]);
223
+ if (__getOwnPropSymbols$f)
224
+ for (var prop of __getOwnPropSymbols$f(b)) {
225
+ if (__propIsEnum$f.call(b, prop))
226
+ __defNormalProp$e(a, prop, b[prop]);
227
227
  }
228
228
  return a;
229
229
  };
@@ -311,14 +311,14 @@ const base = () => ({
311
311
  in: all.in(),
312
312
  notIn: all.notIn()
313
313
  });
314
- const numeric = () => __spreadProps$9(__spreadValues$f({}, base()), {
314
+ const numeric = () => __spreadProps$9(__spreadValues$e({}, base()), {
315
315
  lt: all.lt(),
316
316
  lte: all.lte(),
317
317
  gt: all.gt(),
318
318
  gte: all.gte(),
319
319
  between: all.between()
320
320
  });
321
- const text$1 = () => __spreadProps$9(__spreadValues$f({}, base()), {
321
+ const text$1 = () => __spreadProps$9(__spreadValues$e({}, base()), {
322
322
  contains: all.contains(),
323
323
  containsSensitive: all.containsSensitive(),
324
324
  startsWith: all.startsWith(),
@@ -326,7 +326,7 @@ const text$1 = () => __spreadProps$9(__spreadValues$f({}, base()), {
326
326
  endsWith: all.endsWith(),
327
327
  endsWithSensitive: all.endsWithSensitive()
328
328
  });
329
- const json = () => __spreadProps$9(__spreadValues$f({}, base()), {
329
+ const json = () => __spreadProps$9(__spreadValues$e({}, base()), {
330
330
  jsonPath: all.jsonPath(),
331
331
  jsonSupersetOf: all.jsonSupersetOf(),
332
332
  jsonSubsetOf: all.jsonSubsetOf()
@@ -887,21 +887,21 @@ class BigSerialColumn extends NumberAsStringBaseColumn {
887
887
  }
888
888
  }
889
889
 
890
- var __defProp$e = Object.defineProperty;
890
+ var __defProp$d = Object.defineProperty;
891
891
  var __defProps$8 = Object.defineProperties;
892
892
  var __getOwnPropDescs$8 = Object.getOwnPropertyDescriptors;
893
- var __getOwnPropSymbols$f = Object.getOwnPropertySymbols;
894
- var __hasOwnProp$f = Object.prototype.hasOwnProperty;
895
- var __propIsEnum$f = Object.prototype.propertyIsEnumerable;
896
- var __defNormalProp$e = (obj, key, value) => key in obj ? __defProp$e(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
897
- var __spreadValues$e = (a, b) => {
893
+ var __getOwnPropSymbols$e = Object.getOwnPropertySymbols;
894
+ var __hasOwnProp$e = Object.prototype.hasOwnProperty;
895
+ var __propIsEnum$e = Object.prototype.propertyIsEnumerable;
896
+ var __defNormalProp$d = (obj, key, value) => key in obj ? __defProp$d(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
897
+ var __spreadValues$d = (a, b) => {
898
898
  for (var prop in b || (b = {}))
899
- if (__hasOwnProp$f.call(b, prop))
900
- __defNormalProp$e(a, prop, b[prop]);
901
- if (__getOwnPropSymbols$f)
902
- for (var prop of __getOwnPropSymbols$f(b)) {
903
- if (__propIsEnum$f.call(b, prop))
904
- __defNormalProp$e(a, prop, b[prop]);
899
+ if (__hasOwnProp$e.call(b, prop))
900
+ __defNormalProp$d(a, prop, b[prop]);
901
+ if (__getOwnPropSymbols$e)
902
+ for (var prop of __getOwnPropSymbols$e(b)) {
903
+ if (__propIsEnum$e.call(b, prop))
904
+ __defNormalProp$d(a, prop, b[prop]);
905
905
  }
906
906
  return a;
907
907
  };
@@ -963,7 +963,7 @@ const setTextColumnData = (column, minArg, maxArg) => {
963
963
  }
964
964
  };
965
965
  const textColumnToCode = (column, t) => {
966
- const data = __spreadValues$e({}, column.data);
966
+ const data = __spreadValues$d({}, column.data);
967
967
  let args = "";
968
968
  if (data.minArg !== void 0 && data.min === data.minArg) {
969
969
  args += data.minArg;
@@ -1201,7 +1201,7 @@ class UUIDColumn extends ColumnType {
1201
1201
  this,
1202
1202
  t,
1203
1203
  `uuid()`,
1204
- typeof data.default === "object" && data.default.__raw === uuidDefault.__raw ? __spreadProps$8(__spreadValues$e({}, data), { default: void 0 }) : data
1204
+ typeof data.default === "object" && data.default.__raw === uuidDefault.__raw ? __spreadProps$8(__spreadValues$d({}, data), { default: void 0 }) : data
1205
1205
  );
1206
1206
  }
1207
1207
  }
@@ -1385,26 +1385,26 @@ class EnumColumn extends ColumnType {
1385
1385
  }
1386
1386
  }
1387
1387
 
1388
- var __defProp$d = Object.defineProperty;
1388
+ var __defProp$c = Object.defineProperty;
1389
1389
  var __defProps$7 = Object.defineProperties;
1390
1390
  var __getOwnPropDescs$7 = Object.getOwnPropertyDescriptors;
1391
- var __getOwnPropSymbols$e = Object.getOwnPropertySymbols;
1392
- var __hasOwnProp$e = Object.prototype.hasOwnProperty;
1393
- var __propIsEnum$e = Object.prototype.propertyIsEnumerable;
1394
- var __defNormalProp$d = (obj, key, value) => key in obj ? __defProp$d(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1395
- var __spreadValues$d = (a, b) => {
1391
+ var __getOwnPropSymbols$d = Object.getOwnPropertySymbols;
1392
+ var __hasOwnProp$d = Object.prototype.hasOwnProperty;
1393
+ var __propIsEnum$d = Object.prototype.propertyIsEnumerable;
1394
+ var __defNormalProp$c = (obj, key, value) => key in obj ? __defProp$c(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1395
+ var __spreadValues$c = (a, b) => {
1396
1396
  for (var prop in b || (b = {}))
1397
- if (__hasOwnProp$e.call(b, prop))
1398
- __defNormalProp$d(a, prop, b[prop]);
1399
- if (__getOwnPropSymbols$e)
1400
- for (var prop of __getOwnPropSymbols$e(b)) {
1401
- if (__propIsEnum$e.call(b, prop))
1402
- __defNormalProp$d(a, prop, b[prop]);
1397
+ if (__hasOwnProp$d.call(b, prop))
1398
+ __defNormalProp$c(a, prop, b[prop]);
1399
+ if (__getOwnPropSymbols$d)
1400
+ for (var prop of __getOwnPropSymbols$d(b)) {
1401
+ if (__propIsEnum$d.call(b, prop))
1402
+ __defNormalProp$c(a, prop, b[prop]);
1403
1403
  }
1404
1404
  return a;
1405
1405
  };
1406
1406
  var __spreadProps$7 = (a, b) => __defProps$7(a, __getOwnPropDescs$7(b));
1407
- const jsonTypes = __spreadProps$7(__spreadValues$d({
1407
+ const jsonTypes = __spreadProps$7(__spreadValues$c({
1408
1408
  array,
1409
1409
  discriminatedUnion,
1410
1410
  enum: enumType,
@@ -1640,21 +1640,21 @@ const setQueryObjectValue = (q, object, key, value) => {
1640
1640
  return q;
1641
1641
  };
1642
1642
 
1643
- var __defProp$c = Object.defineProperty;
1643
+ var __defProp$b = Object.defineProperty;
1644
1644
  var __defProps$6 = Object.defineProperties;
1645
1645
  var __getOwnPropDescs$6 = Object.getOwnPropertyDescriptors;
1646
- var __getOwnPropSymbols$d = Object.getOwnPropertySymbols;
1647
- var __hasOwnProp$d = Object.prototype.hasOwnProperty;
1648
- var __propIsEnum$d = Object.prototype.propertyIsEnumerable;
1649
- var __defNormalProp$c = (obj, key, value) => key in obj ? __defProp$c(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1650
- var __spreadValues$c = (a, b) => {
1646
+ var __getOwnPropSymbols$c = Object.getOwnPropertySymbols;
1647
+ var __hasOwnProp$c = Object.prototype.hasOwnProperty;
1648
+ var __propIsEnum$c = Object.prototype.propertyIsEnumerable;
1649
+ var __defNormalProp$b = (obj, key, value) => key in obj ? __defProp$b(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1650
+ var __spreadValues$b = (a, b) => {
1651
1651
  for (var prop in b || (b = {}))
1652
- if (__hasOwnProp$d.call(b, prop))
1653
- __defNormalProp$c(a, prop, b[prop]);
1654
- if (__getOwnPropSymbols$d)
1655
- for (var prop of __getOwnPropSymbols$d(b)) {
1656
- if (__propIsEnum$d.call(b, prop))
1657
- __defNormalProp$c(a, prop, b[prop]);
1652
+ if (__hasOwnProp$c.call(b, prop))
1653
+ __defNormalProp$b(a, prop, b[prop]);
1654
+ if (__getOwnPropSymbols$c)
1655
+ for (var prop of __getOwnPropSymbols$c(b)) {
1656
+ if (__propIsEnum$c.call(b, prop))
1657
+ __defNormalProp$b(a, prop, b[prop]);
1658
1658
  }
1659
1659
  return a;
1660
1660
  };
@@ -1682,7 +1682,7 @@ const processJoinItem = (ctx, table, query, item, quotedAs) => {
1682
1682
  }
1683
1683
  const queryData = {
1684
1684
  shape: j.shape,
1685
- joinedShapes: __spreadProps$6(__spreadValues$c(__spreadValues$c({}, query.joinedShapes), j.joinedShapes), {
1685
+ joinedShapes: __spreadProps$6(__spreadValues$b(__spreadValues$b({}, query.joinedShapes), j.joinedShapes), {
1686
1686
  [table.query.as || table.table]: table.shape
1687
1687
  }),
1688
1688
  and: j.and ? [...j.and] : [],
@@ -1747,8 +1747,8 @@ const processJoinItem = (ctx, table, query, item, quotedAs) => {
1747
1747
  const whereSql = whereToSql(
1748
1748
  ctx,
1749
1749
  first,
1750
- __spreadProps$6(__spreadValues$c({}, joinQuery), {
1751
- joinedShapes: __spreadProps$6(__spreadValues$c(__spreadValues$c({}, query.joinedShapes), joinQuery.joinedShapes), {
1750
+ __spreadProps$6(__spreadValues$b({}, joinQuery), {
1751
+ joinedShapes: __spreadProps$6(__spreadValues$b(__spreadValues$b({}, query.joinedShapes), joinQuery.joinedShapes), {
1752
1752
  [table.query.as || table.table]: table.query.shape
1753
1753
  })
1754
1754
  }),
@@ -1769,7 +1769,7 @@ const processArgs = (args, ctx, table, query, first, joinAs, joinShape, quotedAs
1769
1769
  if (args.length === 2) {
1770
1770
  const arg = args[1];
1771
1771
  if (typeof arg === "function") {
1772
- const joinedShapes = __spreadProps$6(__spreadValues$c({}, query.joinedShapes), {
1772
+ const joinedShapes = __spreadProps$6(__spreadValues$b({}, query.joinedShapes), {
1773
1773
  [table.query.as || table.table]: table.shape
1774
1774
  });
1775
1775
  let q2;
@@ -1806,13 +1806,13 @@ const processArgs = (args, ctx, table, query, first, joinAs, joinShape, quotedAs
1806
1806
  pushQueryArray(q2, "or", query2.or);
1807
1807
  }
1808
1808
  }
1809
- data = __spreadProps$6(__spreadValues$c({}, first.query), {
1810
- joinedShapes: __spreadValues$c(__spreadValues$c({}, first.query.joinedShapes), joinedShapes)
1809
+ data = __spreadProps$6(__spreadValues$b({}, first.query), {
1810
+ joinedShapes: __spreadValues$b(__spreadValues$b({}, first.query.joinedShapes), joinedShapes)
1811
1811
  });
1812
1812
  }
1813
1813
  const jq = arg(new ctx.onQueryBuilder(q2, data, table));
1814
1814
  if (jq.query.joinedShapes !== joinedShapes) {
1815
- jq.query.joinedShapes = __spreadValues$c(__spreadValues$c({}, jq.query.joinedShapes), joinedShapes);
1815
+ jq.query.joinedShapes = __spreadValues$b(__spreadValues$b({}, jq.query.joinedShapes), joinedShapes);
1816
1816
  }
1817
1817
  return whereToSql(ctx, jq, jq.query, joinAs);
1818
1818
  } else {
@@ -2131,21 +2131,21 @@ const pushIn = (query, ands, prefix, quotedAs, values, arg) => {
2131
2131
  );
2132
2132
  };
2133
2133
 
2134
- var __defProp$b = Object.defineProperty;
2134
+ var __defProp$a = Object.defineProperty;
2135
2135
  var __defProps$5 = Object.defineProperties;
2136
2136
  var __getOwnPropDescs$5 = Object.getOwnPropertyDescriptors;
2137
- var __getOwnPropSymbols$c = Object.getOwnPropertySymbols;
2138
- var __hasOwnProp$c = Object.prototype.hasOwnProperty;
2139
- var __propIsEnum$c = Object.prototype.propertyIsEnumerable;
2140
- var __defNormalProp$b = (obj, key, value) => key in obj ? __defProp$b(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2141
- var __spreadValues$b = (a, b) => {
2137
+ var __getOwnPropSymbols$b = Object.getOwnPropertySymbols;
2138
+ var __hasOwnProp$b = Object.prototype.hasOwnProperty;
2139
+ var __propIsEnum$b = Object.prototype.propertyIsEnumerable;
2140
+ var __defNormalProp$a = (obj, key, value) => key in obj ? __defProp$a(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2141
+ var __spreadValues$a = (a, b) => {
2142
2142
  for (var prop in b || (b = {}))
2143
- if (__hasOwnProp$c.call(b, prop))
2144
- __defNormalProp$b(a, prop, b[prop]);
2145
- if (__getOwnPropSymbols$c)
2146
- for (var prop of __getOwnPropSymbols$c(b)) {
2147
- if (__propIsEnum$c.call(b, prop))
2148
- __defNormalProp$b(a, prop, b[prop]);
2143
+ if (__hasOwnProp$b.call(b, prop))
2144
+ __defNormalProp$a(a, prop, b[prop]);
2145
+ if (__getOwnPropSymbols$b)
2146
+ for (var prop of __getOwnPropSymbols$b(b)) {
2147
+ if (__propIsEnum$b.call(b, prop))
2148
+ __defNormalProp$a(a, prop, b[prop]);
2149
2149
  }
2150
2150
  return a;
2151
2151
  };
@@ -2153,7 +2153,7 @@ var __spreadProps$5 = (a, b) => __defProps$5(a, __getOwnPropDescs$5(b));
2153
2153
  const aggregateToSql = (ctx, table, item, quotedAs) => {
2154
2154
  var _a;
2155
2155
  const sql = [`${item.function}(`];
2156
- ctx = __spreadProps$5(__spreadValues$b({}, ctx), { sql });
2156
+ ctx = __spreadProps$5(__spreadValues$a({}, ctx), { sql });
2157
2157
  const options = item.options || emptyObject;
2158
2158
  if (options.distinct && !options.withinGroup)
2159
2159
  sql.push("DISTINCT ");
@@ -2628,62 +2628,71 @@ const getFrom = (table, query, values) => {
2628
2628
  return quoteSchemaAndTable(query.schema, table.table);
2629
2629
  };
2630
2630
 
2631
+ const quotedColumns = [];
2631
2632
  const pushInsertSql = (ctx, table, query, quotedAs) => {
2632
- var _a, _b, _c;
2633
+ var _a, _b, _c, _d;
2633
2634
  const { shape } = table.query;
2634
- const quotedColumns = query.columns.map(
2635
- (key) => {
2636
- var _a2;
2637
- return q(((_a2 = shape[key]) == null ? void 0 : _a2.data.name) || key);
2638
- }
2639
- );
2635
+ const { columns } = query;
2636
+ quotedColumns.length = columns.length;
2637
+ for (let i = 0, len = columns.length; i < len; i++) {
2638
+ quotedColumns[i] = q(((_a = shape[columns[i]]) == null ? void 0 : _a.data.name) || columns[i]);
2639
+ }
2640
2640
  let runtimeDefaults;
2641
2641
  if (table.internal.runtimeDefaultColumns) {
2642
2642
  runtimeDefaults = [];
2643
2643
  for (const key of table.internal.runtimeDefaultColumns) {
2644
- if (!query.columns.includes(key)) {
2644
+ if (!columns.includes(key)) {
2645
2645
  const column = shape[key];
2646
2646
  quotedColumns.push(q(column.data.name || key));
2647
2647
  runtimeDefaults.push(column.data.default);
2648
2648
  }
2649
2649
  }
2650
2650
  }
2651
+ let values = query.values;
2652
+ if (quotedColumns.length === 0) {
2653
+ const key = Object.keys(table.shape)[0];
2654
+ const column = table.shape[key];
2655
+ quotedColumns[0] = q((column == null ? void 0 : column.data.name) || key);
2656
+ if (Array.isArray(values) && Array.isArray(values[0])) {
2657
+ values = [[void 0]];
2658
+ }
2659
+ }
2651
2660
  ctx.sql.push(`INSERT INTO ${quotedAs}(${quotedColumns.join(", ")})`);
2652
- if ("from" in query.values) {
2653
- const { from, values } = query.values;
2661
+ if ("from" in values) {
2662
+ const { from, values: v } = values;
2654
2663
  const q2 = from.clone();
2655
- if (values) {
2664
+ if (v) {
2656
2665
  pushQueryValue(
2657
2666
  q2,
2658
2667
  "select",
2659
- raw(encodeRow(ctx, values[0], runtimeDefaults), false)
2668
+ raw(encodeRow(ctx, v[0], runtimeDefaults), false)
2660
2669
  );
2661
2670
  }
2662
2671
  ctx.sql.push(makeSql(q2, { values: ctx.values }).text);
2663
- } else if (isRaw(query.values)) {
2664
- let valuesSql = getRaw(query.values, ctx.values);
2672
+ } else if (isRaw(values)) {
2673
+ let valuesSql = getRaw(values, ctx.values);
2665
2674
  if (runtimeDefaults) {
2666
2675
  valuesSql += `, ${runtimeDefaults.map((fn) => addValue(ctx.values, fn())).join(", ")}`;
2667
2676
  }
2668
2677
  ctx.sql.push(`VALUES (${valuesSql})`);
2669
- } else if (isRaw(query.values[0])) {
2678
+ } else if (isRaw(values[0])) {
2670
2679
  let sql;
2671
2680
  if (runtimeDefaults) {
2672
- const { values } = ctx;
2673
- sql = query.values.map(
2681
+ const { values: v } = ctx;
2682
+ sql = values.map(
2674
2683
  (raw2) => (
2675
2684
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
2676
- `(${getRaw(raw2, values)}, ${runtimeDefaults.map((fn) => addValue(values, fn())).join(", ")})`
2685
+ `(${getRaw(raw2, v)}, ${runtimeDefaults.map((fn) => addValue(v, fn())).join(", ")})`
2677
2686
  )
2678
2687
  ).join(", ");
2679
2688
  } else {
2680
- const { values } = ctx;
2681
- sql = query.values.map((raw2) => `(${getRaw(raw2, values)})`).join(", ");
2689
+ const { values: v } = ctx;
2690
+ sql = values.map((raw2) => `(${getRaw(raw2, v)})`).join(", ");
2682
2691
  }
2683
2692
  ctx.sql.push(`VALUES ${sql}`);
2684
2693
  } else {
2685
2694
  ctx.sql.push(
2686
- `VALUES ${query.values.map((row) => `(${encodeRow(ctx, row, runtimeDefaults)})`).join(", ")}`
2695
+ `VALUES ${values.map((row) => `(${encodeRow(ctx, row, runtimeDefaults)})`).join(", ")}`
2687
2696
  );
2688
2697
  }
2689
2698
  if (query.onConflict) {
@@ -2691,7 +2700,7 @@ const pushInsertSql = (ctx, table, query, quotedAs) => {
2691
2700
  const { expr, type } = query.onConflict;
2692
2701
  if (expr) {
2693
2702
  if (typeof expr === "string") {
2694
- ctx.sql.push(`(${q(((_a = shape[expr]) == null ? void 0 : _a.data.name) || expr)})`);
2703
+ ctx.sql.push(`(${q(((_b = shape[expr]) == null ? void 0 : _b.data.name) || expr)})`);
2695
2704
  } else if (Array.isArray(expr)) {
2696
2705
  ctx.sql.push(
2697
2706
  `(${expr.map((item) => {
@@ -2704,7 +2713,7 @@ const pushInsertSql = (ctx, table, query, quotedAs) => {
2704
2713
  }
2705
2714
  } else if (type === "merge") {
2706
2715
  const { indexes } = table.internal;
2707
- const quotedUniques = query.columns.reduce((arr, key, i) => {
2716
+ const quotedUniques = columns.reduce((arr, key, i) => {
2708
2717
  var _a2, _b2;
2709
2718
  const unique = (
2710
2719
  // check column index
@@ -2730,7 +2739,7 @@ const pushInsertSql = (ctx, table, query, quotedAs) => {
2730
2739
  const { update } = query.onConflict;
2731
2740
  if (update) {
2732
2741
  if (typeof update === "string") {
2733
- const name = q(((_b = shape[update]) == null ? void 0 : _b.data.name) || update);
2742
+ const name = q(((_c = shape[update]) == null ? void 0 : _c.data.name) || update);
2734
2743
  set = `${name} = excluded.${name}`;
2735
2744
  } else if (Array.isArray(update)) {
2736
2745
  set = update.map((item) => {
@@ -2744,7 +2753,7 @@ const pushInsertSql = (ctx, table, query, quotedAs) => {
2744
2753
  const arr = [];
2745
2754
  for (const key in update) {
2746
2755
  arr.push(
2747
- `${q(((_c = shape[key]) == null ? void 0 : _c.data.name) || key)} = ${addValue(
2756
+ `${q(((_d = shape[key]) == null ? void 0 : _d.data.name) || key)} = ${addValue(
2748
2757
  ctx.values,
2749
2758
  update[key]
2750
2759
  )}`
@@ -3165,27 +3174,27 @@ const cloneQueryArrays = (q) => {
3165
3174
  }
3166
3175
  };
3167
3176
 
3168
- var __defProp$a = Object.defineProperty;
3169
- var __getOwnPropSymbols$b = Object.getOwnPropertySymbols;
3170
- var __hasOwnProp$b = Object.prototype.hasOwnProperty;
3171
- var __propIsEnum$b = Object.prototype.propertyIsEnumerable;
3172
- var __defNormalProp$a = (obj, key, value) => key in obj ? __defProp$a(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3173
- var __spreadValues$a = (a, b) => {
3177
+ var __defProp$9 = Object.defineProperty;
3178
+ var __getOwnPropSymbols$a = Object.getOwnPropertySymbols;
3179
+ var __hasOwnProp$a = Object.prototype.hasOwnProperty;
3180
+ var __propIsEnum$a = Object.prototype.propertyIsEnumerable;
3181
+ var __defNormalProp$9 = (obj, key, value) => key in obj ? __defProp$9(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3182
+ var __spreadValues$9 = (a, b) => {
3174
3183
  for (var prop in b || (b = {}))
3175
- if (__hasOwnProp$b.call(b, prop))
3176
- __defNormalProp$a(a, prop, b[prop]);
3177
- if (__getOwnPropSymbols$b)
3178
- for (var prop of __getOwnPropSymbols$b(b)) {
3179
- if (__propIsEnum$b.call(b, prop))
3180
- __defNormalProp$a(a, prop, b[prop]);
3184
+ if (__hasOwnProp$a.call(b, prop))
3185
+ __defNormalProp$9(a, prop, b[prop]);
3186
+ if (__getOwnPropSymbols$a)
3187
+ for (var prop of __getOwnPropSymbols$a(b)) {
3188
+ if (__propIsEnum$a.call(b, prop))
3189
+ __defNormalProp$9(a, prop, b[prop]);
3181
3190
  }
3182
3191
  return a;
3183
3192
  };
3184
3193
  const getClonedQueryData = (query) => {
3185
- const cloned = __spreadValues$a({}, query);
3194
+ const cloned = __spreadValues$9({}, query);
3186
3195
  delete cloned[toSqlCacheKey];
3187
3196
  if (cloned.parsers)
3188
- cloned.parsers = __spreadValues$a({}, cloned.parsers);
3197
+ cloned.parsers = __spreadValues$9({}, cloned.parsers);
3189
3198
  cloneQueryArrays(cloned);
3190
3199
  return cloned;
3191
3200
  };
@@ -3213,21 +3222,21 @@ class DomainColumn extends CustomTypeColumn {
3213
3222
  }
3214
3223
  }
3215
3224
 
3216
- var __defProp$9 = Object.defineProperty;
3225
+ var __defProp$8 = Object.defineProperty;
3217
3226
  var __defProps$4 = Object.defineProperties;
3218
3227
  var __getOwnPropDescs$4 = Object.getOwnPropertyDescriptors;
3219
- var __getOwnPropSymbols$a = Object.getOwnPropertySymbols;
3220
- var __hasOwnProp$a = Object.prototype.hasOwnProperty;
3221
- var __propIsEnum$a = Object.prototype.propertyIsEnumerable;
3222
- var __defNormalProp$9 = (obj, key, value) => key in obj ? __defProp$9(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3223
- var __spreadValues$9 = (a, b) => {
3228
+ var __getOwnPropSymbols$9 = Object.getOwnPropertySymbols;
3229
+ var __hasOwnProp$9 = Object.prototype.hasOwnProperty;
3230
+ var __propIsEnum$9 = Object.prototype.propertyIsEnumerable;
3231
+ var __defNormalProp$8 = (obj, key, value) => key in obj ? __defProp$8(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3232
+ var __spreadValues$8 = (a, b) => {
3224
3233
  for (var prop in b || (b = {}))
3225
- if (__hasOwnProp$a.call(b, prop))
3226
- __defNormalProp$9(a, prop, b[prop]);
3227
- if (__getOwnPropSymbols$a)
3228
- for (var prop of __getOwnPropSymbols$a(b)) {
3229
- if (__propIsEnum$a.call(b, prop))
3230
- __defNormalProp$9(a, prop, b[prop]);
3234
+ if (__hasOwnProp$9.call(b, prop))
3235
+ __defNormalProp$8(a, prop, b[prop]);
3236
+ if (__getOwnPropSymbols$9)
3237
+ for (var prop of __getOwnPropSymbols$9(b)) {
3238
+ if (__propIsEnum$9.call(b, prop))
3239
+ __defNormalProp$8(a, prop, b[prop]);
3231
3240
  }
3232
3241
  return a;
3233
3242
  };
@@ -3256,7 +3265,7 @@ const getColumnTypes = (types, fn, nowSQL, data = newTableData()) => {
3256
3265
  function text(min, max) {
3257
3266
  return new TextColumn(min, max);
3258
3267
  }
3259
- const columnTypes = __spreadValues$9({
3268
+ const columnTypes = __spreadValues$8({
3260
3269
  name,
3261
3270
  raw,
3262
3271
  smallint() {
@@ -3417,7 +3426,7 @@ const columnTypes = __spreadValues$9({
3417
3426
  columns: toArray(columns).map(
3418
3427
  (column) => typeof column === "string" ? { column } : column
3419
3428
  ),
3420
- options: __spreadProps$4(__spreadValues$9({}, options), { unique: true })
3429
+ options: __spreadProps$4(__spreadValues$8({}, options), { unique: true })
3421
3430
  };
3422
3431
  ((_a = tableData.indexes) != null ? _a : tableData.indexes = []).push(index);
3423
3432
  return emptyObject;
@@ -3559,17 +3568,17 @@ const columnsByType = {
3559
3568
  bigserial: BigSerialColumn
3560
3569
  };
3561
3570
 
3562
- var __getOwnPropSymbols$9 = Object.getOwnPropertySymbols;
3563
- var __hasOwnProp$9 = Object.prototype.hasOwnProperty;
3564
- var __propIsEnum$9 = Object.prototype.propertyIsEnumerable;
3571
+ var __getOwnPropSymbols$8 = Object.getOwnPropertySymbols;
3572
+ var __hasOwnProp$8 = Object.prototype.hasOwnProperty;
3573
+ var __propIsEnum$8 = Object.prototype.propertyIsEnumerable;
3565
3574
  var __objRest$1 = (source, exclude) => {
3566
3575
  var target = {};
3567
3576
  for (var prop in source)
3568
- if (__hasOwnProp$9.call(source, prop) && exclude.indexOf(prop) < 0)
3577
+ if (__hasOwnProp$8.call(source, prop) && exclude.indexOf(prop) < 0)
3569
3578
  target[prop] = source[prop];
3570
- if (source != null && __getOwnPropSymbols$9)
3571
- for (var prop of __getOwnPropSymbols$9(source)) {
3572
- if (exclude.indexOf(prop) < 0 && __propIsEnum$9.call(source, prop))
3579
+ if (source != null && __getOwnPropSymbols$8)
3580
+ for (var prop of __getOwnPropSymbols$8(source)) {
3581
+ if (exclude.indexOf(prop) < 0 && __propIsEnum$8.call(source, prop))
3573
3582
  target[prop] = source[prop];
3574
3583
  }
3575
3584
  return target;
@@ -3753,21 +3762,21 @@ class QueryGet {
3753
3762
  }
3754
3763
  }
3755
3764
 
3756
- var __defProp$8 = Object.defineProperty;
3765
+ var __defProp$7 = Object.defineProperty;
3757
3766
  var __defProps$3 = Object.defineProperties;
3758
3767
  var __getOwnPropDescs$3 = Object.getOwnPropertyDescriptors;
3759
- var __getOwnPropSymbols$8 = Object.getOwnPropertySymbols;
3760
- var __hasOwnProp$8 = Object.prototype.hasOwnProperty;
3761
- var __propIsEnum$8 = Object.prototype.propertyIsEnumerable;
3762
- var __defNormalProp$8 = (obj, key, value) => key in obj ? __defProp$8(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3763
- var __spreadValues$8 = (a, b) => {
3768
+ var __getOwnPropSymbols$7 = Object.getOwnPropertySymbols;
3769
+ var __hasOwnProp$7 = Object.prototype.hasOwnProperty;
3770
+ var __propIsEnum$7 = Object.prototype.propertyIsEnumerable;
3771
+ var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3772
+ var __spreadValues$7 = (a, b) => {
3764
3773
  for (var prop in b || (b = {}))
3765
- if (__hasOwnProp$8.call(b, prop))
3766
- __defNormalProp$8(a, prop, b[prop]);
3767
- if (__getOwnPropSymbols$8)
3768
- for (var prop of __getOwnPropSymbols$8(b)) {
3769
- if (__propIsEnum$8.call(b, prop))
3770
- __defNormalProp$8(a, prop, b[prop]);
3774
+ if (__hasOwnProp$7.call(b, prop))
3775
+ __defNormalProp$7(a, prop, b[prop]);
3776
+ if (__getOwnPropSymbols$7)
3777
+ for (var prop of __getOwnPropSymbols$7(b)) {
3778
+ if (__propIsEnum$7.call(b, prop))
3779
+ __defNormalProp$7(a, prop, b[prop]);
3771
3780
  }
3772
3781
  return a;
3773
3782
  };
@@ -3806,7 +3815,7 @@ const _join = (q, require2, type, args) => {
3806
3815
  shape = (_a = q.query.withShapes) == null ? void 0 : _a[joinKey];
3807
3816
  if (shape) {
3808
3817
  if (!require2)
3809
- shape = __spreadValues$8({}, shape);
3818
+ shape = __spreadValues$7({}, shape);
3810
3819
  parsers = {};
3811
3820
  for (const key in shape) {
3812
3821
  const parser = shape[key].parseFn;
@@ -3840,7 +3849,7 @@ const _joinLateral = (q, type, arg, cb, as) => {
3840
3849
  const t = Object.create(q.queryBuilder);
3841
3850
  t.table = arg;
3842
3851
  t.shape = shape;
3843
- t.query = __spreadProps$3(__spreadValues$8({}, t.query), {
3852
+ t.query = __spreadProps$3(__spreadValues$7({}, t.query), {
3844
3853
  shape
3845
3854
  });
3846
3855
  t.baseQuery = t;
@@ -3864,22 +3873,6 @@ const _joinLateral = (q, type, arg, cb, as) => {
3864
3873
  return pushQueryValue(q, "join", [type, result, as]);
3865
3874
  };
3866
3875
 
3867
- var __defProp$7 = Object.defineProperty;
3868
- var __getOwnPropSymbols$7 = Object.getOwnPropertySymbols;
3869
- var __hasOwnProp$7 = Object.prototype.hasOwnProperty;
3870
- var __propIsEnum$7 = Object.prototype.propertyIsEnumerable;
3871
- var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3872
- var __spreadValues$7 = (a, b) => {
3873
- for (var prop in b || (b = {}))
3874
- if (__hasOwnProp$7.call(b, prop))
3875
- __defNormalProp$7(a, prop, b[prop]);
3876
- if (__getOwnPropSymbols$7)
3877
- for (var prop of __getOwnPropSymbols$7(b)) {
3878
- if (__propIsEnum$7.call(b, prop))
3879
- __defNormalProp$7(a, prop, b[prop]);
3880
- }
3881
- return a;
3882
- };
3883
3876
  const addParserForRawExpression = (q, key, raw2) => {
3884
3877
  var _a;
3885
3878
  const parser = (_a = raw2.__column) == null ? void 0 : _a.parseFn;
@@ -3991,7 +3984,13 @@ const processSelectArg = (q, as, arg, columnAs) => {
3991
3984
  }
3992
3985
  query = value;
3993
3986
  }
3994
- _joinLateral(q, "LEFT JOIN", query, (q2) => q2, key);
3987
+ _joinLateral(
3988
+ q,
3989
+ value.query.innerJoinLateral ? "JOIN" : "LEFT JOIN",
3990
+ query,
3991
+ (q2) => q2,
3992
+ key
3993
+ );
3995
3994
  }
3996
3995
  }
3997
3996
  selectAs[key] = addParserForSelectItem(q, as, key, value);
@@ -4023,36 +4022,46 @@ const processSelectColumnArg = (q, arg, as, columnAs) => {
4023
4022
  const getShapeFromSelect = (q, isSubQuery) => {
4024
4023
  const query = q.query;
4025
4024
  const { select, shape } = query;
4025
+ let result;
4026
4026
  if (!select) {
4027
- return shape;
4028
- }
4029
- const result = {};
4030
- for (const item of select) {
4031
- if (typeof item === "string") {
4032
- addColumnToShapeFromSelect(q, item, shape, query, result, isSubQuery);
4033
- } else if ("selectAs" in item) {
4034
- for (const key in item.selectAs) {
4035
- const it = item.selectAs[key];
4036
- if (typeof it === "string") {
4037
- addColumnToShapeFromSelect(
4038
- q,
4039
- it,
4040
- shape,
4041
- query,
4042
- result,
4043
- isSubQuery,
4044
- key
4045
- );
4046
- } else if (isRaw(it)) {
4047
- result[key] = it.__column || new UnknownColumn();
4048
- } else {
4049
- const { returnType } = it.query;
4050
- if (returnType === "value" || returnType === "valueOrThrow") {
4051
- const type = it.query[getValueKey];
4052
- if (type)
4053
- result[key] = type;
4027
+ if (isSubQuery) {
4028
+ result = {};
4029
+ for (const key in shape) {
4030
+ const column = shape[key];
4031
+ result[key] = column.data.name ? setColumnData(column, "name", void 0) : column;
4032
+ }
4033
+ } else {
4034
+ result = shape;
4035
+ }
4036
+ } else {
4037
+ result = {};
4038
+ for (const item of select) {
4039
+ if (typeof item === "string") {
4040
+ addColumnToShapeFromSelect(q, item, shape, query, result, isSubQuery);
4041
+ } else if ("selectAs" in item) {
4042
+ for (const key in item.selectAs) {
4043
+ const it = item.selectAs[key];
4044
+ if (typeof it === "string") {
4045
+ addColumnToShapeFromSelect(
4046
+ q,
4047
+ it,
4048
+ shape,
4049
+ query,
4050
+ result,
4051
+ isSubQuery,
4052
+ key
4053
+ );
4054
+ } else if (isRaw(it)) {
4055
+ result[key] = it.__column || new UnknownColumn();
4054
4056
  } else {
4055
- result[key] = new JSONTextColumn();
4057
+ const { returnType } = it.query;
4058
+ if (returnType === "value" || returnType === "valueOrThrow") {
4059
+ const type = it.query[getValueKey];
4060
+ if (type)
4061
+ result[key] = type;
4062
+ } else {
4063
+ result[key] = new JSONTextColumn();
4064
+ }
4056
4065
  }
4057
4066
  }
4058
4067
  }
@@ -4086,12 +4095,7 @@ const addColumnToShapeFromSelect = (q, arg, shape, query, result, isSubQuery, ke
4086
4095
  }
4087
4096
  };
4088
4097
  const maybeUnNameColumn = (column, isSubQuery) => {
4089
- if (!isSubQuery || !column.data.name)
4090
- return column;
4091
- const cloned = Object.create(column);
4092
- cloned.data = __spreadValues$7({}, column.data);
4093
- delete cloned.data.name;
4094
- return cloned;
4098
+ return isSubQuery && column.data.name ? setColumnData(column, "name", void 0) : column;
4095
4099
  };
4096
4100
  class Select {
4097
4101
  select(...args) {
@@ -6156,6 +6160,9 @@ class QueryUpsertOrCreate {
6156
6160
  };
6157
6161
  this.query.patchResult = async (queryResult) => {
6158
6162
  if (queryResult.rowCount === 0) {
6163
+ if (typeof data === "function") {
6164
+ data = data();
6165
+ }
6159
6166
  const inner = this.create(data);
6160
6167
  const { handleResult: handleResult2 } = inner.query;
6161
6168
  inner.query.handleResult = (q, r, s) => {