drizzle-kit 0.28.1-d7e3535 → 0.28.1-ddb97ec

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.
Files changed (4) hide show
  1. package/api.js +836 -691
  2. package/api.mjs +836 -691
  3. package/bin.cjs +673 -78
  4. package/package.json +1 -1
package/api.mjs CHANGED
@@ -21126,7 +21126,7 @@ var version;
21126
21126
  var init_version = __esm({
21127
21127
  "../drizzle-orm/dist/version.js"() {
21128
21128
  "use strict";
21129
- version = "0.36.2";
21129
+ version = "0.36.4";
21130
21130
  }
21131
21131
  });
21132
21132
 
@@ -24588,9 +24588,10 @@ var init_delete = __esm({
24588
24588
  constructor(table4, session, dialect4, withList) {
24589
24589
  super();
24590
24590
  __publicField(this, "config");
24591
+ __publicField(this, "authToken");
24591
24592
  __publicField(this, "execute", (placeholderValues) => {
24592
24593
  return tracer.startActiveSpan("drizzle.operation", () => {
24593
- return this._prepare().execute(placeholderValues);
24594
+ return this._prepare().execute(placeholderValues, this.authToken);
24594
24595
  });
24595
24596
  });
24596
24597
  this.session = session;
@@ -24651,167 +24652,16 @@ var init_delete = __esm({
24651
24652
  prepare(name2) {
24652
24653
  return this._prepare(name2);
24653
24654
  }
24654
- $dynamic() {
24655
- return this;
24656
- }
24657
- };
24658
- __publicField(PgDeleteBase, _a124, "PgDelete");
24659
- }
24660
- });
24661
-
24662
- // ../drizzle-orm/dist/pg-core/query-builders/insert.js
24663
- var _a125, PgInsertBuilder, _a126, _b98, PgInsertBase;
24664
- var init_insert = __esm({
24665
- "../drizzle-orm/dist/pg-core/query-builders/insert.js"() {
24666
- "use strict";
24667
- init_entity();
24668
- init_query_promise();
24669
- init_sql();
24670
- init_table();
24671
- init_tracing();
24672
- init_utils2();
24673
- _a125 = entityKind;
24674
- PgInsertBuilder = class {
24675
- constructor(table4, session, dialect4, withList) {
24676
- this.table = table4;
24677
- this.session = session;
24678
- this.dialect = dialect4;
24679
- this.withList = withList;
24680
- }
24681
- values(values) {
24682
- values = Array.isArray(values) ? values : [values];
24683
- if (values.length === 0) {
24684
- throw new Error("values() must be called with at least one value");
24685
- }
24686
- const mappedValues = values.map((entry) => {
24687
- const result = {};
24688
- const cols = this.table[Table2.Symbol.Columns];
24689
- for (const colKey of Object.keys(entry)) {
24690
- const colValue = entry[colKey];
24691
- result[colKey] = is(colValue, SQL) ? colValue : new Param(colValue, cols[colKey]);
24692
- }
24693
- return result;
24694
- });
24695
- return new PgInsertBase(this.table, mappedValues, this.session, this.dialect, this.withList);
24696
- }
24697
- };
24698
- __publicField(PgInsertBuilder, _a125, "PgInsertBuilder");
24699
- PgInsertBase = class extends (_b98 = QueryPromise, _a126 = entityKind, _b98) {
24700
- constructor(table4, values, session, dialect4, withList) {
24701
- super();
24702
- __publicField(this, "config");
24703
- __publicField(this, "execute", (placeholderValues) => {
24704
- return tracer.startActiveSpan("drizzle.operation", () => {
24705
- return this._prepare().execute(placeholderValues);
24706
- });
24707
- });
24708
- this.session = session;
24709
- this.dialect = dialect4;
24710
- this.config = { table: table4, values, withList };
24711
- }
24712
- returning(fields = this.config.table[Table2.Symbol.Columns]) {
24713
- this.config.returning = orderSelectedFields(fields);
24714
- return this;
24715
- }
24716
- /**
24717
- * Adds an `on conflict do nothing` clause to the query.
24718
- *
24719
- * Calling this method simply avoids inserting a row as its alternative action.
24720
- *
24721
- * See docs: {@link https://orm.drizzle.team/docs/insert#on-conflict-do-nothing}
24722
- *
24723
- * @param config The `target` and `where` clauses.
24724
- *
24725
- * @example
24726
- * ```ts
24727
- * // Insert one row and cancel the insert if there's a conflict
24728
- * await db.insert(cars)
24729
- * .values({ id: 1, brand: 'BMW' })
24730
- * .onConflictDoNothing();
24731
- *
24732
- * // Explicitly specify conflict target
24733
- * await db.insert(cars)
24734
- * .values({ id: 1, brand: 'BMW' })
24735
- * .onConflictDoNothing({ target: cars.id });
24736
- * ```
24737
- */
24738
- onConflictDoNothing(config = {}) {
24739
- if (config.target === void 0) {
24740
- this.config.onConflict = sql`do nothing`;
24741
- } else {
24742
- let targetColumn = "";
24743
- targetColumn = Array.isArray(config.target) ? config.target.map((it) => this.dialect.escapeName(this.dialect.casing.getColumnCasing(it))).join(",") : this.dialect.escapeName(this.dialect.casing.getColumnCasing(config.target));
24744
- const whereSql = config.where ? sql` where ${config.where}` : void 0;
24745
- this.config.onConflict = sql`(${sql.raw(targetColumn)})${whereSql} do nothing`;
24746
- }
24747
- return this;
24748
- }
24749
- /**
24750
- * Adds an `on conflict do update` clause to the query.
24751
- *
24752
- * Calling this method will update the existing row that conflicts with the row proposed for insertion as its alternative action.
24753
- *
24754
- * See docs: {@link https://orm.drizzle.team/docs/insert#upserts-and-conflicts}
24755
- *
24756
- * @param config The `target`, `set` and `where` clauses.
24757
- *
24758
- * @example
24759
- * ```ts
24760
- * // Update the row if there's a conflict
24761
- * await db.insert(cars)
24762
- * .values({ id: 1, brand: 'BMW' })
24763
- * .onConflictDoUpdate({
24764
- * target: cars.id,
24765
- * set: { brand: 'Porsche' }
24766
- * });
24767
- *
24768
- * // Upsert with 'where' clause
24769
- * await db.insert(cars)
24770
- * .values({ id: 1, brand: 'BMW' })
24771
- * .onConflictDoUpdate({
24772
- * target: cars.id,
24773
- * set: { brand: 'newBMW' },
24774
- * targetWhere: sql`${cars.createdAt} > '2023-01-01'::date`,
24775
- * });
24776
- * ```
24777
- */
24778
- onConflictDoUpdate(config) {
24779
- if (config.where && (config.targetWhere || config.setWhere)) {
24780
- throw new Error(
24781
- 'You cannot use both "where" and "targetWhere"/"setWhere" at the same time - "where" is deprecated, use "targetWhere" or "setWhere" instead.'
24782
- );
24783
- }
24784
- const whereSql = config.where ? sql` where ${config.where}` : void 0;
24785
- const targetWhereSql = config.targetWhere ? sql` where ${config.targetWhere}` : void 0;
24786
- const setWhereSql = config.setWhere ? sql` where ${config.setWhere}` : void 0;
24787
- const setSql = this.dialect.buildUpdateSet(this.config.table, mapUpdateSet(this.config.table, config.set));
24788
- let targetColumn = "";
24789
- targetColumn = Array.isArray(config.target) ? config.target.map((it) => this.dialect.escapeName(this.dialect.casing.getColumnCasing(it))).join(",") : this.dialect.escapeName(this.dialect.casing.getColumnCasing(config.target));
24790
- this.config.onConflict = sql`(${sql.raw(targetColumn)})${targetWhereSql} do update set ${setSql}${whereSql}${setWhereSql}`;
24791
- return this;
24792
- }
24793
- /** @internal */
24794
- getSQL() {
24795
- return this.dialect.buildInsertQuery(this.config);
24796
- }
24797
- toSQL() {
24798
- const { typings: _typings, ...rest } = this.dialect.sqlToQuery(this.getSQL());
24799
- return rest;
24800
- }
24801
24655
  /** @internal */
24802
- _prepare(name2) {
24803
- return tracer.startActiveSpan("drizzle.prepareQuery", () => {
24804
- return this.session.prepareQuery(this.dialect.sqlToQuery(this.getSQL()), this.config.returning, name2, true);
24805
- });
24806
- }
24807
- prepare(name2) {
24808
- return this._prepare(name2);
24656
+ setToken(token) {
24657
+ this.authToken = token;
24658
+ return this;
24809
24659
  }
24810
24660
  $dynamic() {
24811
24661
  return this;
24812
24662
  }
24813
24663
  };
24814
- __publicField(PgInsertBase, _a126, "PgInsert");
24664
+ __publicField(PgDeleteBase, _a124, "PgDelete");
24815
24665
  }
24816
24666
  });
24817
24667
 
@@ -24830,13 +24680,13 @@ function toCamelCase(input) {
24830
24680
  function noopCase(input) {
24831
24681
  return input;
24832
24682
  }
24833
- var _a127, CasingCache;
24683
+ var _a125, CasingCache;
24834
24684
  var init_casing = __esm({
24835
24685
  "../drizzle-orm/dist/casing.js"() {
24836
24686
  "use strict";
24837
24687
  init_entity();
24838
24688
  init_table();
24839
- _a127 = entityKind;
24689
+ _a125 = entityKind;
24840
24690
  CasingCache = class {
24841
24691
  constructor(casing2) {
24842
24692
  /** @internal */
@@ -24873,25 +24723,25 @@ var init_casing = __esm({
24873
24723
  this.cachedTables = {};
24874
24724
  }
24875
24725
  };
24876
- __publicField(CasingCache, _a127, "CasingCache");
24726
+ __publicField(CasingCache, _a125, "CasingCache");
24877
24727
  }
24878
24728
  });
24879
24729
 
24880
24730
  // ../drizzle-orm/dist/pg-core/view-base.js
24881
- var _a128, _b99, PgViewBase;
24731
+ var _a126, _b98, PgViewBase;
24882
24732
  var init_view_base = __esm({
24883
24733
  "../drizzle-orm/dist/pg-core/view-base.js"() {
24884
24734
  "use strict";
24885
24735
  init_entity();
24886
24736
  init_sql();
24887
- PgViewBase = class extends (_b99 = View3, _a128 = entityKind, _b99) {
24737
+ PgViewBase = class extends (_b98 = View3, _a126 = entityKind, _b98) {
24888
24738
  };
24889
- __publicField(PgViewBase, _a128, "PgViewBase");
24739
+ __publicField(PgViewBase, _a126, "PgViewBase");
24890
24740
  }
24891
24741
  });
24892
24742
 
24893
24743
  // ../drizzle-orm/dist/pg-core/dialect.js
24894
- var _a129, PgDialect;
24744
+ var _a127, PgDialect;
24895
24745
  var init_dialect = __esm({
24896
24746
  "../drizzle-orm/dist/pg-core/dialect.js"() {
24897
24747
  "use strict";
@@ -24910,7 +24760,7 @@ var init_dialect = __esm({
24910
24760
  init_utils2();
24911
24761
  init_view_common();
24912
24762
  init_view_base();
24913
- _a129 = entityKind;
24763
+ _a127 = entityKind;
24914
24764
  PgDialect = class {
24915
24765
  constructor(config) {
24916
24766
  /** @internal */
@@ -25218,43 +25068,55 @@ var init_dialect = __esm({
25218
25068
  const offsetSql = offset ? sql` offset ${offset}` : void 0;
25219
25069
  return sql`${leftChunk}${operatorChunk}${rightChunk}${orderBySql}${limitSql}${offsetSql}`;
25220
25070
  }
25221
- buildInsertQuery({ table: table4, values, onConflict, returning, withList }) {
25071
+ buildInsertQuery({ table: table4, values: valuesOrSelect, onConflict, returning, withList, select, overridingSystemValue_ }) {
25222
25072
  const valuesSqlList = [];
25223
25073
  const columns = table4[Table2.Symbol.Columns];
25224
25074
  const colEntries = Object.entries(columns).filter(([_2, col]) => !col.shouldDisableInsert());
25225
25075
  const insertOrder = colEntries.map(
25226
25076
  ([, column4]) => sql.identifier(this.casing.getColumnCasing(column4))
25227
25077
  );
25228
- for (const [valueIndex, value] of values.entries()) {
25229
- const valueList = [];
25230
- for (const [fieldName, col] of colEntries) {
25231
- const colValue = value[fieldName];
25232
- if (colValue === void 0 || is(colValue, Param) && colValue.value === void 0) {
25233
- if (col.defaultFn !== void 0) {
25234
- const defaultFnResult = col.defaultFn();
25235
- const defaultValue = is(defaultFnResult, SQL) ? defaultFnResult : sql.param(defaultFnResult, col);
25236
- valueList.push(defaultValue);
25237
- } else if (!col.default && col.onUpdateFn !== void 0) {
25238
- const onUpdateFnResult = col.onUpdateFn();
25239
- const newValue = is(onUpdateFnResult, SQL) ? onUpdateFnResult : sql.param(onUpdateFnResult, col);
25240
- valueList.push(newValue);
25078
+ if (select) {
25079
+ const select2 = valuesOrSelect;
25080
+ if (is(select2, SQL)) {
25081
+ valuesSqlList.push(select2);
25082
+ } else {
25083
+ valuesSqlList.push(select2.getSQL());
25084
+ }
25085
+ } else {
25086
+ const values = valuesOrSelect;
25087
+ valuesSqlList.push(sql.raw("values "));
25088
+ for (const [valueIndex, value] of values.entries()) {
25089
+ const valueList = [];
25090
+ for (const [fieldName, col] of colEntries) {
25091
+ const colValue = value[fieldName];
25092
+ if (colValue === void 0 || is(colValue, Param) && colValue.value === void 0) {
25093
+ if (col.defaultFn !== void 0) {
25094
+ const defaultFnResult = col.defaultFn();
25095
+ const defaultValue = is(defaultFnResult, SQL) ? defaultFnResult : sql.param(defaultFnResult, col);
25096
+ valueList.push(defaultValue);
25097
+ } else if (!col.default && col.onUpdateFn !== void 0) {
25098
+ const onUpdateFnResult = col.onUpdateFn();
25099
+ const newValue = is(onUpdateFnResult, SQL) ? onUpdateFnResult : sql.param(onUpdateFnResult, col);
25100
+ valueList.push(newValue);
25101
+ } else {
25102
+ valueList.push(sql`default`);
25103
+ }
25241
25104
  } else {
25242
- valueList.push(sql`default`);
25105
+ valueList.push(colValue);
25243
25106
  }
25244
- } else {
25245
- valueList.push(colValue);
25246
25107
  }
25247
- }
25248
- valuesSqlList.push(valueList);
25249
- if (valueIndex < values.length - 1) {
25250
- valuesSqlList.push(sql`, `);
25108
+ valuesSqlList.push(valueList);
25109
+ if (valueIndex < values.length - 1) {
25110
+ valuesSqlList.push(sql`, `);
25111
+ }
25251
25112
  }
25252
25113
  }
25253
25114
  const withSql = this.buildWithCTE(withList);
25254
25115
  const valuesSql = sql.join(valuesSqlList);
25255
25116
  const returningSql = returning ? sql` returning ${this.buildSelection(returning, { isSingleTable: true })}` : void 0;
25256
25117
  const onConflictSql = onConflict ? sql` on conflict ${onConflict}` : void 0;
25257
- return sql`${withSql}insert into ${table4} ${insertOrder} values ${valuesSql}${onConflictSql}${returningSql}`;
25118
+ const overridingSql = overridingSystemValue_ === true ? sql`overriding system value ` : void 0;
25119
+ return sql`${withSql}insert into ${table4} ${insertOrder} ${overridingSql}${valuesSql}${onConflictSql}${returningSql}`;
25258
25120
  }
25259
25121
  buildRefreshMaterializedViewQuery({ view: view4, concurrently, withNoData }) {
25260
25122
  const concurrentlySql = concurrently ? sql` concurrently` : void 0;
@@ -25990,12 +25852,12 @@ var init_dialect = __esm({
25990
25852
  };
25991
25853
  }
25992
25854
  };
25993
- __publicField(PgDialect, _a129, "PgDialect");
25855
+ __publicField(PgDialect, _a127, "PgDialect");
25994
25856
  }
25995
25857
  });
25996
25858
 
25997
25859
  // ../drizzle-orm/dist/selection-proxy.js
25998
- var _a130, _SelectionProxyHandler, SelectionProxyHandler;
25860
+ var _a128, _SelectionProxyHandler, SelectionProxyHandler;
25999
25861
  var init_selection_proxy = __esm({
26000
25862
  "../drizzle-orm/dist/selection-proxy.js"() {
26001
25863
  "use strict";
@@ -26005,7 +25867,7 @@ var init_selection_proxy = __esm({
26005
25867
  init_sql();
26006
25868
  init_subquery();
26007
25869
  init_view_common();
26008
- _a130 = entityKind;
25870
+ _a128 = entityKind;
26009
25871
  _SelectionProxyHandler = class _SelectionProxyHandler {
26010
25872
  constructor(config) {
26011
25873
  __publicField(this, "config");
@@ -26071,25 +25933,25 @@ var init_selection_proxy = __esm({
26071
25933
  return new Proxy(value, new _SelectionProxyHandler(this.config));
26072
25934
  }
26073
25935
  };
26074
- __publicField(_SelectionProxyHandler, _a130, "SelectionProxyHandler");
25936
+ __publicField(_SelectionProxyHandler, _a128, "SelectionProxyHandler");
26075
25937
  SelectionProxyHandler = _SelectionProxyHandler;
26076
25938
  }
26077
25939
  });
26078
25940
 
26079
25941
  // ../drizzle-orm/dist/query-builders/query-builder.js
26080
- var _a131, TypedQueryBuilder;
25942
+ var _a129, TypedQueryBuilder;
26081
25943
  var init_query_builder = __esm({
26082
25944
  "../drizzle-orm/dist/query-builders/query-builder.js"() {
26083
25945
  "use strict";
26084
25946
  init_entity();
26085
- _a131 = entityKind;
25947
+ _a129 = entityKind;
26086
25948
  TypedQueryBuilder = class {
26087
25949
  /** @internal */
26088
25950
  getSelectedFields() {
26089
25951
  return this._.selectedFields;
26090
25952
  }
26091
25953
  };
26092
- __publicField(TypedQueryBuilder, _a131, "TypedQueryBuilder");
25954
+ __publicField(TypedQueryBuilder, _a129, "TypedQueryBuilder");
26093
25955
  }
26094
25956
  });
26095
25957
 
@@ -26111,7 +25973,7 @@ function createSetOperator(type, isAll) {
26111
25973
  return leftSelect.addSetOperators(setOperators);
26112
25974
  };
26113
25975
  }
26114
- var _a132, PgSelectBuilder, _a133, _b100, PgSelectQueryBuilderBase, _a134, _b101, PgSelectBase, getPgSetOperators, union, unionAll, intersect, intersectAll, except, exceptAll;
25976
+ var _a130, PgSelectBuilder, _a131, _b99, PgSelectQueryBuilderBase, _a132, _b100, PgSelectBase, getPgSetOperators, union, unionAll, intersect, intersectAll, except, exceptAll;
26115
25977
  var init_select2 = __esm({
26116
25978
  "../drizzle-orm/dist/pg-core/query-builders/select.js"() {
26117
25979
  "use strict";
@@ -26127,7 +25989,7 @@ var init_select2 = __esm({
26127
25989
  init_utils2();
26128
25990
  init_utils2();
26129
25991
  init_view_common();
26130
- _a132 = entityKind;
25992
+ _a130 = entityKind;
26131
25993
  PgSelectBuilder = class {
26132
25994
  constructor(config) {
26133
25995
  __publicField(this, "fields");
@@ -26135,6 +25997,7 @@ var init_select2 = __esm({
26135
25997
  __publicField(this, "dialect");
26136
25998
  __publicField(this, "withList", []);
26137
25999
  __publicField(this, "distinct");
26000
+ __publicField(this, "authToken");
26138
26001
  this.fields = config.fields;
26139
26002
  this.session = config.session;
26140
26003
  this.dialect = config.dialect;
@@ -26143,6 +26006,11 @@ var init_select2 = __esm({
26143
26006
  }
26144
26007
  this.distinct = config.distinct;
26145
26008
  }
26009
+ /** @internal */
26010
+ setToken(token) {
26011
+ this.authToken = token;
26012
+ return this;
26013
+ }
26146
26014
  /**
26147
26015
  * Specify the table, subquery, or other target that you're
26148
26016
  * building a select query against.
@@ -26173,11 +26041,11 @@ var init_select2 = __esm({
26173
26041
  dialect: this.dialect,
26174
26042
  withList: this.withList,
26175
26043
  distinct: this.distinct
26176
- });
26044
+ }).setToken(this.authToken);
26177
26045
  }
26178
26046
  };
26179
- __publicField(PgSelectBuilder, _a132, "PgSelectBuilder");
26180
- PgSelectQueryBuilderBase = class extends (_b100 = TypedQueryBuilder, _a133 = entityKind, _b100) {
26047
+ __publicField(PgSelectBuilder, _a130, "PgSelectBuilder");
26048
+ PgSelectQueryBuilderBase = class extends (_b99 = TypedQueryBuilder, _a131 = entityKind, _b99) {
26181
26049
  constructor({ table: table4, fields, isPartialSelect, session, dialect: dialect4, withList, distinct }) {
26182
26050
  super();
26183
26051
  __publicField(this, "_");
@@ -26777,19 +26645,20 @@ var init_select2 = __esm({
26777
26645
  return this;
26778
26646
  }
26779
26647
  };
26780
- __publicField(PgSelectQueryBuilderBase, _a133, "PgSelectQueryBuilder");
26781
- PgSelectBase = class extends (_b101 = PgSelectQueryBuilderBase, _a134 = entityKind, _b101) {
26648
+ __publicField(PgSelectQueryBuilderBase, _a131, "PgSelectQueryBuilder");
26649
+ PgSelectBase = class extends (_b100 = PgSelectQueryBuilderBase, _a132 = entityKind, _b100) {
26782
26650
  constructor() {
26783
26651
  super(...arguments);
26652
+ __publicField(this, "authToken");
26784
26653
  __publicField(this, "execute", (placeholderValues) => {
26785
26654
  return tracer.startActiveSpan("drizzle.operation", () => {
26786
- return this._prepare().execute(placeholderValues);
26655
+ return this._prepare().execute(placeholderValues, this.authToken);
26787
26656
  });
26788
26657
  });
26789
26658
  }
26790
26659
  /** @internal */
26791
26660
  _prepare(name2) {
26792
- const { session, config, dialect: dialect4, joinsNotNullableMap } = this;
26661
+ const { session, config, dialect: dialect4, joinsNotNullableMap, authToken } = this;
26793
26662
  if (!session) {
26794
26663
  throw new Error("Cannot execute a query on a query builder. Please use a database instance instead.");
26795
26664
  }
@@ -26797,7 +26666,7 @@ var init_select2 = __esm({
26797
26666
  const fieldsList = orderSelectedFields(config.fields);
26798
26667
  const query = session.prepareQuery(dialect4.sqlToQuery(this.getSQL()), fieldsList, name2, true);
26799
26668
  query.joinsNotNullableMap = joinsNotNullableMap;
26800
- return query;
26669
+ return query.setToken(authToken);
26801
26670
  });
26802
26671
  }
26803
26672
  /**
@@ -26810,8 +26679,13 @@ var init_select2 = __esm({
26810
26679
  prepare(name2) {
26811
26680
  return this._prepare(name2);
26812
26681
  }
26682
+ /** @internal */
26683
+ setToken(token) {
26684
+ this.authToken = token;
26685
+ return this;
26686
+ }
26813
26687
  };
26814
- __publicField(PgSelectBase, _a134, "PgSelect");
26688
+ __publicField(PgSelectBase, _a132, "PgSelect");
26815
26689
  applyMixins(PgSelectBase, [QueryPromise]);
26816
26690
  getPgSetOperators = () => ({
26817
26691
  union,
@@ -26831,7 +26705,7 @@ var init_select2 = __esm({
26831
26705
  });
26832
26706
 
26833
26707
  // ../drizzle-orm/dist/pg-core/query-builders/query-builder.js
26834
- var _a135, QueryBuilder;
26708
+ var _a133, QueryBuilder;
26835
26709
  var init_query_builder2 = __esm({
26836
26710
  "../drizzle-orm/dist/pg-core/query-builders/query-builder.js"() {
26837
26711
  "use strict";
@@ -26840,7 +26714,7 @@ var init_query_builder2 = __esm({
26840
26714
  init_selection_proxy();
26841
26715
  init_subquery();
26842
26716
  init_select2();
26843
- _a135 = entityKind;
26717
+ _a133 = entityKind;
26844
26718
  QueryBuilder = class {
26845
26719
  constructor(dialect4) {
26846
26720
  __publicField(this, "dialect");
@@ -26921,67 +26795,264 @@ var init_query_builder2 = __esm({
26921
26795
  return this.dialect;
26922
26796
  }
26923
26797
  };
26924
- __publicField(QueryBuilder, _a135, "PgQueryBuilder");
26798
+ __publicField(QueryBuilder, _a133, "PgQueryBuilder");
26925
26799
  }
26926
26800
  });
26927
26801
 
26928
- // ../drizzle-orm/dist/pg-core/query-builders/refresh-materialized-view.js
26929
- var _a136, _b102, PgRefreshMaterializedView;
26930
- var init_refresh_materialized_view = __esm({
26931
- "../drizzle-orm/dist/pg-core/query-builders/refresh-materialized-view.js"() {
26802
+ // ../drizzle-orm/dist/pg-core/query-builders/insert.js
26803
+ var _a134, PgInsertBuilder, _a135, _b101, PgInsertBase;
26804
+ var init_insert = __esm({
26805
+ "../drizzle-orm/dist/pg-core/query-builders/insert.js"() {
26932
26806
  "use strict";
26933
26807
  init_entity();
26934
26808
  init_query_promise();
26809
+ init_sql();
26810
+ init_table();
26935
26811
  init_tracing();
26936
- PgRefreshMaterializedView = class extends (_b102 = QueryPromise, _a136 = entityKind, _b102) {
26937
- constructor(view4, session, dialect4) {
26938
- super();
26939
- __publicField(this, "config");
26940
- __publicField(this, "execute", (placeholderValues) => {
26941
- return tracer.startActiveSpan("drizzle.operation", () => {
26942
- return this._prepare().execute(placeholderValues);
26943
- });
26944
- });
26812
+ init_utils2();
26813
+ init_query_builder2();
26814
+ _a134 = entityKind;
26815
+ PgInsertBuilder = class {
26816
+ constructor(table4, session, dialect4, withList, overridingSystemValue_) {
26817
+ __publicField(this, "authToken");
26818
+ this.table = table4;
26945
26819
  this.session = session;
26946
26820
  this.dialect = dialect4;
26947
- this.config = { view: view4 };
26821
+ this.withList = withList;
26822
+ this.overridingSystemValue_ = overridingSystemValue_;
26948
26823
  }
26949
- concurrently() {
26950
- if (this.config.withNoData !== void 0) {
26951
- throw new Error("Cannot use concurrently and withNoData together");
26952
- }
26953
- this.config.concurrently = true;
26824
+ /** @internal */
26825
+ setToken(token) {
26826
+ this.authToken = token;
26954
26827
  return this;
26955
26828
  }
26956
- withNoData() {
26957
- if (this.config.concurrently !== void 0) {
26958
- throw new Error("Cannot use concurrently and withNoData together");
26959
- }
26960
- this.config.withNoData = true;
26829
+ overridingSystemValue() {
26830
+ this.overridingSystemValue_ = true;
26961
26831
  return this;
26962
26832
  }
26963
- /** @internal */
26964
- getSQL() {
26965
- return this.dialect.buildRefreshMaterializedViewQuery(this.config);
26833
+ values(values) {
26834
+ values = Array.isArray(values) ? values : [values];
26835
+ if (values.length === 0) {
26836
+ throw new Error("values() must be called with at least one value");
26837
+ }
26838
+ const mappedValues = values.map((entry) => {
26839
+ const result = {};
26840
+ const cols = this.table[Table2.Symbol.Columns];
26841
+ for (const colKey of Object.keys(entry)) {
26842
+ const colValue = entry[colKey];
26843
+ result[colKey] = is(colValue, SQL) ? colValue : new Param(colValue, cols[colKey]);
26844
+ }
26845
+ return result;
26846
+ });
26847
+ return new PgInsertBase(
26848
+ this.table,
26849
+ mappedValues,
26850
+ this.session,
26851
+ this.dialect,
26852
+ this.withList,
26853
+ false,
26854
+ this.overridingSystemValue_
26855
+ ).setToken(this.authToken);
26966
26856
  }
26967
- toSQL() {
26968
- const { typings: _typings, ...rest } = this.dialect.sqlToQuery(this.getSQL());
26969
- return rest;
26857
+ select(selectQuery) {
26858
+ const select = typeof selectQuery === "function" ? selectQuery(new QueryBuilder()) : selectQuery;
26859
+ if (!is(select, SQL) && !haveSameKeys(this.table[Columns], select._.selectedFields)) {
26860
+ throw new Error(
26861
+ "Insert select error: selected fields are not the same or are in a different order compared to the table definition"
26862
+ );
26863
+ }
26864
+ return new PgInsertBase(this.table, select, this.session, this.dialect, this.withList, true);
26970
26865
  }
26971
- /** @internal */
26972
- _prepare(name2) {
26973
- return tracer.startActiveSpan("drizzle.prepareQuery", () => {
26974
- return this.session.prepareQuery(this.dialect.sqlToQuery(this.getSQL()), void 0, name2, true);
26866
+ };
26867
+ __publicField(PgInsertBuilder, _a134, "PgInsertBuilder");
26868
+ PgInsertBase = class extends (_b101 = QueryPromise, _a135 = entityKind, _b101) {
26869
+ constructor(table4, values, session, dialect4, withList, select, overridingSystemValue_) {
26870
+ super();
26871
+ __publicField(this, "config");
26872
+ __publicField(this, "authToken");
26873
+ __publicField(this, "execute", (placeholderValues) => {
26874
+ return tracer.startActiveSpan("drizzle.operation", () => {
26875
+ return this._prepare().execute(placeholderValues, this.authToken);
26876
+ });
26975
26877
  });
26878
+ this.session = session;
26879
+ this.dialect = dialect4;
26880
+ this.config = { table: table4, values, withList, select, overridingSystemValue_ };
26976
26881
  }
26977
- prepare(name2) {
26978
- return this._prepare(name2);
26882
+ returning(fields = this.config.table[Table2.Symbol.Columns]) {
26883
+ this.config.returning = orderSelectedFields(fields);
26884
+ return this;
26979
26885
  }
26980
- };
26981
- __publicField(PgRefreshMaterializedView, _a136, "PgRefreshMaterializedView");
26982
- }
26983
- });
26984
-
26886
+ /**
26887
+ * Adds an `on conflict do nothing` clause to the query.
26888
+ *
26889
+ * Calling this method simply avoids inserting a row as its alternative action.
26890
+ *
26891
+ * See docs: {@link https://orm.drizzle.team/docs/insert#on-conflict-do-nothing}
26892
+ *
26893
+ * @param config The `target` and `where` clauses.
26894
+ *
26895
+ * @example
26896
+ * ```ts
26897
+ * // Insert one row and cancel the insert if there's a conflict
26898
+ * await db.insert(cars)
26899
+ * .values({ id: 1, brand: 'BMW' })
26900
+ * .onConflictDoNothing();
26901
+ *
26902
+ * // Explicitly specify conflict target
26903
+ * await db.insert(cars)
26904
+ * .values({ id: 1, brand: 'BMW' })
26905
+ * .onConflictDoNothing({ target: cars.id });
26906
+ * ```
26907
+ */
26908
+ onConflictDoNothing(config = {}) {
26909
+ if (config.target === void 0) {
26910
+ this.config.onConflict = sql`do nothing`;
26911
+ } else {
26912
+ let targetColumn = "";
26913
+ targetColumn = Array.isArray(config.target) ? config.target.map((it) => this.dialect.escapeName(this.dialect.casing.getColumnCasing(it))).join(",") : this.dialect.escapeName(this.dialect.casing.getColumnCasing(config.target));
26914
+ const whereSql = config.where ? sql` where ${config.where}` : void 0;
26915
+ this.config.onConflict = sql`(${sql.raw(targetColumn)})${whereSql} do nothing`;
26916
+ }
26917
+ return this;
26918
+ }
26919
+ /**
26920
+ * Adds an `on conflict do update` clause to the query.
26921
+ *
26922
+ * Calling this method will update the existing row that conflicts with the row proposed for insertion as its alternative action.
26923
+ *
26924
+ * See docs: {@link https://orm.drizzle.team/docs/insert#upserts-and-conflicts}
26925
+ *
26926
+ * @param config The `target`, `set` and `where` clauses.
26927
+ *
26928
+ * @example
26929
+ * ```ts
26930
+ * // Update the row if there's a conflict
26931
+ * await db.insert(cars)
26932
+ * .values({ id: 1, brand: 'BMW' })
26933
+ * .onConflictDoUpdate({
26934
+ * target: cars.id,
26935
+ * set: { brand: 'Porsche' }
26936
+ * });
26937
+ *
26938
+ * // Upsert with 'where' clause
26939
+ * await db.insert(cars)
26940
+ * .values({ id: 1, brand: 'BMW' })
26941
+ * .onConflictDoUpdate({
26942
+ * target: cars.id,
26943
+ * set: { brand: 'newBMW' },
26944
+ * targetWhere: sql`${cars.createdAt} > '2023-01-01'::date`,
26945
+ * });
26946
+ * ```
26947
+ */
26948
+ onConflictDoUpdate(config) {
26949
+ if (config.where && (config.targetWhere || config.setWhere)) {
26950
+ throw new Error(
26951
+ 'You cannot use both "where" and "targetWhere"/"setWhere" at the same time - "where" is deprecated, use "targetWhere" or "setWhere" instead.'
26952
+ );
26953
+ }
26954
+ const whereSql = config.where ? sql` where ${config.where}` : void 0;
26955
+ const targetWhereSql = config.targetWhere ? sql` where ${config.targetWhere}` : void 0;
26956
+ const setWhereSql = config.setWhere ? sql` where ${config.setWhere}` : void 0;
26957
+ const setSql = this.dialect.buildUpdateSet(this.config.table, mapUpdateSet(this.config.table, config.set));
26958
+ let targetColumn = "";
26959
+ targetColumn = Array.isArray(config.target) ? config.target.map((it) => this.dialect.escapeName(this.dialect.casing.getColumnCasing(it))).join(",") : this.dialect.escapeName(this.dialect.casing.getColumnCasing(config.target));
26960
+ this.config.onConflict = sql`(${sql.raw(targetColumn)})${targetWhereSql} do update set ${setSql}${whereSql}${setWhereSql}`;
26961
+ return this;
26962
+ }
26963
+ /** @internal */
26964
+ getSQL() {
26965
+ return this.dialect.buildInsertQuery(this.config);
26966
+ }
26967
+ toSQL() {
26968
+ const { typings: _typings, ...rest } = this.dialect.sqlToQuery(this.getSQL());
26969
+ return rest;
26970
+ }
26971
+ /** @internal */
26972
+ _prepare(name2) {
26973
+ return tracer.startActiveSpan("drizzle.prepareQuery", () => {
26974
+ return this.session.prepareQuery(this.dialect.sqlToQuery(this.getSQL()), this.config.returning, name2, true);
26975
+ });
26976
+ }
26977
+ prepare(name2) {
26978
+ return this._prepare(name2);
26979
+ }
26980
+ /** @internal */
26981
+ setToken(token) {
26982
+ this.authToken = token;
26983
+ return this;
26984
+ }
26985
+ $dynamic() {
26986
+ return this;
26987
+ }
26988
+ };
26989
+ __publicField(PgInsertBase, _a135, "PgInsert");
26990
+ }
26991
+ });
26992
+
26993
+ // ../drizzle-orm/dist/pg-core/query-builders/refresh-materialized-view.js
26994
+ var _a136, _b102, PgRefreshMaterializedView;
26995
+ var init_refresh_materialized_view = __esm({
26996
+ "../drizzle-orm/dist/pg-core/query-builders/refresh-materialized-view.js"() {
26997
+ "use strict";
26998
+ init_entity();
26999
+ init_query_promise();
27000
+ init_tracing();
27001
+ PgRefreshMaterializedView = class extends (_b102 = QueryPromise, _a136 = entityKind, _b102) {
27002
+ constructor(view4, session, dialect4) {
27003
+ super();
27004
+ __publicField(this, "config");
27005
+ __publicField(this, "authToken");
27006
+ __publicField(this, "execute", (placeholderValues) => {
27007
+ return tracer.startActiveSpan("drizzle.operation", () => {
27008
+ return this._prepare().execute(placeholderValues, this.authToken);
27009
+ });
27010
+ });
27011
+ this.session = session;
27012
+ this.dialect = dialect4;
27013
+ this.config = { view: view4 };
27014
+ }
27015
+ concurrently() {
27016
+ if (this.config.withNoData !== void 0) {
27017
+ throw new Error("Cannot use concurrently and withNoData together");
27018
+ }
27019
+ this.config.concurrently = true;
27020
+ return this;
27021
+ }
27022
+ withNoData() {
27023
+ if (this.config.concurrently !== void 0) {
27024
+ throw new Error("Cannot use concurrently and withNoData together");
27025
+ }
27026
+ this.config.withNoData = true;
27027
+ return this;
27028
+ }
27029
+ /** @internal */
27030
+ getSQL() {
27031
+ return this.dialect.buildRefreshMaterializedViewQuery(this.config);
27032
+ }
27033
+ toSQL() {
27034
+ const { typings: _typings, ...rest } = this.dialect.sqlToQuery(this.getSQL());
27035
+ return rest;
27036
+ }
27037
+ /** @internal */
27038
+ _prepare(name2) {
27039
+ return tracer.startActiveSpan("drizzle.prepareQuery", () => {
27040
+ return this.session.prepareQuery(this.dialect.sqlToQuery(this.getSQL()), void 0, name2, true);
27041
+ });
27042
+ }
27043
+ prepare(name2) {
27044
+ return this._prepare(name2);
27045
+ }
27046
+ /** @internal */
27047
+ setToken(token) {
27048
+ this.authToken = token;
27049
+ return this;
27050
+ }
27051
+ };
27052
+ __publicField(PgRefreshMaterializedView, _a136, "PgRefreshMaterializedView");
27053
+ }
27054
+ });
27055
+
26985
27056
  // ../drizzle-orm/dist/pg-core/query-builders/select.types.js
26986
27057
  var init_select_types = __esm({
26987
27058
  "../drizzle-orm/dist/pg-core/query-builders/select.types.js"() {
@@ -27006,11 +27077,16 @@ var init_update = __esm({
27006
27077
  _a137 = entityKind;
27007
27078
  PgUpdateBuilder = class {
27008
27079
  constructor(table4, session, dialect4, withList) {
27080
+ __publicField(this, "authToken");
27009
27081
  this.table = table4;
27010
27082
  this.session = session;
27011
27083
  this.dialect = dialect4;
27012
27084
  this.withList = withList;
27013
27085
  }
27086
+ setToken(token) {
27087
+ this.authToken = token;
27088
+ return this;
27089
+ }
27014
27090
  set(values) {
27015
27091
  return new PgUpdateBase(
27016
27092
  this.table,
@@ -27018,7 +27094,7 @@ var init_update = __esm({
27018
27094
  this.session,
27019
27095
  this.dialect,
27020
27096
  this.withList
27021
- );
27097
+ ).setToken(this.authToken);
27022
27098
  }
27023
27099
  };
27024
27100
  __publicField(PgUpdateBuilder, _a137, "PgUpdateBuilder");
@@ -27032,8 +27108,9 @@ var init_update = __esm({
27032
27108
  __publicField(this, "rightJoin", this.createJoin("right"));
27033
27109
  __publicField(this, "innerJoin", this.createJoin("inner"));
27034
27110
  __publicField(this, "fullJoin", this.createJoin("full"));
27111
+ __publicField(this, "authToken");
27035
27112
  __publicField(this, "execute", (placeholderValues) => {
27036
- return this._prepare().execute(placeholderValues);
27113
+ return this._prepare().execute(placeholderValues, this.authToken);
27037
27114
  });
27038
27115
  this.session = session;
27039
27116
  this.dialect = dialect4;
@@ -27181,6 +27258,11 @@ var init_update = __esm({
27181
27258
  prepare(name2) {
27182
27259
  return this._prepare(name2);
27183
27260
  }
27261
+ /** @internal */
27262
+ setToken(token) {
27263
+ this.authToken = token;
27264
+ return this;
27265
+ }
27184
27266
  $dynamic() {
27185
27267
  return this;
27186
27268
  }
@@ -27214,6 +27296,7 @@ var init_count = __esm({
27214
27296
  constructor(params) {
27215
27297
  super(_PgCountBuilder.buildEmbeddedCount(params.source, params.filters).queryChunks);
27216
27298
  __publicField(this, "sql");
27299
+ __publicField(this, "token");
27217
27300
  __publicField(this, _a139, "PgCountBuilder");
27218
27301
  __publicField(this, "session");
27219
27302
  this.params = params;
@@ -27230,8 +27313,13 @@ var init_count = __esm({
27230
27313
  static buildCount(source, filters) {
27231
27314
  return sql`select count(*) as count from ${source}${sql.raw(" where ").if(filters)}${filters};`;
27232
27315
  }
27316
+ /** @intrnal */
27317
+ setToken(token) {
27318
+ this.token = token;
27319
+ return this;
27320
+ }
27233
27321
  then(onfulfilled, onrejected) {
27234
- return Promise.resolve(this.session.count(this.sql)).then(
27322
+ return Promise.resolve(this.session.count(this.sql, this.token)).then(
27235
27323
  onfulfilled,
27236
27324
  onrejected
27237
27325
  );
@@ -27308,6 +27396,7 @@ var init_query = __esm({
27308
27396
  PgRelationalQuery = class extends (_b105 = QueryPromise, _a141 = entityKind, _b105) {
27309
27397
  constructor(fullSchema, schema4, tableNamesMap, table4, tableConfig, dialect4, session, config, mode) {
27310
27398
  super();
27399
+ __publicField(this, "authToken");
27311
27400
  this.fullSchema = fullSchema;
27312
27401
  this.schema = schema4;
27313
27402
  this.tableNamesMap = tableNamesMap;
@@ -27365,9 +27454,14 @@ var init_query = __esm({
27365
27454
  toSQL() {
27366
27455
  return this._toSQL().builtQuery;
27367
27456
  }
27457
+ /** @internal */
27458
+ setToken(token) {
27459
+ this.authToken = token;
27460
+ return this;
27461
+ }
27368
27462
  execute() {
27369
27463
  return tracer.startActiveSpan("drizzle.operation", () => {
27370
- return this._prepare().execute();
27464
+ return this._prepare().execute(void 0, this.authToken);
27371
27465
  });
27372
27466
  }
27373
27467
  };
@@ -27430,6 +27524,7 @@ var init_db = __esm({
27430
27524
  PgDatabase = class {
27431
27525
  constructor(dialect4, session, schema4) {
27432
27526
  __publicField(this, "query");
27527
+ __publicField(this, "authToken");
27433
27528
  this.dialect = dialect4;
27434
27529
  this.session = session;
27435
27530
  this._ = schema4 ? {
@@ -27685,7 +27780,7 @@ var init_db = __esm({
27685
27780
  false
27686
27781
  );
27687
27782
  return new PgRaw(
27688
- () => prepared.execute(),
27783
+ () => prepared.execute(void 0, this.authToken),
27689
27784
  sequel,
27690
27785
  builtQuery,
27691
27786
  (result) => prepared.mapResult(result, true)
@@ -28230,6 +28325,7 @@ var init_session = __esm({
28230
28325
  _a159 = entityKind;
28231
28326
  PgPreparedQuery = class {
28232
28327
  constructor(query) {
28328
+ __publicField(this, "authToken");
28233
28329
  /** @internal */
28234
28330
  __publicField(this, "joinsNotNullableMap");
28235
28331
  this.query = query;
@@ -28240,6 +28336,11 @@ var init_session = __esm({
28240
28336
  mapResult(response, _isFromBatch) {
28241
28337
  return response;
28242
28338
  }
28339
+ /** @internal */
28340
+ setToken(token) {
28341
+ this.authToken = token;
28342
+ return this;
28343
+ }
28243
28344
  };
28244
28345
  __publicField(PgPreparedQuery, _a159, "PgPreparedQuery");
28245
28346
  _a160 = entityKind;
@@ -28247,7 +28348,8 @@ var init_session = __esm({
28247
28348
  constructor(dialect4) {
28248
28349
  this.dialect = dialect4;
28249
28350
  }
28250
- execute(query) {
28351
+ /** @internal */
28352
+ execute(query, token) {
28251
28353
  return tracer.startActiveSpan("drizzle.operation", () => {
28252
28354
  const prepared = tracer.startActiveSpan("drizzle.prepareQuery", () => {
28253
28355
  return this.prepareQuery(
@@ -28257,7 +28359,7 @@ var init_session = __esm({
28257
28359
  false
28258
28360
  );
28259
28361
  });
28260
- return prepared.execute();
28362
+ return prepared.setToken(token).execute(void 0, token);
28261
28363
  });
28262
28364
  }
28263
28365
  all(query) {
@@ -28268,8 +28370,9 @@ var init_session = __esm({
28268
28370
  false
28269
28371
  ).all();
28270
28372
  }
28271
- async count(sql2) {
28272
- const res = await this.execute(sql2);
28373
+ /** @internal */
28374
+ async count(sql2, token) {
28375
+ const res = await this.execute(sql2, token);
28273
28376
  return Number(
28274
28377
  res[0]["count"]
28275
28378
  );
@@ -30937,235 +31040,67 @@ var init_delete2 = __esm({
30937
31040
  }
30938
31041
  });
30939
31042
 
30940
- // ../drizzle-orm/dist/sqlite-core/query-builders/insert.js
30941
- var _a197, SQLiteInsertBuilder, _a198, _b142, SQLiteInsertBase;
30942
- var init_insert2 = __esm({
30943
- "../drizzle-orm/dist/sqlite-core/query-builders/insert.js"() {
31043
+ // ../drizzle-orm/dist/sqlite-core/view-base.js
31044
+ var _a197, _b142, SQLiteViewBase;
31045
+ var init_view_base2 = __esm({
31046
+ "../drizzle-orm/dist/sqlite-core/view-base.js"() {
30944
31047
  "use strict";
30945
31048
  init_entity();
30946
- init_query_promise();
30947
31049
  init_sql();
31050
+ SQLiteViewBase = class extends (_b142 = View3, _a197 = entityKind, _b142) {
31051
+ };
31052
+ __publicField(SQLiteViewBase, _a197, "SQLiteViewBase");
31053
+ }
31054
+ });
31055
+
31056
+ // ../drizzle-orm/dist/sqlite-core/dialect.js
31057
+ var _a198, SQLiteDialect, _a199, _b143, SQLiteSyncDialect, _a200, _b144, SQLiteAsyncDialect;
31058
+ var init_dialect2 = __esm({
31059
+ "../drizzle-orm/dist/sqlite-core/dialect.js"() {
31060
+ "use strict";
31061
+ init_alias();
31062
+ init_casing();
31063
+ init_column();
31064
+ init_entity();
31065
+ init_errors();
31066
+ init_relations();
31067
+ init_sql2();
31068
+ init_sql();
31069
+ init_columns2();
30948
31070
  init_table3();
31071
+ init_subquery();
30949
31072
  init_table();
30950
31073
  init_utils2();
30951
- _a197 = entityKind;
30952
- SQLiteInsertBuilder = class {
30953
- constructor(table4, session, dialect4, withList) {
30954
- this.table = table4;
30955
- this.session = session;
30956
- this.dialect = dialect4;
30957
- this.withList = withList;
31074
+ init_view_common();
31075
+ init_view_base2();
31076
+ _a198 = entityKind;
31077
+ SQLiteDialect = class {
31078
+ constructor(config) {
31079
+ /** @internal */
31080
+ __publicField(this, "casing");
31081
+ this.casing = new CasingCache(config?.casing);
30958
31082
  }
30959
- values(values) {
30960
- values = Array.isArray(values) ? values : [values];
30961
- if (values.length === 0) {
30962
- throw new Error("values() must be called with at least one value");
30963
- }
30964
- const mappedValues = values.map((entry) => {
30965
- const result = {};
30966
- const cols = this.table[Table2.Symbol.Columns];
30967
- for (const colKey of Object.keys(entry)) {
30968
- const colValue = entry[colKey];
30969
- result[colKey] = is(colValue, SQL) ? colValue : new Param(colValue, cols[colKey]);
31083
+ escapeName(name2) {
31084
+ return `"${name2}"`;
31085
+ }
31086
+ escapeParam(_num) {
31087
+ return "?";
31088
+ }
31089
+ escapeString(str) {
31090
+ return `'${str.replace(/'/g, "''")}'`;
31091
+ }
31092
+ buildWithCTE(queries) {
31093
+ if (!queries?.length)
31094
+ return void 0;
31095
+ const withSqlChunks = [sql`with `];
31096
+ for (const [i, w] of queries.entries()) {
31097
+ withSqlChunks.push(sql`${sql.identifier(w._.alias)} as (${w._.sql})`);
31098
+ if (i < queries.length - 1) {
31099
+ withSqlChunks.push(sql`, `);
30970
31100
  }
30971
- return result;
30972
- });
30973
- return new SQLiteInsertBase(this.table, mappedValues, this.session, this.dialect, this.withList);
30974
- }
30975
- };
30976
- __publicField(SQLiteInsertBuilder, _a197, "SQLiteInsertBuilder");
30977
- SQLiteInsertBase = class extends (_b142 = QueryPromise, _a198 = entityKind, _b142) {
30978
- constructor(table4, values, session, dialect4, withList) {
30979
- super();
30980
- /** @internal */
30981
- __publicField(this, "config");
30982
- __publicField(this, "run", (placeholderValues) => {
30983
- return this._prepare().run(placeholderValues);
30984
- });
30985
- __publicField(this, "all", (placeholderValues) => {
30986
- return this._prepare().all(placeholderValues);
30987
- });
30988
- __publicField(this, "get", (placeholderValues) => {
30989
- return this._prepare().get(placeholderValues);
30990
- });
30991
- __publicField(this, "values", (placeholderValues) => {
30992
- return this._prepare().values(placeholderValues);
30993
- });
30994
- this.session = session;
30995
- this.dialect = dialect4;
30996
- this.config = { table: table4, values, withList };
30997
- }
30998
- returning(fields = this.config.table[SQLiteTable.Symbol.Columns]) {
30999
- this.config.returning = orderSelectedFields(fields);
31000
- return this;
31001
- }
31002
- /**
31003
- * Adds an `on conflict do nothing` clause to the query.
31004
- *
31005
- * Calling this method simply avoids inserting a row as its alternative action.
31006
- *
31007
- * See docs: {@link https://orm.drizzle.team/docs/insert#on-conflict-do-nothing}
31008
- *
31009
- * @param config The `target` and `where` clauses.
31010
- *
31011
- * @example
31012
- * ```ts
31013
- * // Insert one row and cancel the insert if there's a conflict
31014
- * await db.insert(cars)
31015
- * .values({ id: 1, brand: 'BMW' })
31016
- * .onConflictDoNothing();
31017
- *
31018
- * // Explicitly specify conflict target
31019
- * await db.insert(cars)
31020
- * .values({ id: 1, brand: 'BMW' })
31021
- * .onConflictDoNothing({ target: cars.id });
31022
- * ```
31023
- */
31024
- onConflictDoNothing(config = {}) {
31025
- if (config.target === void 0) {
31026
- this.config.onConflict = sql`do nothing`;
31027
- } else {
31028
- const targetSql = Array.isArray(config.target) ? sql`${config.target}` : sql`${[config.target]}`;
31029
- const whereSql = config.where ? sql` where ${config.where}` : sql``;
31030
- this.config.onConflict = sql`${targetSql} do nothing${whereSql}`;
31031
- }
31032
- return this;
31033
- }
31034
- /**
31035
- * Adds an `on conflict do update` clause to the query.
31036
- *
31037
- * Calling this method will update the existing row that conflicts with the row proposed for insertion as its alternative action.
31038
- *
31039
- * See docs: {@link https://orm.drizzle.team/docs/insert#upserts-and-conflicts}
31040
- *
31041
- * @param config The `target`, `set` and `where` clauses.
31042
- *
31043
- * @example
31044
- * ```ts
31045
- * // Update the row if there's a conflict
31046
- * await db.insert(cars)
31047
- * .values({ id: 1, brand: 'BMW' })
31048
- * .onConflictDoUpdate({
31049
- * target: cars.id,
31050
- * set: { brand: 'Porsche' }
31051
- * });
31052
- *
31053
- * // Upsert with 'where' clause
31054
- * await db.insert(cars)
31055
- * .values({ id: 1, brand: 'BMW' })
31056
- * .onConflictDoUpdate({
31057
- * target: cars.id,
31058
- * set: { brand: 'newBMW' },
31059
- * where: sql`${cars.createdAt} > '2023-01-01'::date`,
31060
- * });
31061
- * ```
31062
- */
31063
- onConflictDoUpdate(config) {
31064
- if (config.where && (config.targetWhere || config.setWhere)) {
31065
- throw new Error(
31066
- 'You cannot use both "where" and "targetWhere"/"setWhere" at the same time - "where" is deprecated, use "targetWhere" or "setWhere" instead.'
31067
- );
31068
- }
31069
- const whereSql = config.where ? sql` where ${config.where}` : void 0;
31070
- const targetWhereSql = config.targetWhere ? sql` where ${config.targetWhere}` : void 0;
31071
- const setWhereSql = config.setWhere ? sql` where ${config.setWhere}` : void 0;
31072
- const targetSql = Array.isArray(config.target) ? sql`${config.target}` : sql`${[config.target]}`;
31073
- const setSql = this.dialect.buildUpdateSet(this.config.table, mapUpdateSet(this.config.table, config.set));
31074
- this.config.onConflict = sql`${targetSql}${targetWhereSql} do update set ${setSql}${whereSql}${setWhereSql}`;
31075
- return this;
31076
- }
31077
- /** @internal */
31078
- getSQL() {
31079
- return this.dialect.buildInsertQuery(this.config);
31080
- }
31081
- toSQL() {
31082
- const { typings: _typings, ...rest } = this.dialect.sqlToQuery(this.getSQL());
31083
- return rest;
31084
- }
31085
- /** @internal */
31086
- _prepare(isOneTimeQuery = true) {
31087
- return this.session[isOneTimeQuery ? "prepareOneTimeQuery" : "prepareQuery"](
31088
- this.dialect.sqlToQuery(this.getSQL()),
31089
- this.config.returning,
31090
- this.config.returning ? "all" : "run",
31091
- true
31092
- );
31093
- }
31094
- prepare() {
31095
- return this._prepare(false);
31096
- }
31097
- async execute() {
31098
- return this.config.returning ? this.all() : this.run();
31099
- }
31100
- $dynamic() {
31101
- return this;
31102
- }
31103
- };
31104
- __publicField(SQLiteInsertBase, _a198, "SQLiteInsert");
31105
- }
31106
- });
31107
-
31108
- // ../drizzle-orm/dist/sqlite-core/view-base.js
31109
- var _a199, _b143, SQLiteViewBase;
31110
- var init_view_base2 = __esm({
31111
- "../drizzle-orm/dist/sqlite-core/view-base.js"() {
31112
- "use strict";
31113
- init_entity();
31114
- init_sql();
31115
- SQLiteViewBase = class extends (_b143 = View3, _a199 = entityKind, _b143) {
31116
- };
31117
- __publicField(SQLiteViewBase, _a199, "SQLiteViewBase");
31118
- }
31119
- });
31120
-
31121
- // ../drizzle-orm/dist/sqlite-core/dialect.js
31122
- var _a200, SQLiteDialect, _a201, _b144, SQLiteSyncDialect, _a202, _b145, SQLiteAsyncDialect;
31123
- var init_dialect2 = __esm({
31124
- "../drizzle-orm/dist/sqlite-core/dialect.js"() {
31125
- "use strict";
31126
- init_alias();
31127
- init_casing();
31128
- init_column();
31129
- init_entity();
31130
- init_errors();
31131
- init_relations();
31132
- init_sql2();
31133
- init_sql();
31134
- init_columns2();
31135
- init_table3();
31136
- init_subquery();
31137
- init_table();
31138
- init_utils2();
31139
- init_view_common();
31140
- init_view_base2();
31141
- _a200 = entityKind;
31142
- SQLiteDialect = class {
31143
- constructor(config) {
31144
- /** @internal */
31145
- __publicField(this, "casing");
31146
- this.casing = new CasingCache(config?.casing);
31147
- }
31148
- escapeName(name2) {
31149
- return `"${name2}"`;
31150
- }
31151
- escapeParam(_num) {
31152
- return "?";
31153
- }
31154
- escapeString(str) {
31155
- return `'${str.replace(/'/g, "''")}'`;
31156
- }
31157
- buildWithCTE(queries) {
31158
- if (!queries?.length)
31159
- return void 0;
31160
- const withSqlChunks = [sql`with `];
31161
- for (const [i, w] of queries.entries()) {
31162
- withSqlChunks.push(sql`${sql.identifier(w._.alias)} as (${w._.sql})`);
31163
- if (i < queries.length - 1) {
31164
- withSqlChunks.push(sql`, `);
31165
- }
31166
- }
31167
- withSqlChunks.push(sql` `);
31168
- return sql.join(withSqlChunks);
31101
+ }
31102
+ withSqlChunks.push(sql` `);
31103
+ return sql.join(withSqlChunks);
31169
31104
  }
31170
31105
  buildDeleteQuery({ table: table4, where, returning, withList, limit, orderBy }) {
31171
31106
  const withSql = this.buildWithCTE(withList);
@@ -31402,45 +31337,56 @@ var init_dialect2 = __esm({
31402
31337
  const offsetSql = offset ? sql` offset ${offset}` : void 0;
31403
31338
  return sql`${leftChunk}${operatorChunk}${rightChunk}${orderBySql}${limitSql}${offsetSql}`;
31404
31339
  }
31405
- buildInsertQuery({ table: table4, values, onConflict, returning, withList }) {
31340
+ buildInsertQuery({ table: table4, values: valuesOrSelect, onConflict, returning, withList, select }) {
31406
31341
  const valuesSqlList = [];
31407
31342
  const columns = table4[Table2.Symbol.Columns];
31408
31343
  const colEntries = Object.entries(columns).filter(
31409
31344
  ([_2, col]) => !col.shouldDisableInsert()
31410
31345
  );
31411
31346
  const insertOrder = colEntries.map(([, column4]) => sql.identifier(this.casing.getColumnCasing(column4)));
31412
- for (const [valueIndex, value] of values.entries()) {
31413
- const valueList = [];
31414
- for (const [fieldName, col] of colEntries) {
31415
- const colValue = value[fieldName];
31416
- if (colValue === void 0 || is(colValue, Param) && colValue.value === void 0) {
31417
- let defaultValue;
31418
- if (col.default !== null && col.default !== void 0) {
31419
- defaultValue = is(col.default, SQL) ? col.default : sql.param(col.default, col);
31420
- } else if (col.defaultFn !== void 0) {
31421
- const defaultFnResult = col.defaultFn();
31422
- defaultValue = is(defaultFnResult, SQL) ? defaultFnResult : sql.param(defaultFnResult, col);
31423
- } else if (!col.default && col.onUpdateFn !== void 0) {
31424
- const onUpdateFnResult = col.onUpdateFn();
31425
- defaultValue = is(onUpdateFnResult, SQL) ? onUpdateFnResult : sql.param(onUpdateFnResult, col);
31347
+ if (select) {
31348
+ const select2 = valuesOrSelect;
31349
+ if (is(select2, SQL)) {
31350
+ valuesSqlList.push(select2);
31351
+ } else {
31352
+ valuesSqlList.push(select2.getSQL());
31353
+ }
31354
+ } else {
31355
+ const values = valuesOrSelect;
31356
+ valuesSqlList.push(sql.raw("values "));
31357
+ for (const [valueIndex, value] of values.entries()) {
31358
+ const valueList = [];
31359
+ for (const [fieldName, col] of colEntries) {
31360
+ const colValue = value[fieldName];
31361
+ if (colValue === void 0 || is(colValue, Param) && colValue.value === void 0) {
31362
+ let defaultValue;
31363
+ if (col.default !== null && col.default !== void 0) {
31364
+ defaultValue = is(col.default, SQL) ? col.default : sql.param(col.default, col);
31365
+ } else if (col.defaultFn !== void 0) {
31366
+ const defaultFnResult = col.defaultFn();
31367
+ defaultValue = is(defaultFnResult, SQL) ? defaultFnResult : sql.param(defaultFnResult, col);
31368
+ } else if (!col.default && col.onUpdateFn !== void 0) {
31369
+ const onUpdateFnResult = col.onUpdateFn();
31370
+ defaultValue = is(onUpdateFnResult, SQL) ? onUpdateFnResult : sql.param(onUpdateFnResult, col);
31371
+ } else {
31372
+ defaultValue = sql`null`;
31373
+ }
31374
+ valueList.push(defaultValue);
31426
31375
  } else {
31427
- defaultValue = sql`null`;
31376
+ valueList.push(colValue);
31428
31377
  }
31429
- valueList.push(defaultValue);
31430
- } else {
31431
- valueList.push(colValue);
31432
31378
  }
31433
- }
31434
- valuesSqlList.push(valueList);
31435
- if (valueIndex < values.length - 1) {
31436
- valuesSqlList.push(sql`, `);
31379
+ valuesSqlList.push(valueList);
31380
+ if (valueIndex < values.length - 1) {
31381
+ valuesSqlList.push(sql`, `);
31382
+ }
31437
31383
  }
31438
31384
  }
31439
31385
  const withSql = this.buildWithCTE(withList);
31440
31386
  const valuesSql = sql.join(valuesSqlList);
31441
31387
  const returningSql = returning ? sql` returning ${this.buildSelection(returning, { isSingleTable: true })}` : void 0;
31442
31388
  const onConflictSql = onConflict ? sql` on conflict ${onConflict}` : void 0;
31443
- return sql`${withSql}insert into ${table4} ${insertOrder} values ${valuesSql}${onConflictSql}${returningSql}`;
31389
+ return sql`${withSql}insert into ${table4} ${insertOrder} ${valuesSql}${onConflictSql}${returningSql}`;
31444
31390
  }
31445
31391
  sqlToQuery(sql2, invokeSource) {
31446
31392
  return sql2.toQuery({
@@ -31669,8 +31615,8 @@ var init_dialect2 = __esm({
31669
31615
  };
31670
31616
  }
31671
31617
  };
31672
- __publicField(SQLiteDialect, _a200, "SQLiteDialect");
31673
- SQLiteSyncDialect = class extends (_b144 = SQLiteDialect, _a201 = entityKind, _b144) {
31618
+ __publicField(SQLiteDialect, _a198, "SQLiteDialect");
31619
+ SQLiteSyncDialect = class extends (_b143 = SQLiteDialect, _a199 = entityKind, _b143) {
31674
31620
  migrate(migrations, session, config) {
31675
31621
  const migrationsTable = config === void 0 ? "__drizzle_migrations" : typeof config === "string" ? "__drizzle_migrations" : config.migrationsTable ?? "__drizzle_migrations";
31676
31622
  const migrationTableCreate = sql`
@@ -31704,8 +31650,8 @@ var init_dialect2 = __esm({
31704
31650
  }
31705
31651
  }
31706
31652
  };
31707
- __publicField(SQLiteSyncDialect, _a201, "SQLiteSyncDialect");
31708
- SQLiteAsyncDialect = class extends (_b145 = SQLiteDialect, _a202 = entityKind, _b145) {
31653
+ __publicField(SQLiteSyncDialect, _a199, "SQLiteSyncDialect");
31654
+ SQLiteAsyncDialect = class extends (_b144 = SQLiteDialect, _a200 = entityKind, _b144) {
31709
31655
  async migrate(migrations, session, config) {
31710
31656
  const migrationsTable = config === void 0 ? "__drizzle_migrations" : typeof config === "string" ? "__drizzle_migrations" : config.migrationsTable ?? "__drizzle_migrations";
31711
31657
  const migrationTableCreate = sql`
@@ -31734,7 +31680,7 @@ var init_dialect2 = __esm({
31734
31680
  });
31735
31681
  }
31736
31682
  };
31737
- __publicField(SQLiteAsyncDialect, _a202, "SQLiteAsyncDialect");
31683
+ __publicField(SQLiteAsyncDialect, _a200, "SQLiteAsyncDialect");
31738
31684
  }
31739
31685
  });
31740
31686
 
@@ -31756,7 +31702,7 @@ function createSetOperator2(type, isAll) {
31756
31702
  return leftSelect.addSetOperators(setOperators);
31757
31703
  };
31758
31704
  }
31759
- var _a203, SQLiteSelectBuilder, _a204, _b146, SQLiteSelectQueryBuilderBase, _a205, _b147, SQLiteSelectBase, getSQLiteSetOperators, union2, unionAll2, intersect2, except2;
31705
+ var _a201, SQLiteSelectBuilder, _a202, _b145, SQLiteSelectQueryBuilderBase, _a203, _b146, SQLiteSelectBase, getSQLiteSetOperators, union2, unionAll2, intersect2, except2;
31760
31706
  var init_select3 = __esm({
31761
31707
  "../drizzle-orm/dist/sqlite-core/query-builders/select.js"() {
31762
31708
  "use strict";
@@ -31770,7 +31716,7 @@ var init_select3 = __esm({
31770
31716
  init_utils2();
31771
31717
  init_view_common();
31772
31718
  init_view_base2();
31773
- _a203 = entityKind;
31719
+ _a201 = entityKind;
31774
31720
  SQLiteSelectBuilder = class {
31775
31721
  constructor(config) {
31776
31722
  __publicField(this, "fields");
@@ -31811,8 +31757,8 @@ var init_select3 = __esm({
31811
31757
  });
31812
31758
  }
31813
31759
  };
31814
- __publicField(SQLiteSelectBuilder, _a203, "SQLiteSelectBuilder");
31815
- SQLiteSelectQueryBuilderBase = class extends (_b146 = TypedQueryBuilder, _a204 = entityKind, _b146) {
31760
+ __publicField(SQLiteSelectBuilder, _a201, "SQLiteSelectBuilder");
31761
+ SQLiteSelectQueryBuilderBase = class extends (_b145 = TypedQueryBuilder, _a202 = entityKind, _b145) {
31816
31762
  constructor({ table: table4, fields, isPartialSelect, session, dialect: dialect4, withList, distinct }) {
31817
31763
  super();
31818
31764
  __publicField(this, "_");
@@ -32317,8 +32263,8 @@ var init_select3 = __esm({
32317
32263
  return this;
32318
32264
  }
32319
32265
  };
32320
- __publicField(SQLiteSelectQueryBuilderBase, _a204, "SQLiteSelectQueryBuilder");
32321
- SQLiteSelectBase = class extends (_b147 = SQLiteSelectQueryBuilderBase, _a205 = entityKind, _b147) {
32266
+ __publicField(SQLiteSelectQueryBuilderBase, _a202, "SQLiteSelectQueryBuilder");
32267
+ SQLiteSelectBase = class extends (_b146 = SQLiteSelectQueryBuilderBase, _a203 = entityKind, _b146) {
32322
32268
  constructor() {
32323
32269
  super(...arguments);
32324
32270
  __publicField(this, "run", (placeholderValues) => {
@@ -32356,7 +32302,7 @@ var init_select3 = __esm({
32356
32302
  return this.all();
32357
32303
  }
32358
32304
  };
32359
- __publicField(SQLiteSelectBase, _a205, "SQLiteSelect");
32305
+ __publicField(SQLiteSelectBase, _a203, "SQLiteSelect");
32360
32306
  applyMixins(SQLiteSelectBase, [QueryPromise]);
32361
32307
  getSQLiteSetOperators = () => ({
32362
32308
  union: union2,
@@ -32372,7 +32318,7 @@ var init_select3 = __esm({
32372
32318
  });
32373
32319
 
32374
32320
  // ../drizzle-orm/dist/sqlite-core/query-builders/query-builder.js
32375
- var _a206, QueryBuilder2;
32321
+ var _a204, QueryBuilder2;
32376
32322
  var init_query_builder3 = __esm({
32377
32323
  "../drizzle-orm/dist/sqlite-core/query-builders/query-builder.js"() {
32378
32324
  "use strict";
@@ -32381,7 +32327,7 @@ var init_query_builder3 = __esm({
32381
32327
  init_dialect2();
32382
32328
  init_subquery();
32383
32329
  init_select3();
32384
- _a206 = entityKind;
32330
+ _a204 = entityKind;
32385
32331
  QueryBuilder2 = class {
32386
32332
  constructor(dialect4) {
32387
32333
  __publicField(this, "dialect");
@@ -32443,7 +32389,185 @@ var init_query_builder3 = __esm({
32443
32389
  return this.dialect;
32444
32390
  }
32445
32391
  };
32446
- __publicField(QueryBuilder2, _a206, "SQLiteQueryBuilder");
32392
+ __publicField(QueryBuilder2, _a204, "SQLiteQueryBuilder");
32393
+ }
32394
+ });
32395
+
32396
+ // ../drizzle-orm/dist/sqlite-core/query-builders/insert.js
32397
+ var _a205, SQLiteInsertBuilder, _a206, _b147, SQLiteInsertBase;
32398
+ var init_insert2 = __esm({
32399
+ "../drizzle-orm/dist/sqlite-core/query-builders/insert.js"() {
32400
+ "use strict";
32401
+ init_entity();
32402
+ init_query_promise();
32403
+ init_sql();
32404
+ init_table3();
32405
+ init_table();
32406
+ init_utils2();
32407
+ init_query_builder3();
32408
+ _a205 = entityKind;
32409
+ SQLiteInsertBuilder = class {
32410
+ constructor(table4, session, dialect4, withList) {
32411
+ this.table = table4;
32412
+ this.session = session;
32413
+ this.dialect = dialect4;
32414
+ this.withList = withList;
32415
+ }
32416
+ values(values) {
32417
+ values = Array.isArray(values) ? values : [values];
32418
+ if (values.length === 0) {
32419
+ throw new Error("values() must be called with at least one value");
32420
+ }
32421
+ const mappedValues = values.map((entry) => {
32422
+ const result = {};
32423
+ const cols = this.table[Table2.Symbol.Columns];
32424
+ for (const colKey of Object.keys(entry)) {
32425
+ const colValue = entry[colKey];
32426
+ result[colKey] = is(colValue, SQL) ? colValue : new Param(colValue, cols[colKey]);
32427
+ }
32428
+ return result;
32429
+ });
32430
+ return new SQLiteInsertBase(this.table, mappedValues, this.session, this.dialect, this.withList);
32431
+ }
32432
+ select(selectQuery) {
32433
+ const select = typeof selectQuery === "function" ? selectQuery(new QueryBuilder2()) : selectQuery;
32434
+ if (!is(select, SQL) && !haveSameKeys(this.table[Columns], select._.selectedFields)) {
32435
+ throw new Error(
32436
+ "Insert select error: selected fields are not the same or are in a different order compared to the table definition"
32437
+ );
32438
+ }
32439
+ return new SQLiteInsertBase(this.table, select, this.session, this.dialect, this.withList, true);
32440
+ }
32441
+ };
32442
+ __publicField(SQLiteInsertBuilder, _a205, "SQLiteInsertBuilder");
32443
+ SQLiteInsertBase = class extends (_b147 = QueryPromise, _a206 = entityKind, _b147) {
32444
+ constructor(table4, values, session, dialect4, withList, select) {
32445
+ super();
32446
+ /** @internal */
32447
+ __publicField(this, "config");
32448
+ __publicField(this, "run", (placeholderValues) => {
32449
+ return this._prepare().run(placeholderValues);
32450
+ });
32451
+ __publicField(this, "all", (placeholderValues) => {
32452
+ return this._prepare().all(placeholderValues);
32453
+ });
32454
+ __publicField(this, "get", (placeholderValues) => {
32455
+ return this._prepare().get(placeholderValues);
32456
+ });
32457
+ __publicField(this, "values", (placeholderValues) => {
32458
+ return this._prepare().values(placeholderValues);
32459
+ });
32460
+ this.session = session;
32461
+ this.dialect = dialect4;
32462
+ this.config = { table: table4, values, withList, select };
32463
+ }
32464
+ returning(fields = this.config.table[SQLiteTable.Symbol.Columns]) {
32465
+ this.config.returning = orderSelectedFields(fields);
32466
+ return this;
32467
+ }
32468
+ /**
32469
+ * Adds an `on conflict do nothing` clause to the query.
32470
+ *
32471
+ * Calling this method simply avoids inserting a row as its alternative action.
32472
+ *
32473
+ * See docs: {@link https://orm.drizzle.team/docs/insert#on-conflict-do-nothing}
32474
+ *
32475
+ * @param config The `target` and `where` clauses.
32476
+ *
32477
+ * @example
32478
+ * ```ts
32479
+ * // Insert one row and cancel the insert if there's a conflict
32480
+ * await db.insert(cars)
32481
+ * .values({ id: 1, brand: 'BMW' })
32482
+ * .onConflictDoNothing();
32483
+ *
32484
+ * // Explicitly specify conflict target
32485
+ * await db.insert(cars)
32486
+ * .values({ id: 1, brand: 'BMW' })
32487
+ * .onConflictDoNothing({ target: cars.id });
32488
+ * ```
32489
+ */
32490
+ onConflictDoNothing(config = {}) {
32491
+ if (config.target === void 0) {
32492
+ this.config.onConflict = sql`do nothing`;
32493
+ } else {
32494
+ const targetSql = Array.isArray(config.target) ? sql`${config.target}` : sql`${[config.target]}`;
32495
+ const whereSql = config.where ? sql` where ${config.where}` : sql``;
32496
+ this.config.onConflict = sql`${targetSql} do nothing${whereSql}`;
32497
+ }
32498
+ return this;
32499
+ }
32500
+ /**
32501
+ * Adds an `on conflict do update` clause to the query.
32502
+ *
32503
+ * Calling this method will update the existing row that conflicts with the row proposed for insertion as its alternative action.
32504
+ *
32505
+ * See docs: {@link https://orm.drizzle.team/docs/insert#upserts-and-conflicts}
32506
+ *
32507
+ * @param config The `target`, `set` and `where` clauses.
32508
+ *
32509
+ * @example
32510
+ * ```ts
32511
+ * // Update the row if there's a conflict
32512
+ * await db.insert(cars)
32513
+ * .values({ id: 1, brand: 'BMW' })
32514
+ * .onConflictDoUpdate({
32515
+ * target: cars.id,
32516
+ * set: { brand: 'Porsche' }
32517
+ * });
32518
+ *
32519
+ * // Upsert with 'where' clause
32520
+ * await db.insert(cars)
32521
+ * .values({ id: 1, brand: 'BMW' })
32522
+ * .onConflictDoUpdate({
32523
+ * target: cars.id,
32524
+ * set: { brand: 'newBMW' },
32525
+ * where: sql`${cars.createdAt} > '2023-01-01'::date`,
32526
+ * });
32527
+ * ```
32528
+ */
32529
+ onConflictDoUpdate(config) {
32530
+ if (config.where && (config.targetWhere || config.setWhere)) {
32531
+ throw new Error(
32532
+ 'You cannot use both "where" and "targetWhere"/"setWhere" at the same time - "where" is deprecated, use "targetWhere" or "setWhere" instead.'
32533
+ );
32534
+ }
32535
+ const whereSql = config.where ? sql` where ${config.where}` : void 0;
32536
+ const targetWhereSql = config.targetWhere ? sql` where ${config.targetWhere}` : void 0;
32537
+ const setWhereSql = config.setWhere ? sql` where ${config.setWhere}` : void 0;
32538
+ const targetSql = Array.isArray(config.target) ? sql`${config.target}` : sql`${[config.target]}`;
32539
+ const setSql = this.dialect.buildUpdateSet(this.config.table, mapUpdateSet(this.config.table, config.set));
32540
+ this.config.onConflict = sql`${targetSql}${targetWhereSql} do update set ${setSql}${whereSql}${setWhereSql}`;
32541
+ return this;
32542
+ }
32543
+ /** @internal */
32544
+ getSQL() {
32545
+ return this.dialect.buildInsertQuery(this.config);
32546
+ }
32547
+ toSQL() {
32548
+ const { typings: _typings, ...rest } = this.dialect.sqlToQuery(this.getSQL());
32549
+ return rest;
32550
+ }
32551
+ /** @internal */
32552
+ _prepare(isOneTimeQuery = true) {
32553
+ return this.session[isOneTimeQuery ? "prepareOneTimeQuery" : "prepareQuery"](
32554
+ this.dialect.sqlToQuery(this.getSQL()),
32555
+ this.config.returning,
32556
+ this.config.returning ? "all" : "run",
32557
+ true
32558
+ );
32559
+ }
32560
+ prepare() {
32561
+ return this._prepare(false);
32562
+ }
32563
+ async execute() {
32564
+ return this.config.returning ? this.all() : this.run();
32565
+ }
32566
+ $dynamic() {
32567
+ return this;
32568
+ }
32569
+ };
32570
+ __publicField(SQLiteInsertBase, _a206, "SQLiteInsert");
32447
32571
  }
32448
32572
  });
32449
32573
 
@@ -35835,131 +35959,6 @@ var init_delete3 = __esm({
35835
35959
  }
35836
35960
  });
35837
35961
 
35838
- // ../drizzle-orm/dist/mysql-core/query-builders/insert.js
35839
- var _a299, MySqlInsertBuilder, _a300, _b222, MySqlInsertBase;
35840
- var init_insert3 = __esm({
35841
- "../drizzle-orm/dist/mysql-core/query-builders/insert.js"() {
35842
- "use strict";
35843
- init_entity();
35844
- init_query_promise();
35845
- init_sql();
35846
- init_table();
35847
- init_utils2();
35848
- _a299 = entityKind;
35849
- MySqlInsertBuilder = class {
35850
- constructor(table4, session, dialect4) {
35851
- __publicField(this, "shouldIgnore", false);
35852
- this.table = table4;
35853
- this.session = session;
35854
- this.dialect = dialect4;
35855
- }
35856
- ignore() {
35857
- this.shouldIgnore = true;
35858
- return this;
35859
- }
35860
- values(values) {
35861
- values = Array.isArray(values) ? values : [values];
35862
- if (values.length === 0) {
35863
- throw new Error("values() must be called with at least one value");
35864
- }
35865
- const mappedValues = values.map((entry) => {
35866
- const result = {};
35867
- const cols = this.table[Table2.Symbol.Columns];
35868
- for (const colKey of Object.keys(entry)) {
35869
- const colValue = entry[colKey];
35870
- result[colKey] = is(colValue, SQL) ? colValue : new Param(colValue, cols[colKey]);
35871
- }
35872
- return result;
35873
- });
35874
- return new MySqlInsertBase(this.table, mappedValues, this.shouldIgnore, this.session, this.dialect);
35875
- }
35876
- };
35877
- __publicField(MySqlInsertBuilder, _a299, "MySqlInsertBuilder");
35878
- MySqlInsertBase = class extends (_b222 = QueryPromise, _a300 = entityKind, _b222) {
35879
- constructor(table4, values, ignore, session, dialect4) {
35880
- super();
35881
- __publicField(this, "config");
35882
- __publicField(this, "execute", (placeholderValues) => {
35883
- return this.prepare().execute(placeholderValues);
35884
- });
35885
- __publicField(this, "createIterator", () => {
35886
- const self2 = this;
35887
- return async function* (placeholderValues) {
35888
- yield* self2.prepare().iterator(placeholderValues);
35889
- };
35890
- });
35891
- __publicField(this, "iterator", this.createIterator());
35892
- this.session = session;
35893
- this.dialect = dialect4;
35894
- this.config = { table: table4, values, ignore };
35895
- }
35896
- /**
35897
- * Adds an `on duplicate key update` clause to the query.
35898
- *
35899
- * Calling this method will update the row if any unique index conflicts. MySQL will automatically determine the conflict target based on the primary key and unique indexes.
35900
- *
35901
- * See docs: {@link https://orm.drizzle.team/docs/insert#on-duplicate-key-update}
35902
- *
35903
- * @param config The `set` clause
35904
- *
35905
- * @example
35906
- * ```ts
35907
- * await db.insert(cars)
35908
- * .values({ id: 1, brand: 'BMW'})
35909
- * .onDuplicateKeyUpdate({ set: { brand: 'Porsche' }});
35910
- * ```
35911
- *
35912
- * While MySQL does not directly support doing nothing on conflict, you can perform a no-op by setting any column's value to itself and achieve the same effect:
35913
- *
35914
- * ```ts
35915
- * import { sql } from 'drizzle-orm';
35916
- *
35917
- * await db.insert(cars)
35918
- * .values({ id: 1, brand: 'BMW' })
35919
- * .onDuplicateKeyUpdate({ set: { id: sql`id` } });
35920
- * ```
35921
- */
35922
- onDuplicateKeyUpdate(config) {
35923
- const setSql = this.dialect.buildUpdateSet(this.config.table, mapUpdateSet(this.config.table, config.set));
35924
- this.config.onConflict = sql`update ${setSql}`;
35925
- return this;
35926
- }
35927
- $returningId() {
35928
- const returning = [];
35929
- for (const [key, value] of Object.entries(this.config.table[Table2.Symbol.Columns])) {
35930
- if (value.primary) {
35931
- returning.push({ field: value, path: [key] });
35932
- }
35933
- }
35934
- this.config.returning = returning;
35935
- return this;
35936
- }
35937
- /** @internal */
35938
- getSQL() {
35939
- return this.dialect.buildInsertQuery(this.config).sql;
35940
- }
35941
- toSQL() {
35942
- const { typings: _typings, ...rest } = this.dialect.sqlToQuery(this.getSQL());
35943
- return rest;
35944
- }
35945
- prepare() {
35946
- const { sql: sql2, generatedIds } = this.dialect.buildInsertQuery(this.config);
35947
- return this.session.prepareQuery(
35948
- this.dialect.sqlToQuery(sql2),
35949
- void 0,
35950
- void 0,
35951
- generatedIds,
35952
- this.config.returning
35953
- );
35954
- }
35955
- $dynamic() {
35956
- return this;
35957
- }
35958
- };
35959
- __publicField(MySqlInsertBase, _a300, "MySqlInsert");
35960
- }
35961
- });
35962
-
35963
35962
  // ../drizzle-orm/dist/mysql-core/columns/all.js
35964
35963
  function getMySqlColumnBuilders() {
35965
35964
  return {
@@ -36040,7 +36039,7 @@ function mysqlTableWithSchema(name2, columns, extraConfig, schema4, baseName = n
36040
36039
  }
36041
36040
  return table4;
36042
36041
  }
36043
- var InlineForeignKeys3, _a301, _b223, _c9, _d4, _e4, MySqlTable, mysqlTable;
36042
+ var InlineForeignKeys3, _a299, _b222, _c9, _d4, _e4, MySqlTable, mysqlTable;
36044
36043
  var init_table4 = __esm({
36045
36044
  "../drizzle-orm/dist/mysql-core/table.js"() {
36046
36045
  "use strict";
@@ -36048,15 +36047,15 @@ var init_table4 = __esm({
36048
36047
  init_table();
36049
36048
  init_all3();
36050
36049
  InlineForeignKeys3 = Symbol.for("drizzle:MySqlInlineForeignKeys");
36051
- MySqlTable = class extends (_e4 = Table2, _d4 = entityKind, _c9 = Table2.Symbol.Columns, _b223 = InlineForeignKeys3, _a301 = Table2.Symbol.ExtraConfigBuilder, _e4) {
36050
+ MySqlTable = class extends (_e4 = Table2, _d4 = entityKind, _c9 = Table2.Symbol.Columns, _b222 = InlineForeignKeys3, _a299 = Table2.Symbol.ExtraConfigBuilder, _e4) {
36052
36051
  constructor() {
36053
36052
  super(...arguments);
36054
36053
  /** @internal */
36055
36054
  __publicField(this, _c9);
36056
36055
  /** @internal */
36057
- __publicField(this, _b223, []);
36056
+ __publicField(this, _b222, []);
36058
36057
  /** @internal */
36059
- __publicField(this, _a301);
36058
+ __publicField(this, _a299);
36060
36059
  }
36061
36060
  };
36062
36061
  __publicField(MySqlTable, _d4, "MySqlTable");
@@ -36071,20 +36070,20 @@ var init_table4 = __esm({
36071
36070
  });
36072
36071
 
36073
36072
  // ../drizzle-orm/dist/mysql-core/view-base.js
36074
- var _a302, _b224, MySqlViewBase;
36073
+ var _a300, _b223, MySqlViewBase;
36075
36074
  var init_view_base3 = __esm({
36076
36075
  "../drizzle-orm/dist/mysql-core/view-base.js"() {
36077
36076
  "use strict";
36078
36077
  init_entity();
36079
36078
  init_sql();
36080
- MySqlViewBase = class extends (_b224 = View3, _a302 = entityKind, _b224) {
36079
+ MySqlViewBase = class extends (_b223 = View3, _a300 = entityKind, _b223) {
36081
36080
  };
36082
- __publicField(MySqlViewBase, _a302, "MySqlViewBase");
36081
+ __publicField(MySqlViewBase, _a300, "MySqlViewBase");
36083
36082
  }
36084
36083
  });
36085
36084
 
36086
36085
  // ../drizzle-orm/dist/mysql-core/dialect.js
36087
- var _a303, MySqlDialect;
36086
+ var _a301, MySqlDialect;
36088
36087
  var init_dialect3 = __esm({
36089
36088
  "../drizzle-orm/dist/mysql-core/dialect.js"() {
36090
36089
  "use strict";
@@ -36103,7 +36102,7 @@ var init_dialect3 = __esm({
36103
36102
  init_common4();
36104
36103
  init_table4();
36105
36104
  init_view_base3();
36106
- _a303 = entityKind;
36105
+ _a301 = entityKind;
36107
36106
  MySqlDialect = class {
36108
36107
  constructor(config) {
36109
36108
  /** @internal */
@@ -36386,7 +36385,7 @@ var init_dialect3 = __esm({
36386
36385
  const offsetSql = offset ? sql` offset ${offset}` : void 0;
36387
36386
  return sql`${leftChunk}${operatorChunk}${rightChunk}${orderBySql}${limitSql}${offsetSql}`;
36388
36387
  }
36389
- buildInsertQuery({ table: table4, values, ignore, onConflict }) {
36388
+ buildInsertQuery({ table: table4, values: valuesOrSelect, ignore, onConflict, select }) {
36390
36389
  const valuesSqlList = [];
36391
36390
  const columns = table4[Table2.Symbol.Columns];
36392
36391
  const colEntries = Object.entries(columns).filter(
@@ -36394,42 +36393,53 @@ var init_dialect3 = __esm({
36394
36393
  );
36395
36394
  const insertOrder = colEntries.map(([, column4]) => sql.identifier(this.casing.getColumnCasing(column4)));
36396
36395
  const generatedIdsResponse = [];
36397
- for (const [valueIndex, value] of values.entries()) {
36398
- const generatedIds = {};
36399
- const valueList = [];
36400
- for (const [fieldName, col] of colEntries) {
36401
- const colValue = value[fieldName];
36402
- if (colValue === void 0 || is(colValue, Param) && colValue.value === void 0) {
36403
- if (col.defaultFn !== void 0) {
36404
- const defaultFnResult = col.defaultFn();
36405
- generatedIds[fieldName] = defaultFnResult;
36406
- const defaultValue = is(defaultFnResult, SQL) ? defaultFnResult : sql.param(defaultFnResult, col);
36407
- valueList.push(defaultValue);
36408
- } else if (!col.default && col.onUpdateFn !== void 0) {
36409
- const onUpdateFnResult = col.onUpdateFn();
36410
- const newValue = is(onUpdateFnResult, SQL) ? onUpdateFnResult : sql.param(onUpdateFnResult, col);
36411
- valueList.push(newValue);
36396
+ if (select) {
36397
+ const select2 = valuesOrSelect;
36398
+ if (is(select2, SQL)) {
36399
+ valuesSqlList.push(select2);
36400
+ } else {
36401
+ valuesSqlList.push(select2.getSQL());
36402
+ }
36403
+ } else {
36404
+ const values = valuesOrSelect;
36405
+ valuesSqlList.push(sql.raw("values "));
36406
+ for (const [valueIndex, value] of values.entries()) {
36407
+ const generatedIds = {};
36408
+ const valueList = [];
36409
+ for (const [fieldName, col] of colEntries) {
36410
+ const colValue = value[fieldName];
36411
+ if (colValue === void 0 || is(colValue, Param) && colValue.value === void 0) {
36412
+ if (col.defaultFn !== void 0) {
36413
+ const defaultFnResult = col.defaultFn();
36414
+ generatedIds[fieldName] = defaultFnResult;
36415
+ const defaultValue = is(defaultFnResult, SQL) ? defaultFnResult : sql.param(defaultFnResult, col);
36416
+ valueList.push(defaultValue);
36417
+ } else if (!col.default && col.onUpdateFn !== void 0) {
36418
+ const onUpdateFnResult = col.onUpdateFn();
36419
+ const newValue = is(onUpdateFnResult, SQL) ? onUpdateFnResult : sql.param(onUpdateFnResult, col);
36420
+ valueList.push(newValue);
36421
+ } else {
36422
+ valueList.push(sql`default`);
36423
+ }
36412
36424
  } else {
36413
- valueList.push(sql`default`);
36414
- }
36415
- } else {
36416
- if (col.defaultFn && is(colValue, Param)) {
36417
- generatedIds[fieldName] = colValue.value;
36425
+ if (col.defaultFn && is(colValue, Param)) {
36426
+ generatedIds[fieldName] = colValue.value;
36427
+ }
36428
+ valueList.push(colValue);
36418
36429
  }
36419
- valueList.push(colValue);
36420
36430
  }
36421
- }
36422
- generatedIdsResponse.push(generatedIds);
36423
- valuesSqlList.push(valueList);
36424
- if (valueIndex < values.length - 1) {
36425
- valuesSqlList.push(sql`, `);
36431
+ generatedIdsResponse.push(generatedIds);
36432
+ valuesSqlList.push(valueList);
36433
+ if (valueIndex < values.length - 1) {
36434
+ valuesSqlList.push(sql`, `);
36435
+ }
36426
36436
  }
36427
36437
  }
36428
36438
  const valuesSql = sql.join(valuesSqlList);
36429
36439
  const ignoreSql = ignore ? sql` ignore` : void 0;
36430
36440
  const onConflictSql = onConflict ? sql` on duplicate key ${onConflict}` : void 0;
36431
36441
  return {
36432
- sql: sql`insert${ignoreSql} into ${table4} ${insertOrder} values ${valuesSql}${onConflictSql}`,
36442
+ sql: sql`insert${ignoreSql} into ${table4} ${insertOrder} ${valuesSql}${onConflictSql}`,
36433
36443
  generatedIds: generatedIdsResponse
36434
36444
  };
36435
36445
  }
@@ -36889,7 +36899,7 @@ var init_dialect3 = __esm({
36889
36899
  };
36890
36900
  }
36891
36901
  };
36892
- __publicField(MySqlDialect, _a303, "MySqlDialect");
36902
+ __publicField(MySqlDialect, _a301, "MySqlDialect");
36893
36903
  }
36894
36904
  });
36895
36905
 
@@ -36911,7 +36921,7 @@ function createSetOperator3(type, isAll) {
36911
36921
  return leftSelect.addSetOperators(setOperators);
36912
36922
  };
36913
36923
  }
36914
- var _a304, MySqlSelectBuilder, _a305, _b225, MySqlSelectQueryBuilderBase, _a306, _b226, MySqlSelectBase, getMySqlSetOperators, union3, unionAll3, intersect3, intersectAll2, except3, exceptAll2;
36924
+ var _a302, MySqlSelectBuilder, _a303, _b224, MySqlSelectQueryBuilderBase, _a304, _b225, MySqlSelectBase, getMySqlSetOperators, union3, unionAll3, intersect3, intersectAll2, except3, exceptAll2;
36915
36925
  var init_select4 = __esm({
36916
36926
  "../drizzle-orm/dist/mysql-core/query-builders/select.js"() {
36917
36927
  "use strict";
@@ -36926,7 +36936,7 @@ var init_select4 = __esm({
36926
36936
  init_utils2();
36927
36937
  init_view_common();
36928
36938
  init_view_base3();
36929
- _a304 = entityKind;
36939
+ _a302 = entityKind;
36930
36940
  MySqlSelectBuilder = class {
36931
36941
  constructor(config) {
36932
36942
  __publicField(this, "fields");
@@ -36971,8 +36981,8 @@ var init_select4 = __esm({
36971
36981
  );
36972
36982
  }
36973
36983
  };
36974
- __publicField(MySqlSelectBuilder, _a304, "MySqlSelectBuilder");
36975
- MySqlSelectQueryBuilderBase = class extends (_b225 = TypedQueryBuilder, _a305 = entityKind, _b225) {
36984
+ __publicField(MySqlSelectBuilder, _a302, "MySqlSelectBuilder");
36985
+ MySqlSelectQueryBuilderBase = class extends (_b224 = TypedQueryBuilder, _a303 = entityKind, _b224) {
36976
36986
  constructor({ table: table4, fields, isPartialSelect, session, dialect: dialect4, withList, distinct }) {
36977
36987
  super();
36978
36988
  __publicField(this, "_");
@@ -37573,8 +37583,8 @@ var init_select4 = __esm({
37573
37583
  return this;
37574
37584
  }
37575
37585
  };
37576
- __publicField(MySqlSelectQueryBuilderBase, _a305, "MySqlSelectQueryBuilder");
37577
- MySqlSelectBase = class extends (_b226 = MySqlSelectQueryBuilderBase, _a306 = entityKind, _b226) {
37586
+ __publicField(MySqlSelectQueryBuilderBase, _a303, "MySqlSelectQueryBuilder");
37587
+ MySqlSelectBase = class extends (_b225 = MySqlSelectQueryBuilderBase, _a304 = entityKind, _b225) {
37578
37588
  constructor() {
37579
37589
  super(...arguments);
37580
37590
  __publicField(this, "execute", (placeholderValues) => {
@@ -37598,7 +37608,7 @@ var init_select4 = __esm({
37598
37608
  return query;
37599
37609
  }
37600
37610
  };
37601
- __publicField(MySqlSelectBase, _a306, "MySqlSelect");
37611
+ __publicField(MySqlSelectBase, _a304, "MySqlSelect");
37602
37612
  applyMixins(MySqlSelectBase, [QueryPromise]);
37603
37613
  getMySqlSetOperators = () => ({
37604
37614
  union: union3,
@@ -37618,7 +37628,7 @@ var init_select4 = __esm({
37618
37628
  });
37619
37629
 
37620
37630
  // ../drizzle-orm/dist/mysql-core/query-builders/query-builder.js
37621
- var _a307, QueryBuilder3;
37631
+ var _a305, QueryBuilder3;
37622
37632
  var init_query_builder4 = __esm({
37623
37633
  "../drizzle-orm/dist/mysql-core/query-builders/query-builder.js"() {
37624
37634
  "use strict";
@@ -37627,7 +37637,7 @@ var init_query_builder4 = __esm({
37627
37637
  init_selection_proxy();
37628
37638
  init_subquery();
37629
37639
  init_select4();
37630
- _a307 = entityKind;
37640
+ _a305 = entityKind;
37631
37641
  QueryBuilder3 = class {
37632
37642
  constructor(dialect4) {
37633
37643
  __publicField(this, "dialect");
@@ -37689,7 +37699,142 @@ var init_query_builder4 = __esm({
37689
37699
  return this.dialect;
37690
37700
  }
37691
37701
  };
37692
- __publicField(QueryBuilder3, _a307, "MySqlQueryBuilder");
37702
+ __publicField(QueryBuilder3, _a305, "MySqlQueryBuilder");
37703
+ }
37704
+ });
37705
+
37706
+ // ../drizzle-orm/dist/mysql-core/query-builders/insert.js
37707
+ var _a306, MySqlInsertBuilder, _a307, _b226, MySqlInsertBase;
37708
+ var init_insert3 = __esm({
37709
+ "../drizzle-orm/dist/mysql-core/query-builders/insert.js"() {
37710
+ "use strict";
37711
+ init_entity();
37712
+ init_query_promise();
37713
+ init_sql();
37714
+ init_table();
37715
+ init_utils2();
37716
+ init_query_builder4();
37717
+ _a306 = entityKind;
37718
+ MySqlInsertBuilder = class {
37719
+ constructor(table4, session, dialect4) {
37720
+ __publicField(this, "shouldIgnore", false);
37721
+ this.table = table4;
37722
+ this.session = session;
37723
+ this.dialect = dialect4;
37724
+ }
37725
+ ignore() {
37726
+ this.shouldIgnore = true;
37727
+ return this;
37728
+ }
37729
+ values(values) {
37730
+ values = Array.isArray(values) ? values : [values];
37731
+ if (values.length === 0) {
37732
+ throw new Error("values() must be called with at least one value");
37733
+ }
37734
+ const mappedValues = values.map((entry) => {
37735
+ const result = {};
37736
+ const cols = this.table[Table2.Symbol.Columns];
37737
+ for (const colKey of Object.keys(entry)) {
37738
+ const colValue = entry[colKey];
37739
+ result[colKey] = is(colValue, SQL) ? colValue : new Param(colValue, cols[colKey]);
37740
+ }
37741
+ return result;
37742
+ });
37743
+ return new MySqlInsertBase(this.table, mappedValues, this.shouldIgnore, this.session, this.dialect);
37744
+ }
37745
+ select(selectQuery) {
37746
+ const select = typeof selectQuery === "function" ? selectQuery(new QueryBuilder3()) : selectQuery;
37747
+ if (!is(select, SQL) && !haveSameKeys(this.table[Columns], select._.selectedFields)) {
37748
+ throw new Error(
37749
+ "Insert select error: selected fields are not the same or are in a different order compared to the table definition"
37750
+ );
37751
+ }
37752
+ return new MySqlInsertBase(this.table, select, this.shouldIgnore, this.session, this.dialect, true);
37753
+ }
37754
+ };
37755
+ __publicField(MySqlInsertBuilder, _a306, "MySqlInsertBuilder");
37756
+ MySqlInsertBase = class extends (_b226 = QueryPromise, _a307 = entityKind, _b226) {
37757
+ constructor(table4, values, ignore, session, dialect4, select) {
37758
+ super();
37759
+ __publicField(this, "config");
37760
+ __publicField(this, "execute", (placeholderValues) => {
37761
+ return this.prepare().execute(placeholderValues);
37762
+ });
37763
+ __publicField(this, "createIterator", () => {
37764
+ const self2 = this;
37765
+ return async function* (placeholderValues) {
37766
+ yield* self2.prepare().iterator(placeholderValues);
37767
+ };
37768
+ });
37769
+ __publicField(this, "iterator", this.createIterator());
37770
+ this.session = session;
37771
+ this.dialect = dialect4;
37772
+ this.config = { table: table4, values, select, ignore };
37773
+ }
37774
+ /**
37775
+ * Adds an `on duplicate key update` clause to the query.
37776
+ *
37777
+ * Calling this method will update the row if any unique index conflicts. MySQL will automatically determine the conflict target based on the primary key and unique indexes.
37778
+ *
37779
+ * See docs: {@link https://orm.drizzle.team/docs/insert#on-duplicate-key-update}
37780
+ *
37781
+ * @param config The `set` clause
37782
+ *
37783
+ * @example
37784
+ * ```ts
37785
+ * await db.insert(cars)
37786
+ * .values({ id: 1, brand: 'BMW'})
37787
+ * .onDuplicateKeyUpdate({ set: { brand: 'Porsche' }});
37788
+ * ```
37789
+ *
37790
+ * While MySQL does not directly support doing nothing on conflict, you can perform a no-op by setting any column's value to itself and achieve the same effect:
37791
+ *
37792
+ * ```ts
37793
+ * import { sql } from 'drizzle-orm';
37794
+ *
37795
+ * await db.insert(cars)
37796
+ * .values({ id: 1, brand: 'BMW' })
37797
+ * .onDuplicateKeyUpdate({ set: { id: sql`id` } });
37798
+ * ```
37799
+ */
37800
+ onDuplicateKeyUpdate(config) {
37801
+ const setSql = this.dialect.buildUpdateSet(this.config.table, mapUpdateSet(this.config.table, config.set));
37802
+ this.config.onConflict = sql`update ${setSql}`;
37803
+ return this;
37804
+ }
37805
+ $returningId() {
37806
+ const returning = [];
37807
+ for (const [key, value] of Object.entries(this.config.table[Table2.Symbol.Columns])) {
37808
+ if (value.primary) {
37809
+ returning.push({ field: value, path: [key] });
37810
+ }
37811
+ }
37812
+ this.config.returning = returning;
37813
+ return this;
37814
+ }
37815
+ /** @internal */
37816
+ getSQL() {
37817
+ return this.dialect.buildInsertQuery(this.config).sql;
37818
+ }
37819
+ toSQL() {
37820
+ const { typings: _typings, ...rest } = this.dialect.sqlToQuery(this.getSQL());
37821
+ return rest;
37822
+ }
37823
+ prepare() {
37824
+ const { sql: sql2, generatedIds } = this.dialect.buildInsertQuery(this.config);
37825
+ return this.session.prepareQuery(
37826
+ this.dialect.sqlToQuery(sql2),
37827
+ void 0,
37828
+ void 0,
37829
+ generatedIds,
37830
+ this.config.returning
37831
+ );
37832
+ }
37833
+ $dynamic() {
37834
+ return this;
37835
+ }
37836
+ };
37837
+ __publicField(MySqlInsertBase, _a307, "MySqlInsert");
37693
37838
  }
37694
37839
  });
37695
37840