pqb 0.56.4 → 0.56.5

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, templateLiteralSQLToCode, quoteObjectKey, toArray, emptyArray, singleQuote, addCode, singleQuoteArray, objectHasValues, toSnakeCase, columnDefaultArgumentToCode, columnErrorMessagesToCode, setObjectValueImmutable, getValueKey, addValue, isExpression, dateDataToCode, joinTruthy, arrayDataToCode, numberDataToCode, noop, stringDataToCode, getDefaultLanguage, setDefaultNowFn, setDefaultLanguage, setCurrentColumnName, timestampHelpers, _getQueryAliasOrName, _getQueryOuterAliases, returnArg, pushQueryValueImmutable, NotFoundError, OrchidOrmInternalError, _setSubQueryAliases, _applyRelationAliases, isRelationQuery, _checkIfAliased, logColors, OrchidOrmError, applyTransforms, callWithThis, requirePrimaryKeys, pick, getFreeAlias, _setQueryAs, _copyQueryAliasToQuery, setParserToQuery, newDelayedRelationSelect, pushOrNewArray, getPrimaryKeys, setDelayedRelation, UnhandledTypeError, isRawSQL, pushOrNewArrayToObjectImmutable, QueryHookUtils, MoreThanOneRowError, isObjectEmpty, ValExpression, applyMixins, _getQueryAs, _setQueryAlias, QueryError, snakeCaseKey } from 'orchid-core';
1
+ import { ExpressionTypeMethod, Expression, RawSQLBase, emptyObject, isTemplateLiteralArgs, ColumnTypeBase, setColumnData, pushColumnData, templateLiteralSQLToCode, quoteObjectKey, toArray, emptyArray, singleQuote, addCode, singleQuoteArray, objectHasValues, toSnakeCase, columnDefaultArgumentToCode, columnErrorMessagesToCode, setObjectValueImmutable, getValueKey, addValue, isExpression, dateDataToCode, joinTruthy, arrayDataToCode, numberDataToCode, noop, stringDataToCode, getDefaultLanguage, setDefaultNowFn, setDefaultLanguage, setCurrentColumnName, timestampHelpers, _getQueryAliasOrName, _getQueryOuterAliases, returnArg, pushQueryValueImmutable, NotFoundError, OrchidOrmInternalError, _setSubQueryAliases, _applyRelationAliases, isRelationQuery, getFreeAlias, _checkIfAliased, logColors, OrchidOrmError, applyTransforms, callWithThis, requirePrimaryKeys, pick, _setQueryAs, _copyQueryAliasToQuery, setParserToQuery, newDelayedRelationSelect, pushOrNewArray, getPrimaryKeys, setDelayedRelation, UnhandledTypeError, isRawSQL, pushOrNewArrayToObjectImmutable, _getQueryFreeAlias, _setQueryAlias, QueryHookUtils, MoreThanOneRowError, isObjectEmpty, ValExpression, applyMixins, _getQueryAs, QueryError, snakeCaseKey } from 'orchid-core';
2
2
  import { inspect } from 'node:util';
3
3
  import { AsyncLocalStorage } from 'node:async_hooks';
4
4
  import { templateLiteralToSQL as templateLiteralToSQL$1 } from 'pqb';
@@ -4233,14 +4233,7 @@ const throwIfJoinLateral = (q, method) => {
4233
4233
  };
4234
4234
  const saveAliasedShape = (q, as, key) => {
4235
4235
  const shapes = q.q[key];
4236
- if (shapes?.[as]) {
4237
- let suffix = 2;
4238
- let name;
4239
- while (shapes[name = `${as}${suffix}`]) {
4240
- suffix++;
4241
- }
4242
- as = name;
4243
- }
4236
+ as = getFreeAlias(shapes, as);
4244
4237
  setQueryObjectValueImmutable(q, key, as, emptyObject);
4245
4238
  return as;
4246
4239
  };
@@ -6352,15 +6345,26 @@ const pushWithSql = (ctx, items) => {
6352
6345
  const sql = withToSql(ctx, items);
6353
6346
  if (sql) ctx.sql.push("WITH", sql);
6354
6347
  };
6348
+ const pushOrAppendWithSql = (ctx, query, items) => {
6349
+ const sql = withToSql(ctx, items);
6350
+ if (sql) {
6351
+ if (query.with) {
6352
+ ctx.sql[ctx.sql.length - 1] += ",";
6353
+ } else {
6354
+ ctx.sql.push("WITH");
6355
+ }
6356
+ ctx.sql.push(sql);
6357
+ }
6358
+ };
6355
6359
 
