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