6356
6360
  const makeInsertSql = (ctx, q, query, quotedAs) => {
6357
6361
  let { columns } = query;
6358
6362
  const { shape, inCTE, hookCreateSet } = query;
6359
6363
  const QueryClass = ctx.qb.constructor;
6360
- let values = query.values;
6364
+ let { insertFrom, queryColumnsCount, values } = query;
6361
6365
  let hookSetSql;
6362
6366
  if (hookCreateSet) {
6363
- ({ hookSetSql, columns, values } = processHookSet(
6367
+ ({ hookSetSql, columns, insertFrom, queryColumnsCount, values } = processHookSet(
6364
6368
  ctx,
6365
6369
  q,
6366
6370
  values,
@@ -6379,6 +6383,7 @@ const makeInsertSql = (ctx, q, query, quotedAs) => {
6379
6383
  for (const key of q.internal.runtimeDefaultColumns) {
6380
6384
  if (!columns.includes(key)) {
6381
6385
  const column = shape[key];
6386
+ columns.push(key);
6382
6387
  quotedColumns.push(`"${column.data.name || key}"`);
6383
6388
  runtimeDefaults.push(column.data.runtimeDefault);
6384
6389
  }
@@ -6396,8 +6401,22 @@ const makeInsertSql = (ctx, q, query, quotedAs) => {
6396
6401
  }
6397
6402
  const insertSql = `INSERT INTO ${quotedAs}${quotedColumns.length ? "(" + quotedColumns.join(", ") + ")" : ""}`;
6398
6403
  const hasNonSelect = ctx.hasNonSelect;
6399
- if ("from" in values && query.insertWith) {
6400
- pushWithSql(ctx, Object.values(query.insertWith).flat());
6404
+ let hasWith = !!query.with;
6405
+ if (insertFrom) {
6406
+ if (values.length < 2) {
6407
+ if (query.insertWith) {
6408
+ hasWith = true;
6409
+ pushOrAppendWithSql(ctx, query, Object.values(query.insertWith).flat());
6410
+ }
6411
+ } else {
6412
+ hasWith = true;
6413
+ pushOrAppendWithSql(ctx, query, [
6414
+ {
6415
+ n: getQueryAs(insertFrom),
6416
+ q: insertFrom
6417
+ }
6418
+ ]);
6419
+ }
6401
6420
  }
6402
6421
  const valuesPos = ctx.sql.length + 1;
6403
6422
  ctx.sql.push(insertSql, null);
@@ -6473,28 +6492,38 @@ const makeInsertSql = (ctx, q, query, quotedAs) => {
6473
6492
  );
6474
6493
  }
6475
6494
  if (returning.select) ctx.sql.push("RETURNING", returning.select);
6476
- if ("from" in values) {
6477
- const { from, values: v } = values;
6478
- const q2 = from.clone();
6479
- if (v) {
6480
- pushQueryValueImmutable(
6481
- q2,
6482
- "select",
6483
- new RawSQL(
6484
- encodeRow(
6485
- ctx,
6486
- ctx.values,
6487
- q2,
6488
- QueryClass,
6489
- v,
6490
- runtimeDefaults,
6491
- quotedAs
6495
+ let insertManyFromValuesAs;
6496
+ if (insertFrom) {
6497
+ if (values.length < 2) {
6498
+ const q2 = insertFrom.clone();
6499
+ if (values[0]?.length) {
6500
+ pushQueryValueImmutable(
6501
+ q2,
6502
+ "select",
6503
+ new RawSQL(
6504
+ encodeRow(
6505
+ ctx,
6506
+ ctx.values,
6507
+ q2,
6508
+ QueryClass,
6509
+ values[0],
6510
+ runtimeDefaults,
6511
+ quotedAs
6512
+ )
6492
6513
  )
6493
- )
6494
- );
6514
+ );
6515
+ }
6516
+ ctx.sql[valuesPos] = getSqlText(toSQL(q2, ctx));
6517
+ } else {
6518
+ insertManyFromValuesAs = query.insertValuesAs;
6519
+ const queryAs = getQueryAs(insertFrom);
6520
+ ctx.sql[valuesPos - 1] += ` SELECT "${queryAs}".*, ${columns.slice(queryColumnsCount || 0).map((key) => {
6521
+ const column = shape[key];
6522
+ return column ? `${insertManyFromValuesAs}."${column.data.name || key}"::${column.dataType}` : `${insertManyFromValuesAs}."${key}"`;
6523
+ }).join(", ")} FROM "${queryAs}",`;
6495
6524
  }
6496
- ctx.sql[valuesPos] = getSqlText(toSQL(q2, ctx));
6497
- } else {
6525
+ }
6526
+ if (!insertFrom || insertManyFromValuesAs) {
6498
6527
  const valuesSql = [];
6499
6528
  let ctxValues = ctx.values;
6500
6529
  const restValuesLen = ctxValues.length;
@@ -6503,6 +6532,8 @@ const makeInsertSql = (ctx, q, query, quotedAs) => {
6503
6532
  const { insertWith } = query;
6504
6533
  const { skipBatchCheck } = ctx;
6505
6534
  const withSqls = [];
6535
+ const startingKeyword = (insertManyFromValuesAs ? "(" : "") + (inCTE ? "SELECT " : "VALUES ");
6536
+ const valuesAppend = insertManyFromValuesAs ? `) ${insertManyFromValuesAs}(${quotedColumns.slice(queryColumnsCount || 0).join(", ")})` : "";
6506
6537
  for (let i = 0; i < values.length; i++) {
6507
6538
  const withes = insertWith?.[i];
6508
6539
  ctx.skipBatchCheck = true;
@@ -6526,11 +6557,8 @@ const makeInsertSql = (ctx, q, query, quotedAs) => {
6526
6557
  );
6527
6558
  }
6528
6559
  if (!skipBatchCheck) {
6529
- if (withSqls.length) {
6530
- ctx.sql[valuesPos - 1] = "WITH " + withSqls.join(", ") + " " + insertSql;
6531
- withSqls.length = 0;
6532
- }
6533
- ctx.sql[valuesPos] = (inCTE ? "SELECT " : "VALUES ") + valuesSql.join(", ");
6560
+ addWithSqls(ctx, hasWith, withSqls, valuesPos, insertSql);
6561
+ ctx.sql[valuesPos] = startingKeyword + valuesSql.join(", ") + valuesAppend;
6534
6562
  ctxValues.length = currentValuesLen;
6535
6563
  batch = pushOrNewArray(batch, {
6536
6564
  text: ctx.sql.join(" "),
@@ -6546,9 +6574,7 @@ const makeInsertSql = (ctx, q, query, quotedAs) => {
6546
6574
  if (withSql) withSqls.push(withSql);
6547
6575
  valuesSql.push(encodedRow);
6548
6576
  }
6549
- if (withSqls.length) {
6550
- ctx.sql[valuesPos - 1] = "WITH " + withSqls.join(", ") + " " + insertSql;
6551
- }
6577
+ addWithSqls(ctx, hasWith, withSqls, valuesPos, insertSql);
6552
6578
  if (batch) {
6553
6579
  if (hasNonSelect) {
6554
6580
  throw new OrchidOrmInternalError(
@@ -6556,7 +6582,7 @@ const makeInsertSql = (ctx, q, query, quotedAs) => {
6556
6582
  `Cannot insert many records when having a non-select sub-query`
6557
6583
  );
6558
6584
  }
6559
- ctx.sql[valuesPos] = (inCTE ? "SELECT " : "VALUES ") + valuesSql.join(", ");
6585
+ ctx.sql[valuesPos] = startingKeyword + valuesSql.join(", ") + valuesAppend;
6560
6586
  batch.push({
6561
6587
  text: ctx.sql.join(" "),
6562
6588
  values: ctxValues
@@ -6567,7 +6593,7 @@ const makeInsertSql = (ctx, q, query, quotedAs) => {
6567
6593
  batch
6568
6594
  };
6569
6595
  } else {
6570
- ctx.sql[valuesPos] = (inCTE ? "SELECT " : "VALUES ") + valuesSql.join(", ");
6596
+ ctx.sql[valuesPos] = startingKeyword + valuesSql.join(", ") + valuesAppend;
6571
6597
  }
6572
6598
  if (inCTE) {
6573
6599
  ctx.sql[valuesPos] += ' WHERE NOT EXISTS (SELECT 1 FROM "f")';
@@ -6580,6 +6606,15 @@ const makeInsertSql = (ctx, q, query, quotedAs) => {
6580
6606
  values: ctx.values
6581
6607
  };
6582
6608
  };
6609
+ const addWithSqls = (ctx, hasWith, withSqls, valuesPos, insertSql) => {
6610
+ if (withSqls.length) {
6611
+ if (hasWith) {
6612
+ ctx.sql[valuesPos - 2] += ",";
6613
+ }
6614
+ ctx.sql[valuesPos - 1] = (hasWith ? "" : "WITH ") + withSqls.join(", ") + " " + insertSql;
6615
+ withSqls.length = 0;
6616
+ }
6617
+ };
6583
6618
  const processHookSet = (ctx, q, values, hookCreateSet, columns, QueryClass, quotedAs) => {
6584
6619
  const hookSet = {};
6585
6620
  for (const item of hookCreateSet) {
@@ -6588,48 +6623,54 @@ const processHookSet = (ctx, q, values, hookCreateSet, columns, QueryClass, quot
6588
6623
  const addHookSetColumns = Object.keys(hookSet).filter(
6589
6624
  (key) => !columns.includes(key)
6590
6625
  );
6591
- if ("from" in values) {
6592
- const v = { ...values };
6593
- const newColumns = [];
6594
- const originalSelect = v.from.q.select;
6626
+ let insertFrom = q.q.insertFrom;
6627
+ if (insertFrom) {
6628
+ const newColumns = /* @__PURE__ */ new Set();
6629
+ const originalSelect = insertFrom.q.select;
6595
6630
  if (originalSelect) {
6596
- v.from = _clone(v.from);
6631
+ insertFrom = _clone(insertFrom);
6597
6632
  const select = [];
6598
6633
  for (const s of originalSelect) {
6599
6634
  if (typeof s === "string" && !hookSet[s]) {
6600
6635
  select.push(s);
6601
- newColumns.push(s);
6636
+ newColumns.add(s);
6602
6637
  } else if (typeof s === "object" && "selectAs" in s) {
6603
6638
  const filtered = {};
6604
6639
  for (const key in s.selectAs) {
6605
6640
  if (!hookSet[key]) {
6606
6641
  filtered[key] = s.selectAs[key];
6607
- newColumns.push(key);
6642
+ newColumns.add(key);
6608
6643
  }
6609
6644
  }
6610
6645
  select.push({ selectAs: filtered });
6611
6646
  }
6612
6647
  }
6613
- v.from.q.select = select;
6614
- }
6615
- let row;
6616
- if (v.values) {
6617
- const originalRow = v.values;
6618
- const valuesColumns = columns.slice(-originalRow.length);
6619
- row = [];
6620
- valuesColumns.forEach((c, i) => {
6621
- if (!hookSet[c]) {
6622
- newColumns.push(c);
6623
- row.push(originalRow[i]);
6624
- }
6648
+ insertFrom.q.select = select;
6649
+ }
6650
+ if (values.length) {
6651
+ const newValues = [];
6652
+ const valuesColumnsSet = /* @__PURE__ */ new Set();
6653
+ values.forEach((originalRow, i) => {
6654
+ const valuesColumns = columns.slice(-originalRow.length);
6655
+ const row = [];
6656
+ newValues[i] = row;
6657
+ valuesColumns.forEach((c, i2) => {
6658
+ if (!hookSet[c] && !newColumns.has(c)) {
6659
+ valuesColumnsSet.add(c);
6660
+ row.push(originalRow[i2]);
6661
+ }
6662
+ });
6625
6663
  });
6664
+ for (const valueColumn of valuesColumnsSet) {
6665
+ newColumns.add(valueColumn);
6666
+ }
6667
+ values = newValues;
6626
6668
  } else {
6627
- row = [];
6669
+ values = [[]];
6628
6670
  }
6629
- v.values = row;
6630
6671
  columns.forEach((column) => {
6631
6672
  if (column in hookSet) {
6632
- newColumns.push(column);
6673
+ newColumns.add(column);
6633
6674
  const fromHook = {
6634
6675
  fromHook: encodeValue(
6635
6676
  ctx,
@@ -6640,28 +6681,35 @@ const processHookSet = (ctx, q, values, hookCreateSet, columns, QueryClass, quot
6640
6681
  quotedAs
6641
6682
  )
6642
6683
  };
6643
- row.push(fromHook);
6684
+ for (const row of values) {
6685
+ row.push(fromHook);
6686
+ }
6644
6687
  }
6645
6688
  });
6689
+ const queryColumnsCount = insertFrom.q.select?.length;
6646
6690
  if (addHookSetColumns) {
6647
6691
  for (const key of addHookSetColumns) {
6648
- row.push({
6649
- fromHook: encodeValue(
6650
- ctx,
6651
- ctx.values,
6652
- q,
6653
- QueryClass,
6654
- hookSet[key],
6655
- quotedAs
6656
- )
6657
- });
6692
+ for (const row of values) {
6693
+ row.push({
6694
+ fromHook: encodeValue(
6695
+ ctx,
6696
+ ctx.values,
6697
+ q,
6698
+ QueryClass,
6699
+ hookSet[key],
6700
+ quotedAs
6701
+ )
6702
+ });
6703
+ }
6658
6704
  }
6659
6705
  return {
6660
6706
  columns: [...newColumns, ...addHookSetColumns],
6661
- values: v
6707
+ insertFrom,
6708
+ queryColumnsCount,
6709
+ values
6662
6710
  };
6663
6711
  }
6664
- return { columns: newColumns, values: v };
6712
+ return { columns: [...newColumns], insertFrom, queryColumnsCount, values };
6665
6713
  }
6666
6714
  columns.forEach((column, i) => {
6667
6715
  if (column in hookSet) {
@@ -6977,8 +7025,7 @@ const selectToSql = (ctx, table, query, quotedAs, hookSelect = query.hookSelect,
6977
7025
  hookSelect.delete(column);
6978
7026
  continue;
6979
7027
  }
6980
- let i = 2;
6981
- while (selected[name = `${column}${i}`]) i++;
7028
+ name = getFreeAlias(selected, column);
6982
7029
  item.as = name;
6983
7030
  item.temp = name;
6984
7031
  sql += ` "${name}"`;
@@ -8621,7 +8668,7 @@ class Union {
8621
8668
  }
8622
8669
  }
8623
8670
 
8624
- const addWith = (q, withStore, item, key = "with") => {
8671
+ const _addWith = (query, withStore, item, key = "with") => {
8625
8672
  if (item.q) {
8626
8673
  item.q.q.with?.forEach((item2, i, arr) => {
8627
8674
  if (item2?.q?.q.type) {
@@ -8632,7 +8679,8 @@ const addWith = (q, withStore, item, key = "with") => {
8632
8679
  if (item.q.q.insertWith) {
8633
8680
  const values = Object.values(item.q.q.insertWith).flat();
8634
8681
  item.q.q.insertWith = void 0;
8635
- q.q.with = q.q.with ? [...q.q.with, ...values] : values;
8682
+ const { q } = query;
8683
+ q.with = q.with ? [...q.with, ...values] : values;
8636
8684
  }
8637
8685
  }
8638
8686
  pushOrNewArrayToObjectImmutable(withStore, key, item);
@@ -8640,7 +8688,7 @@ const addWith = (q, withStore, item, key = "with") => {
8640
8688
  const moveQueryValueToWith = (q, withStore, value, withKey, set, key) => {
8641
8689
  if (value.q.type) {
8642
8690
  const as = saveAliasedShape(q, "q", "withShapes");
8643
- addWith(
8691
+ _addWith(
8644
8692
  q,
8645
8693
  withStore,
8646
8694
  {
@@ -8674,7 +8722,7 @@ class WithMethods {
8674
8722
  columns: Object.keys(query.shape)
8675
8723
  };
8676
8724
  }
8677
- addWith(q, q.q, { n: name, o: options, q: query });
8725
+ _addWith(q, q.q, { n: name, o: options, q: query });
8678
8726
  const shape = getShapeFromSelect(query, true);
8679
8727
  return setQueryObjectValueImmutable(q, "withShapes", name, {
8680
8728
  shape,
@@ -8700,7 +8748,7 @@ class WithMethods {
8700
8748
  columns: Object.keys(shape)
8701
8749
  };
8702
8750
  }
8703
- addWith(q, q.q, { n: name, o: options, q: query });
8751
+ _addWith(q, q.q, { n: name, o: options, q: query });
8704
8752
  return setQueryObjectValueImmutable(q, "withShapes", name, withConfig);
8705
8753
  }
8706
8754
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -8718,6 +8766,248 @@ class WithMethods {
8718
8766
  }
8719
8767
  }
8720
8768
 
8769
+ const insertFrom = (query, from, many, queryMany, data) => {
8770
+ const ctx = createCtx();
8771
+ const obj = data && (Array.isArray(data) ? handleManyData(query, data, ctx) : handleOneData(query, data, ctx));
8772
+ return insert(
8773
+ query,
8774
+ {
8775
+ insertFrom: from,
8776
+ columns: obj?.columns || [],
8777
+ values: obj?.values || []
8778
+ },
8779
+ many,
8780
+ queryMany
8781
+ );
8782
+ };
8783
+ const getFromSelectColumns = (q, from, obj, many) => {
8784
+ if (!many && !queryTypeWithLimitOne[from.q.returnType]) {
8785
+ throw new Error(
8786
+ "Cannot create based on a query which returns multiple records"
8787
+ );
8788
+ }
8789
+ const queryColumns = /* @__PURE__ */ new Set();
8790
+ from.q.select?.forEach((item) => {
8791
+ if (typeof item === "string") {
8792
+ const index = item.indexOf(".");
8793
+ queryColumns.add(index === -1 ? item : item.slice(index + 1));
8794
+ } else if (item && "selectAs" in item) {
8795
+ for (const column in item.selectAs) {
8796
+ queryColumns.add(column);
8797
+ }
8798
+ }
8799
+ });
8800
+ const allColumns = new Set(queryColumns);
8801
+ const queryColumnsCount = queryColumns.size;
8802
+ const allValues = [];
8803
+ if (obj?.columns) {
8804
+ for (const objectValues of obj.values) {
8805
+ const values = [];
8806
+ allValues.push(values);
8807
+ obj.columns.forEach((column, i) => {
8808
+ if (!queryColumns.has(column)) {
8809
+ allColumns.add(column);
8810
+ values.push(objectValues[i]);
8811
+ }
8812
+ });
8813
+ }
8814
+ }
8815
+ for (const key of queryColumns) {
8816
+ const column = q.shape[key];
8817
+ if (column) throwOnReadOnly$1(from, column, key);
8818
+ }
8819
+ return {
8820
+ columns: [...allColumns],
8821
+ queryColumnsCount,
8822
+ values: allValues
8823
+ };
8824
+ };
8825
+ const _queryCreateOneFrom = (q, query, data) => {
8826
+ createSelect(q);
8827
+ return insertFrom(q, query, false, false, data);
8828
+ };
8829
+ const _queryInsertOneFrom = (q, query, data) => {
8830
+ return insertFrom(q, query, false, false, data);
8831
+ };
8832
+ const _queryCreateManyFrom = (q, query, data) => {
8833
+ createSelect(q);
8834
+ return insertFrom(q, query, true, false, data);
8835
+ };
8836
+ const _queryInsertManyFrom = (q, query, data) => {
8837
+ return insertFrom(q, query, true, false, data);
8838
+ };
8839
+ const _queryCreateForEachFrom = (q, query) => {
8840
+ createSelect(q);
8841
+ return insertFrom(q, query, true, true);
8842
+ };
8843
+ const _queryInsertForEachFrom = (q, query) => {
8844
+ return insertFrom(q, query, true, true);
8845
+ };
8846
+ class QueryCreateFrom {
8847
+ /**
8848
+ * Inserts a single record based on a query that selects a single record.
8849
+ *
8850
+ * Performs a single SQL query based on `INSERT ... SELECT ... FROM`.
8851
+ *
8852
+ * See {@link createManyFrom} to insert multiple records based on a single record query,
8853
+ * and {@link createForEachFrom} to insert a record per every one found by the query.
8854
+ *
8855
+ * The first argument is a query of a **single** record, it should have `find`, `take`, or similar.
8856
+ *
8857
+ * The second optional argument is a data which will be merged with columns returned by the query.
8858
+ *
8859
+ * The data for the second argument is the same as in {@link create}.
8860
+ *
8861
+ * Columns with runtime defaults (defined with a callback) are supported here.
8862
+ * The value for such a column will be injected unless selected from a related table or provided in a data object.
8863
+ *
8864
+ * ```ts
8865
+ * const oneRecord = await db.table.createOneFrom(
8866
+ * db.relatedTable
8867
+ * // use select to map columns from one table to another
8868
+ * .select({
8869
+ * // relatedTable's id will be inserted as "relatedId"
8870
+ * relatedId: 'id',
8871
+ * })
8872
+ * .findBy({ key: 'value' }),
8873
+ * // optional argument:
8874
+ * {
8875
+ * key: 'value',
8876
+ * // supports sql, nested select, create, update, delete queries
8877
+ * fromSql: () => sql`custom sql`,
8878
+ * fromQuery: () => db.otherTable.find(id).update(data).get('column'),
8879
+ * fromRelated: (q) => q.relatedTable.create(data).get('column'),
8880
+ * },
8881
+ * );
8882
+ * ```
8883
+ *
8884
+ * The query above will produce such a SQL (omitting `from*` values):
8885
+ *
8886
+ * ```sql
8887
+ * INSERT INTO "table"("relatedId", "key")
8888
+ * SELECT "relatedTable"."id" AS "relatedId", 'value'
8889
+ * FROM "relatedTable"
8890
+ * WHERE "relatedTable"."key" = 'value'
8891
+ * LIMIT 1
8892
+ * RETURNING *
8893
+ * ```
8894
+ *
8895
+ * @param query - query to create new records from
8896
+ * @param data - additionally you can set some columns
8897
+ */
8898
+ createOneFrom(query, data) {
8899
+ return _queryCreateOneFrom(_clone(this), query, data);
8900
+ }
8901
+ /**
8902
+ * Works exactly as {@link createOneFrom}, except that it returns inserted row count by default.
8903
+ *
8904
+ * @param query - query to create new records from
8905
+ * @param data - additionally you can set some columns
8906
+ */
8907
+ insertOneFrom(query, data) {
8908
+ return _queryInsertOneFrom(_clone(this), query, data);
8909
+ }
8910
+ /**
8911
+ * Inserts multiple records based on a query that selects a single record.
8912
+ *
8913
+ * Performs a single SQL query based on `INSERT ... SELECT ... FROM`.
8914
+ *
8915
+ * See {@link createOneFrom} to insert a single record based on a single record query,
8916
+ * and {@link createForEachFrom} to insert a record per every one found by the query.
8917
+ *
8918
+ * The first argument is a query of a **single** record, it should have `find`, `take`, or similar.
8919
+ *
8920
+ * The second argument is array of objects to be merged with columns returned by the query.
8921
+ *
8922
+ * The data for the second argument is the same as in {@link createMany}.
8923
+ *
8924
+ * Columns with runtime defaults (defined with a callback) are supported here.
8925
+ * The value for such a column will be injected unless selected from a related table or provided in a data object.
8926
+ *
8927
+ * ```ts
8928
+ * const twoRecords = await db.table.createManyFrom(
8929
+ * db.relatedTable
8930
+ * // use select to map columns from one table to another
8931
+ * .select({
8932
+ * // relatedTable's id will be inserted as "relatedId"
8933
+ * relatedId: 'id',
8934
+ * })
8935
+ * .findBy({ key: 'value' }),
8936
+ * [
8937
+ * {
8938
+ * key: 'value 1',
8939
+ * // supports sql, nested select, create, update, delete queries
8940
+ * fromSql: () => sql`custom sql`,
8941
+ * fromQuery: () => db.otherTable.find(id).update(data).get('column'),
8942
+ * fromRelated: (q) => q.relatedTable.create(data).get('column'),
8943
+ * },
8944
+ * {
8945
+ * key: 'value 2',
8946
+ * },
8947
+ * ],
8948
+ * );
8949
+ * ```
8950
+ *
8951
+ * The query above will produce such a SQL (omitting `from*` values):
8952
+ *
8953
+ * ```sql
8954
+ * WITH "relatedTable" AS (
8955
+ * SELECT "relatedTable"."id" AS "relatedId", 'value'
8956
+ * FROM "relatedTable"
8957
+ * WHERE "relatedTable"."key" = 'value'
8958
+ * LIMIT 1
8959
+ * )
8960
+ * INSERT INTO "table"("relatedId", "key")
8961
+ * SELECT "relatedTable".*, v."key"::text
8962
+ * FROM "relatedTable", (VALUES ('value1'), ('value2')) v("key")
8963
+ * RETURNING *
8964
+ * ```
8965
+ *
8966
+ * @param query - query to create new records from
8967
+ * @param data - array of records to create
8968
+ */
8969
+ createManyFrom(query, data) {
8970
+ return _queryCreateManyFrom(_clone(this), query, data);
8971
+ }
8972
+ /**
8973
+ * Works exactly as {@link createManyFrom}, except that it returns inserted row count by default.
8974
+ *
8975
+ * @param query - query to create new records from
8976
+ * @param data - array of records to create
8977
+ */
8978
+ insertManyFrom(query, data) {
8979
+ return _queryInsertManyFrom(_clone(this), query, data);
8980
+ }
8981
+ /**
8982
+ * Inserts a single record per every record found in a given query.
8983
+ *
8984
+ * Performs a single SQL query based on `INSERT ... SELECT ... FROM`.
8985
+ *
8986
+ * Unlike {@link createOneFrom}, it doesn't accept second argument with data.
8987
+ *
8988
+ * Runtime defaults cannot work with it.
8989
+ *
8990
+ * ```ts
8991
+ * const manyRecords = await db.table.createForEachFrom(
8992
+ * RelatedTable.select({ relatedId: 'id' }).where({ key: 'value' }),
8993
+ * );
8994
+ * ```
8995
+ *
8996
+ * @param query - query to create new records from
8997
+ */
8998
+ createForEachFrom(query) {
8999
+ return _queryCreateForEachFrom(_clone(this), query);
9000
+ }
9001
+ /**
9002
+ * Works exactly as {@link createForEachFrom}, except that it returns inserted row count by default.
9003
+ *
9004
+ * @param query - query to create new records from
9005
+ */
9006
+ insertForEachFrom(query) {
9007
+ return _queryInsertForEachFrom(_clone(this), query);
9008
+ }
9009
+ }
9010
+
8721
9011
  const createSelect = (q) => {
8722
9012
  if (q.q.returnType === "void" || isSelectingCount(q)) {
8723
9013
  q.q.select = void 0;
@@ -8816,8 +9106,9 @@ const handleManyData = (q, data, ctx) => {
8816
9106
  };
8817
9107
  const insert = (self, {
8818
9108
  columns,
9109
+ insertFrom,
8819
9110
  values
8820
- }, many) => {
9111
+ }, many, queryMany) => {
8821
9112
  const { q } = self;
8822
9113
  if (!q.select?.length) {
8823
9114
  q.returning = true;
@@ -8826,6 +9117,28 @@ const insert = (self, {
8826
9117
  delete q.or;
8827
9118
  delete q.scopes;
8828
9119
  q.type = "insert";
9120
+ insertFrom = insertFrom ? q.insertFrom = insertFrom : q.insertFrom;
9121
+ if (insertFrom) {
9122
+ if (q.insertFrom) {
9123
+ const obj = getFromSelectColumns(
9124
+ self,
9125
+ q.insertFrom,
9126
+ {
9127
+ columns,
9128
+ values
9129
+ },
9130
+ queryMany
9131
+ );
9132
+ columns = obj.columns;
9133
+ values = obj.values;
9134
+ q.queryColumnsCount = obj.queryColumnsCount;
9135
+ }
9136
+ if (values.length > 1) {
9137
+ const insertValuesAs = _getQueryFreeAlias(q, "v");
9138
+ _setQueryAlias(self, "v", insertValuesAs);
9139
+ q.insertValuesAs = insertValuesAs;
9140
+ }
9141
+ }
8829
9142
  q.columns = columns;
8830
9143
  q.values = values;
8831
9144
  const { select, returnType } = q;
@@ -8841,63 +9154,20 @@ const insert = (self, {
8841
9154
  q.returnType = "pluck";
8842
9155
  }
8843
9156
  } else if (!returnType || returnType === "all") {
8844
- q.returnType = "from" in values ? values.from.q.returnType : "one";
9157
+ q.returnType = insertFrom ? insertFrom.q.returnType : "one";
8845
9158
  } else if (returnType === "pluck") {
8846
9159
  q.returnType = "valueOrThrow";
8847
9160
  }
8848
9161
  return self;
8849
9162
  };
8850
- const getFromSelectColumns = (q, from, obj, many) => {
8851
- if (!many && !queryTypeWithLimitOne[from.q.returnType]) {
8852
- throw new Error(
8853
- "Cannot create based on a query which returns multiple records"
8854
- );
8855
- }
8856
- const queryColumns = [];
8857
- from.q.select?.forEach((item) => {
8858
- if (typeof item === "string") {
8859
- const index = item.indexOf(".");
8860
- queryColumns.push(index === -1 ? item : item.slice(index + 1));
8861
- } else if (item && "selectAs" in item) {
8862
- queryColumns.push(...Object.keys(item.selectAs));
8863
- }
8864
- });
8865
- if (obj?.columns) {
8866
- queryColumns.push(...obj.columns);
8867
- }
8868
- for (const key of queryColumns) {
8869
- const column = q.shape[key];
8870
- if (column) throwOnReadOnly$1(from, column, key);
8871
- }
8872
- return queryColumns;
8873
- };
8874
- const insertFromQuery = (q, from, many, data) => {
8875
- const ctx = createCtx();
8876
- const obj = data && handleOneData(q, data, ctx);
8877
- const columns = getFromSelectColumns(q, from, obj, many);
8878
- return insert(
8879
- q,
8880
- {
8881
- columns,
8882
- values: { from, values: obj?.values[0] }
8883
- },
8884
- many
8885
- );
8886
- };
8887
9163
  const _queryCreate = (q, data) => {
8888
9164
  createSelect(q);
8889
9165
  return _queryInsert(q, data);
8890
9166
  };
8891
- const _queryInsert = (q, data) => {
9167
+ const _queryInsert = (query, data) => {
8892
9168
  const ctx = createCtx();
8893
- const obj = handleOneData(q, data, ctx);
8894
- const values = q.q.values;
8895
- if (values && "from" in values) {
8896
- obj.columns = getFromSelectColumns(q, values.from, obj);
8897
- values.values = obj.values[0];
8898
- obj.values = values;
8899
- }
8900
- return insert(q, obj);
9169
+ const obj = handleOneData(query, data, ctx);
9170
+ return insert(query, obj);
8901
9171
  };
8902
9172
  const _queryCreateMany = (q, data) => {
8903
9173
  createSelect(q);
@@ -8909,20 +9179,6 @@ const _queryInsertMany = (q, data) => {
8909
9179
  if (!data.length) result = result.none();
8910
9180
  return result;
8911
9181
  };
8912
- const _queryCreateFrom = (q, query, data) => {
8913
- createSelect(q);
8914
- return insertFromQuery(q, query, false, data);
8915
- };
8916
- const _queryInsertFrom = (q, query, data) => {
8917
- return insertFromQuery(q, query, false, data);
8918
- };
8919
- const _queryCreateManyFrom = (q, query) => {
8920
- createSelect(q);
8921
- return insertFromQuery(q, query, true);
8922
- };
8923
- const _queryInsertManyFrom = (q, query) => {
8924
- return insertFromQuery(q, query, true);
8925
- };
8926
9182
  const _queryDefaults = (q, data) => {
8927
9183
  q.q.defaults = data;
8928
9184
  return q;
@@ -9040,85 +9296,6 @@ class QueryCreate {
9040
9296
  insertMany(data) {
9041
9297
  return _queryInsertMany(_clone(this), data);
9042
9298
  }
9043
- /**
9044
- * These methods are for creating a single record, for batch creating see {@link createManyFrom}.
9045
- *
9046
- * `createFrom` is to perform the `INSERT ... SELECT ...` SQL statement, it does select and insert by performing a single query.
9047
- *
9048
- * The first argument is a query for a **single** record, it should have `find`, `take`, or similar.
9049
- *
9050
- * The second optional argument is a data which will be merged with columns returned from the select query.
9051
- *
9052
- * The data for the second argument is the same as in {@link create}.
9053
- *
9054
- * Columns with runtime defaults (defined with a callback) are supported here.
9055
- * The value for such a column will be injected unless selected from a related table or provided in a data object.
9056
- *
9057
- * ```ts
9058
- * const oneRecord = await db.table.createFrom(
9059
- * // In the select, key is a related table column, value is a column to insert as
9060
- * RelatedTable.select({ relatedId: 'id' }).findBy({ key: 'value' }),
9061
- * // optional argument:
9062
- * {
9063
- * key: 'value',
9064
- * // supports sql, nested select, create, update, delete queries
9065
- * fromSql: () => sql`custom sql`,
9066
- * fromQuery: () => db.otherTable.find(id).update(data).get('column'),
9067
- * fromRelated: (q) => q.relatedTable.create(data).get('column'),
9068
- * },
9069
- * );
9070
- * ```
9071
- *
9072
- * The query above will produce such SQL:
9073
- *
9074
- * ```sql
9075
- * INSERT INTO "table"("relatedId", "key")
9076
- * SELECT "relatedTable"."id" AS "relatedId", 'value'
9077
- * FROM "relatedTable"
9078
- * WHERE "relatedTable"."key" = 'value'
9079
- * LIMIT 1
9080
- * RETURNING *
9081
- * ```
9082
- *
9083
- * @param query - query to create new records from
9084
- * @param data - additionally you can set some columns
9085
- */
9086
- createFrom(query, data) {
9087
- return _queryCreateFrom(_clone(this), query, data);
9088
- }
9089
- /**
9090
- * Works exactly as {@link createFrom}, except that it returns inserted row count by default.
9091
- *
9092
- * @param query - query to create new records from
9093
- * @param data - additionally you can set some columns
9094
- */
9095
- insertFrom(query, data) {
9096
- return _queryInsertFrom(_clone(this), query, data);
9097
- }
9098
- /**
9099
- * Similar to `createFrom`, but intended to create many records.
9100
- *
9101
- * Unlike `createFrom`, it doesn't accept second argument with data, and runtime defaults cannot work with it.
9102
- *
9103
- * ```ts
9104
- * const manyRecords = await db.table.createManyFrom(
9105
- * RelatedTable.select({ relatedId: 'id' }).where({ key: 'value' }),
9106
- * );
9107
- * ```
9108
- *
9109
- * @param query - query to create new records from
9110
- */
9111
- createManyFrom(query) {
9112
- return _queryCreateManyFrom(_clone(this), query);
9113
- }
9114
- /**
9115
- * Works exactly as {@link createManyFrom}, except that it returns inserted row count by default.
9116
- *
9117
- * @param query - query to create new records from
9118
- */
9119
- insertManyFrom(query) {
9120
- return _queryInsertManyFrom(_clone(this), query);
9121
- }
9122
9299
  /**
9123
9300
  * `defaults` allows setting values that will be used later in `create`.
9124
9301
  *
@@ -10503,9 +10680,9 @@ class Join {
10503
10680
  }
10504
10681
  /**
10505
10682
  * This method may be useful
10506
- * for combining with [createManyFrom](/guide/create-update-delete.html#createmanyfrom-insertmanyfrom).
10683
+ * for combining with [createForEachFrom](/guide/create-update-delete.html#createForEachFrom-insertForEachFrom).
10507
10684
  *
10508
- * `createManyFrom` creates multiple record based on a selecting query:
10685
+ * `createForEachFrom` creates multiple record based on a selecting query:
10509
10686
  *
10510
10687
  * ```sql
10511
10688
  * INSERT INTO t1(c1, c2)
@@ -10519,7 +10696,7 @@ class Join {
10519
10696
  * ```ts
10520
10697
  * const data = [{ column2: 'one' }, { column2: 'two' }, { column2: 'three' }];
10521
10698
  *
10522
- * await db.table.createManyFrom(
10699
+ * await db.table.createForEachFrom(
10523
10700
  * db.otherTable
10524
10701
  * .joinData('data', (t) => ({ column2: t.text() }), data)
10525
10702
  * .select('otherTable.column1', 'data.column2'),
@@ -12616,6 +12793,7 @@ applyMixins(QueryMethods, [
12616
12793
  Union,
12617
12794
  JsonMethods,
12618
12795
  QueryCreate,
12796
+ QueryCreateFrom,
12619
12797
  Update,
12620
12798
  Delete,
12621
12799
  Transaction,
@@ -13254,5 +13432,5 @@ function copyTableData(query, arg) {
13254
13432
  return q;
13255
13433
  }
13256
13434
 
13257
- export { AfterCommitError, AggregateMethods, ArrayColumn, BigIntColumn, BigSerialColumn, BitColumn, BitVaryingColumn, BooleanColumn, BoxColumn, ByteaColumn, CidrColumn, CircleColumn, CitextColumn, Clear, ColumnRefExpression, ColumnType, ComputedColumn, 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, NumberAsStringBaseColumn, NumberBaseColumn, OnConflictQueryBuilder, OnMethods, Operators, OrExpression, PathColumn, PointColumn, PolygonColumn, PostgisGeographyPointColumn, QueryAsMethods, QueryCreate, QueryGet, QueryHooks, QueryLog, QueryMethods, QueryUpsert, RawSQL, RealColumn, RefExpression, SearchMethods, Select, SerialColumn, SmallIntColumn, SmallSerialColumn, SqlMethod, StringColumn, TextBaseColumn, TextColumn, Then, TimeColumn, TimestampColumn, TimestampTZColumn, Transaction, TransformMethods, TsQueryColumn, TsVectorColumn, UUIDColumn, Union, UnknownColumn, Update, VarCharColumn, VirtualColumn, Where, WithMethods, XMLColumn, _clone, _getSelectableColumn, _initQueryBuilder, _queryAfterSaveCommit, _queryAll, _queryChangeCounter, _queryCreate, _queryCreateFrom, _queryCreateMany, _queryCreateManyFrom, _queryDefaults, _queryDelete, _queryExec, _queryFindBy, _queryFindByOptional, _queryGet, _queryGetOptional, _queryHookAfterCreate, _queryHookAfterCreateCommit, _queryHookAfterDelete, _queryHookAfterDeleteCommit, _queryHookAfterQuery, _queryHookAfterSave, _queryHookAfterUpdate, _queryHookAfterUpdateCommit, _queryHookBeforeCreate, _queryHookBeforeDelete, _queryHookBeforeQuery, _queryHookBeforeSave, _queryHookBeforeUpdate, _queryInsert, _queryInsertFrom, _queryInsertMany, _queryInsertManyFrom, _queryJoinOn, _queryJoinOnJsonPathEquals, _queryJoinOrOn, _queryOr, _queryOrNot, _queryRows, _querySelect, _queryTake, _queryTakeOptional, _queryUnion, _queryUpdate, _queryUpdateOrThrow, _queryWhere, _queryWhereExists, _queryWhereIn, _queryWhereNot, _queryWhereNotOneOf, _queryWhereNotSql, _queryWhereOneOf, _queryWhereSql, _runAfterCommitHooks, addColumnParserToQuery, addParserForRawExpression, addParserForSelectItem, addQueryOn, anyShape, applyComputedColumns, assignDbDataToColumn, checkIfASimpleQuery, cloneQueryBaseUnscoped, columnCheckToCode, columnCode, columnExcludesToCode, columnForeignKeysToCode, columnIndexesToCode, columnsShapeToCode, commitSql, constraintInnerToCode, constraintToCode, copyTableData, countSelect, createDbWithAdapter, defaultSchemaConfig, escapeForLog, escapeForMigration, escapeString, excludeInnerToCode, excludeToCode, extendQuery, filterResult, foreignKeyArgumentToCode, getClonedQueryData, getColumnBaseType, getColumnInfo, getColumnTypes, getFullColumnTable, getQueryAs, getShapeFromSelect, getSqlText, handleResult, identityToCode, indexInnerToCode, indexToCode, isDefaultTimeStamp, isInUserTransaction, isQueryReturnsAll, isSelectingCount, joinSubQuery, logParamToLogObject, makeColumnTypes, makeColumnsByType, makeFnExpression, moveQueryValueToWith, parseRecord, parseTableData, parseTableDataInput, postgisTypmodToSql, primaryKeyInnerToCode, processComputedBatches, processComputedResult, processSelectArg, pushLimitSQL, pushQueryArrayImmutable, pushQueryOn, pushQueryOnForOuter, pushQueryOrOn, pushTableDataCode, queryFrom, queryFromSql, queryJson, queryMethodByReturnType, queryTypeWithLimitOne, queryWrap, raw, referencesArgsToCode, resolveSubQueryCallbackV2, rollbackSql, saveAliasedShape, setColumnDefaultParse, setColumnEncode, setColumnParse, setColumnParseNull, setParserForSelectedString, setQueryObjectValueImmutable, setQueryOperators, simplifyColumnDefault, sqlFn, sqlQueryArgsToExpression, tableDataMethods, templateLiteralToSQL, testTransaction, throwIfJoinLateral, throwIfNoWhere, toSQL };
13435
+ export { AfterCommitError, AggregateMethods, ArrayColumn, BigIntColumn, BigSerialColumn, BitColumn, BitVaryingColumn, BooleanColumn, BoxColumn, ByteaColumn, CidrColumn, CircleColumn, CitextColumn, Clear, ColumnRefExpression, ColumnType, ComputedColumn, 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, NumberAsStringBaseColumn, NumberBaseColumn, OnMethods, Operators, OrExpression, PathColumn, PointColumn, PolygonColumn, PostgisGeographyPointColumn, QueryAsMethods, QueryGet, QueryHooks, QueryLog, QueryMethods, QueryUpsert, RawSQL, RealColumn, RefExpression, SearchMethods, Select, SerialColumn, SmallIntColumn, SmallSerialColumn, SqlMethod, StringColumn, TextBaseColumn, TextColumn, Then, TimeColumn, TimestampColumn, TimestampTZColumn, Transaction, TransformMethods, TsQueryColumn, TsVectorColumn, UUIDColumn, Union, UnknownColumn, Update, VarCharColumn, VirtualColumn, Where, WithMethods, XMLColumn, _addWith, _clone, _getSelectableColumn, _initQueryBuilder, _queryAfterSaveCommit, _queryAll, _queryChangeCounter, _queryCreate, _queryCreateForEachFrom, _queryCreateMany, _queryCreateManyFrom, _queryCreateOneFrom, _queryDefaults, _queryDelete, _queryExec, _queryFindBy, _queryFindByOptional, _queryGet, _queryGetOptional, _queryHookAfterCreate, _queryHookAfterCreateCommit, _queryHookAfterDelete, _queryHookAfterDeleteCommit, _queryHookAfterQuery, _queryHookAfterSave, _queryHookAfterUpdate, _queryHookAfterUpdateCommit, _queryHookBeforeCreate, _queryHookBeforeDelete, _queryHookBeforeQuery, _queryHookBeforeSave, _queryHookBeforeUpdate, _queryInsert, _queryInsertForEachFrom, _queryInsertMany, _queryInsertManyFrom, _queryInsertOneFrom, _queryJoinOn, _queryJoinOnJsonPathEquals, _queryJoinOrOn, _queryOr, _queryOrNot, _queryRows, _querySelect, _queryTake, _queryTakeOptional, _queryUnion, _queryUpdate, _queryUpdateOrThrow, _queryWhere, _queryWhereExists, _queryWhereIn, _queryWhereNot, _queryWhereNotOneOf, _queryWhereNotSql, _queryWhereOneOf, _queryWhereSql, _runAfterCommitHooks, addColumnParserToQuery, addParserForRawExpression, addParserForSelectItem, addQueryOn, anyShape, applyComputedColumns, assignDbDataToColumn, checkIfASimpleQuery, cloneQueryBaseUnscoped, columnCheckToCode, columnCode, columnExcludesToCode, columnForeignKeysToCode, columnIndexesToCode, columnsShapeToCode, commitSql, constraintInnerToCode, constraintToCode, copyTableData, countSelect, createDbWithAdapter, defaultSchemaConfig, escapeForLog, escapeForMigration, escapeString, excludeInnerToCode, excludeToCode, extendQuery, filterResult, foreignKeyArgumentToCode, getClonedQueryData, getColumnBaseType, getColumnInfo, getColumnTypes, getFullColumnTable, getQueryAs, getShapeFromSelect, getSqlText, handleResult, identityToCode, indexInnerToCode, indexToCode, isDefaultTimeStamp, isInUserTransaction, isQueryReturnsAll, isSelectingCount, joinSubQuery, logParamToLogObject, makeColumnTypes, makeColumnsByType, makeFnExpression, moveQueryValueToWith, parseRecord, parseTableData, parseTableDataInput, postgisTypmodToSql, primaryKeyInnerToCode, processComputedBatches, processComputedResult, processSelectArg, pushLimitSQL, pushQueryArrayImmutable, pushQueryOn, pushQueryOnForOuter, pushQueryOrOn, pushTableDataCode, queryFrom, queryFromSql, queryJson, queryMethodByReturnType, queryTypeWithLimitOne, queryWrap, raw, referencesArgsToCode, resolveSubQueryCallbackV2, rollbackSql, saveAliasedShape, setColumnDefaultParse, setColumnEncode, setColumnParse, setColumnParseNull, setParserForSelectedString, setQueryObjectValueImmutable, setQueryOperators, simplifyColumnDefault, sqlFn, sqlQueryArgsToExpression, tableDataMethods, templateLiteralToSQL, testTransaction, throwIfJoinLateral, throwIfNoWhere, toSQL };
13258
13436
  //# sourceMappingURL=index.mjs.map