kysely 0.13.0 → 0.14.0

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 (87) hide show
  1. package/dist/cjs/{introspection → dialect}/database-introspector.d.ts +0 -0
  2. package/dist/cjs/{introspection → dialect}/database-introspector.js +0 -0
  3. package/dist/cjs/dialect/dialect.d.ts +1 -1
  4. package/dist/cjs/dialect/mysql/mysql-dialect.d.ts +1 -1
  5. package/dist/cjs/dialect/mysql/mysql-introspector.d.ts +1 -1
  6. package/dist/cjs/dialect/postgres/postgres-dialect.d.ts +1 -1
  7. package/dist/cjs/dialect/postgres/postgres-introspector.d.ts +1 -1
  8. package/dist/cjs/dialect/sqlite/sqlite-dialect.d.ts +1 -1
  9. package/dist/cjs/dialect/sqlite/sqlite-introspector.d.ts +1 -1
  10. package/dist/cjs/index.d.ts +2 -2
  11. package/dist/cjs/index.js +2 -2
  12. package/dist/cjs/kysely.d.ts +1 -1
  13. package/dist/cjs/operation-node/check-constraint-node.d.ts +1 -1
  14. package/dist/cjs/operation-node/check-constraint-node.js +2 -3
  15. package/dist/cjs/operation-node/column-definition-node.d.ts +2 -2
  16. package/dist/cjs/operation-node/data-type-node.d.ts +1 -1
  17. package/dist/cjs/operation-node/generated-node.d.ts +20 -0
  18. package/dist/cjs/operation-node/generated-node.js +31 -0
  19. package/dist/cjs/operation-node/on-conflict-node.d.ts +13 -2
  20. package/dist/cjs/operation-node/on-conflict-node.js +39 -1
  21. package/dist/cjs/operation-node/operation-node-transformer.d.ts +2 -2
  22. package/dist/cjs/operation-node/operation-node-transformer.js +11 -5
  23. package/dist/cjs/operation-node/operation-node-visitor.d.ts +2 -2
  24. package/dist/cjs/operation-node/operation-node-visitor.js +1 -1
  25. package/dist/cjs/operation-node/operation-node.d.ts +1 -1
  26. package/dist/cjs/query-builder/insert-query-builder.d.ts +76 -75
  27. package/dist/cjs/query-builder/insert-query-builder.js +150 -15
  28. package/dist/cjs/query-builder/on-conflict-builder.d.ts +684 -0
  29. package/dist/cjs/query-builder/on-conflict-builder.js +323 -0
  30. package/dist/cjs/query-compiler/default-query-compiler.d.ts +2 -2
  31. package/dist/cjs/query-compiler/default-query-compiler.js +33 -7
  32. package/dist/cjs/schema/alter-table-builder.d.ts +29 -9
  33. package/dist/cjs/schema/alter-table-builder.js +33 -9
  34. package/dist/cjs/schema/column-definition-builder.d.ts +28 -8
  35. package/dist/cjs/schema/column-definition-builder.js +17 -7
  36. package/dist/cjs/schema/create-index-builder.d.ts +3 -2
  37. package/dist/cjs/schema/create-index-builder.js +2 -2
  38. package/dist/cjs/schema/create-table-builder.d.ts +3 -2
  39. package/dist/cjs/schema/create-table-builder.js +2 -2
  40. package/dist/esm/{introspection → dialect}/database-introspector.d.ts +0 -0
  41. package/dist/esm/{introspection → dialect}/database-introspector.js +0 -0
  42. package/dist/esm/dialect/dialect.d.ts +1 -1
  43. package/dist/esm/dialect/mysql/mysql-dialect.d.ts +1 -1
  44. package/dist/esm/dialect/mysql/mysql-introspector.d.ts +1 -1
  45. package/dist/esm/dialect/postgres/postgres-dialect.d.ts +1 -1
  46. package/dist/esm/dialect/postgres/postgres-introspector.d.ts +1 -1
  47. package/dist/esm/dialect/sqlite/sqlite-dialect.d.ts +1 -1
  48. package/dist/esm/dialect/sqlite/sqlite-introspector.d.ts +1 -1
  49. package/dist/esm/index.d.ts +2 -2
  50. package/dist/esm/index.js +2 -2
  51. package/dist/esm/kysely.d.ts +1 -1
  52. package/dist/esm/operation-node/check-constraint-node.d.ts +1 -1
  53. package/dist/esm/operation-node/check-constraint-node.js +2 -3
  54. package/dist/esm/operation-node/column-definition-node.d.ts +2 -2
  55. package/dist/esm/operation-node/data-type-node.d.ts +1 -1
  56. package/dist/esm/operation-node/generated-node.d.ts +20 -0
  57. package/dist/esm/operation-node/generated-node.js +28 -0
  58. package/dist/esm/operation-node/on-conflict-node.d.ts +13 -2
  59. package/dist/esm/operation-node/on-conflict-node.js +39 -1
  60. package/dist/esm/operation-node/operation-node-transformer.d.ts +2 -2
  61. package/dist/esm/operation-node/operation-node-transformer.js +11 -5
  62. package/dist/esm/operation-node/operation-node-visitor.d.ts +2 -2
  63. package/dist/esm/operation-node/operation-node-visitor.js +1 -1
  64. package/dist/esm/operation-node/operation-node.d.ts +1 -1
  65. package/dist/esm/query-builder/insert-query-builder.d.ts +76 -75
  66. package/dist/esm/query-builder/insert-query-builder.js +150 -15
  67. package/dist/esm/query-builder/on-conflict-builder.d.ts +684 -0
  68. package/dist/esm/query-builder/on-conflict-builder.js +317 -0
  69. package/dist/esm/query-compiler/default-query-compiler.d.ts +2 -2
  70. package/dist/esm/query-compiler/default-query-compiler.js +33 -7
  71. package/dist/esm/schema/alter-table-builder.d.ts +29 -9
  72. package/dist/esm/schema/alter-table-builder.js +33 -9
  73. package/dist/esm/schema/column-definition-builder.d.ts +28 -8
  74. package/dist/esm/schema/column-definition-builder.js +17 -7
  75. package/dist/esm/schema/create-index-builder.d.ts +3 -2
  76. package/dist/esm/schema/create-index-builder.js +2 -2
  77. package/dist/esm/schema/create-table-builder.d.ts +3 -2
  78. package/dist/esm/schema/create-table-builder.js +2 -2
  79. package/package.json +1 -1
  80. package/dist/cjs/operation-node/generated-always-as-node.d.ts +0 -16
  81. package/dist/cjs/operation-node/generated-always-as-node.js +0 -25
  82. package/dist/cjs/parser/on-conflict-parser.d.ts +0 -10
  83. package/dist/cjs/parser/on-conflict-parser.js +0 -35
  84. package/dist/esm/operation-node/generated-always-as-node.d.ts +0 -16
  85. package/dist/esm/operation-node/generated-always-as-node.js +0 -22
  86. package/dist/esm/parser/on-conflict-parser.d.ts +0 -10
  87. package/dist/esm/parser/on-conflict-parser.js +0 -30
@@ -3,18 +3,18 @@ import { CompiledQuery } from '../query-compiler/compiled-query.js';
3
3
  import { SelectExpression } from '../parser/select-parser.js';
4
4
  import { InsertObject } from '../parser/insert-values-parser.js';
5
5
  import { InsertQueryNode } from '../operation-node/insert-query-node.js';
6
- import { AnyColumn, SingleResultType } from '../util/type-utils.js';
6
+ import { SingleResultType } from '../util/type-utils.js';
7
7
  import { MutationObject } from '../parser/update-set-parser.js';
8
8
  import { Compilable } from '../util/compilable.js';
9
9
  import { QueryExecutor } from '../query-executor/query-executor.js';
10
10
  import { QueryId } from '../util/query-id.js';
11
- import { OnConflictConstraintTarget } from '../parser/on-conflict-parser.js';
12
11
  import { ParseContext } from '../parser/parse-context.js';
13
12
  import { KyselyPlugin } from '../plugin/kysely-plugin.js';
14
13
  import { ReturningRow } from '../parser/returning-parser.js';
15
14
  import { NoResultErrorConstructor } from './no-result-error.js';
16
15
  import { ComplexExpression } from '../parser/complex-expression-parser.js';
17
16
  import { ReturningInterface } from './returning-interface.js';
17
+ import { OnConflictBuilder, OnConflictDoNothingBuilder, OnConflictUpdateBuilder } from './on-conflict-builder.js';
18
18
  export declare class InsertQueryBuilder<DB, TB extends keyof DB, O> implements ReturningInterface<DB, TB, O>, OperationNodeSource, Compilable {
19
19
  #private;
20
20
  constructor(props: InsertQueryBuilderProps);
@@ -196,21 +196,32 @@ export declare class InsertQueryBuilder<DB, TB extends keyof DB, O> implements R
196
196
  */
197
197
  expression(expression: ComplexExpression<DB, TB>): InsertQueryBuilder<DB, TB, O>;
198
198
  /**
199
- * Ignores the insert if the column or constraint given as the first
200
- * argument conflicts with the current rows in the database. The
201
- * default behavior without this method call is to throw an error.
199
+ * Changes an `insert into` query to an `insert ignore into` query.
202
200
  *
203
- * For example if a table has a field `name` that has a unique constraint
204
- * and you try to insert a row with a `name` that already exists in the
205
- * database, calling `onConflictDoNothing('name')` will ignore the conflict
206
- * and do nothing. By default the query would throw.
201
+ * If you use the ignore modifier, ignorable errors that occur while executing the
202
+ * insert statement are ignored. For example, without ignore, a row that duplicates
203
+ * an existing unique index or primary key value in the table causes a duplicate-key
204
+ * error and the statement is aborted. With ignore, the row is discarded and no error
205
+ * occurs.
207
206
  *
208
- * Only some dialects like PostgreSQL and SQLite implement the `on conflict`
209
- * statement. On MySQL you should use the {@link ignore} method to achieve
210
- * similar results.
207
+ * This is only supported on some dialects like MySQL. On most dialects you should
208
+ * use the {@link onConflict} method.
211
209
  *
212
- * Also see the {@link onConflictUpdate} method if you want to perform an
213
- * update in case of a conflict (upsert).
210
+ * ### Examples
211
+ *
212
+ * ```ts
213
+ * await db.insertInto('person')
214
+ * .ignore()
215
+ * .values(values)
216
+ * .execute()
217
+ * ```
218
+ */
219
+ ignore(): InsertQueryBuilder<DB, TB, O>;
220
+ /**
221
+ * Adds an `on conflict` clause to the query.
222
+ *
223
+ * `on conflict` is only supported by some dialects like PostgreSQL and SQLite. On MySQL
224
+ * you can use {@link ignore} and {@link onDuplicateKeyUpdate} to achieve similar results.
214
225
  *
215
226
  * ### Examples
216
227
  *
@@ -222,7 +233,10 @@ export declare class InsertQueryBuilder<DB, TB extends keyof DB, O> implements R
222
233
  * name: 'Catto',
223
234
  * species: 'cat',
224
235
  * })
225
- * .onConflictDoNothing('name')
236
+ * .onConflict((oc) => oc
237
+ * .column('name')
238
+ * .doUpdateSet({ species: 'hamster' })
239
+ * )
226
240
  * .execute()
227
241
  * ```
228
242
  *
@@ -231,10 +245,11 @@ export declare class InsertQueryBuilder<DB, TB extends keyof DB, O> implements R
231
245
  * ```sql
232
246
  * insert into "pet" ("name", "species")
233
247
  * values ($1, $2)
234
- * on conflict ("name") do nothing
248
+ * on conflict ("name")
249
+ * do update set "species" = $3
235
250
  * ```
236
251
  *
237
- * You can provide the name of the constraint instead of a column name
252
+ * You can provide the name of the constraint instead of a column name:
238
253
  *
239
254
  * ```ts
240
255
  * await db
@@ -244,9 +259,11 @@ export declare class InsertQueryBuilder<DB, TB extends keyof DB, O> implements R
244
259
  * name: 'Catto',
245
260
  * species: 'cat',
246
261
  * })
247
- * .onConflictDoNothing({
248
- * constraint: 'pet_name_key'
249
- * })
262
+ * .onConflict((oc) => oc
263
+ * .constraint('pet_name_key')
264
+ * .doUpdateSet({ species: 'hamster' })
265
+ * )
266
+ * .execute()
250
267
  * .execute()
251
268
  * ```
252
269
  *
@@ -256,56 +273,37 @@ export declare class InsertQueryBuilder<DB, TB extends keyof DB, O> implements R
256
273
  * insert into "pet" ("name", "species")
257
274
  * values ($1, $2)
258
275
  * on conflict on constraint "pet_name_key"
259
- * do nothing
276
+ * do update set "species" = $3
260
277
  * ```
261
- */
262
- onConflictDoNothing(column: AnyColumn<DB, TB>): InsertQueryBuilder<DB, TB, O>;
263
- onConflictDoNothing(columns: ReadonlyArray<AnyColumn<DB, TB>>): InsertQueryBuilder<DB, TB, O>;
264
- onConflictDoNothing(constraint: OnConflictConstraintTarget): InsertQueryBuilder<DB, TB, O>;
265
- /**
266
- * Changes an `insert into` query to an `insert ignore into` query.
267
- *
268
- * If you use the ignore modifier, ignorable errors that occur while executing the
269
- * insert statement are ignored. For example, without ignore, a row that duplicates
270
- * an existing unique index or primary key value in the table causes a duplicate-key
271
- * error and the statement is aborted. With ignore, the row is discarded and no error
272
- * occurs.
273
278
  *
274
- * This is only supported on some dialects like MySQL. On most dialects you should
275
- * use the {@link onConflictDoNothing} method.
276
- *
277
- * ### Examples
279
+ * You can also specify an expression as the conflict target in case
280
+ * the unique index is an expression index:
278
281
  *
279
282
  * ```ts
280
- * await db.insertInto('person')
281
- * .ignore()
282
- * .values(values)
283
+ * await db
284
+ * .insertInto('pet')
285
+ * .values({
286
+ * id: db.generated,
287
+ * name: 'Catto',
288
+ * species: 'cat',
289
+ * })
290
+ * .onConflict((oc) => oc
291
+ * .expression(db.raw('lower(name)'))
292
+ * .doUpdateSet({ species: 'hamster' })
293
+ * )
283
294
  * .execute()
284
295
  * ```
285
- */
286
- ignore(): InsertQueryBuilder<DB, TB, O>;
287
- /**
288
- * Ignores an insert if the column or constraint given as the first
289
- * argument conflicts with the current rows in the database and
290
- * performs an update on the conflicting row instead. This method
291
- * can be used to implement an upsert operation.
292
- *
293
- * For example if a table has a field `name` that has a unique constraint
294
- * and you try to insert a row with a `name` that already exists in the
295
- * database, calling `onConfictUpdate('name', { species: 'hamster' })`
296
- * will set the conflicting row's `species` field to value `'hamster'`.
297
- * By default the query would throw.
298
- *
299
- * The second argument (updates) can be anything the {@link UpdateQueryBuilder.set | set}
300
- * method accepts.
301
296
  *
302
- * The `on conflict do update` statement is only implemented by some dialects
303
- * like PostgreSQL and SQLite. On MySQL you should use the {@link onDuplicateKeyUpdate}
304
- * method instead.
297
+ * The generated SQL (PostgreSQL):
305
298
  *
306
- * Also see the {@link onConflictDoNothing} method.
299
+ * ```sql
300
+ * insert into "pet" ("name", "species")
301
+ * values ($1, $2)
302
+ * on conflict (lower(name))
303
+ * do update set "species" = $3
304
+ * ```
307
305
  *
308
- * ### Examples
306
+ * You can add a filter for the update statement like this:
309
307
  *
310
308
  * ```ts
311
309
  * await db
@@ -315,7 +313,11 @@ export declare class InsertQueryBuilder<DB, TB extends keyof DB, O> implements R
315
313
  * name: 'Catto',
316
314
  * species: 'cat',
317
315
  * })
318
- * .onConflictUpdate('name', { species: 'hamster' })
316
+ * .onConflict((oc) => oc
317
+ * .column('name')
318
+ * .doUpdateSet({ species: 'hamster' })
319
+ * .where('excluded.name', '!=', 'Catto'')
320
+ * )
319
321
  * .execute()
320
322
  * ```
321
323
  *
@@ -324,10 +326,12 @@ export declare class InsertQueryBuilder<DB, TB extends keyof DB, O> implements R
324
326
  * ```sql
325
327
  * insert into "pet" ("name", "species")
326
328
  * values ($1, $2)
327
- * on conflict ("name") do update set "species" = $3
329
+ * on conflict ("name")
330
+ * do update set "species" = $3
331
+ * where "excluded"."name" != $4
328
332
  * ```
329
333
  *
330
- * You can provied the name of the constraint instead of a column name
334
+ * You can create an `on conflict do nothing` clauses like this:
331
335
  *
332
336
  * ```ts
333
337
  * await db
@@ -337,9 +341,9 @@ export declare class InsertQueryBuilder<DB, TB extends keyof DB, O> implements R
337
341
  * name: 'Catto',
338
342
  * species: 'cat',
339
343
  * })
340
- * .onConflictUpdate(
341
- * { constraint: 'pet_name_key' },
342
- * { species: 'hamster' }
344
+ * .onConflict((oc) => oc
345
+ * .column('name')
346
+ * .doNothing()
343
347
  * )
344
348
  * .execute()
345
349
  * ```
@@ -349,13 +353,10 @@ export declare class InsertQueryBuilder<DB, TB extends keyof DB, O> implements R
349
353
  * ```sql
350
354
  * insert into "pet" ("name", "species")
351
355
  * values ($1, $2)
352
- * on conflict on constraint "pet_name_key"
353
- * do update set "species" = $3
356
+ * on conflict ("name") do nothing
354
357
  * ```
355
358
  */
356
- onConflictUpdate(column: AnyColumn<DB, TB>, updates: MutationObject<DB, TB>): InsertQueryBuilder<DB, TB, O>;
357
- onConflictUpdate(columns: ReadonlyArray<AnyColumn<DB, TB>>, updates: MutationObject<DB, TB>): InsertQueryBuilder<DB, TB, O>;
358
- onConflictUpdate(constraint: OnConflictConstraintTarget, updates: MutationObject<DB, TB>): InsertQueryBuilder<DB, TB, O>;
359
+ onConflict(callback: (builder: OnConflictBuilder<DB, TB>) => OnConflictDoNothingBuilder<DB, TB> | OnConflictUpdateBuilder<DB, TB>): InsertQueryBuilder<DB, TB, O>;
359
360
  /**
360
361
  * Adds `on duplicate key update` to the query.
361
362
  *
@@ -363,7 +364,7 @@ export declare class InsertQueryBuilder<DB, TB extends keyof DB, O> implements R
363
364
  * a duplicate value in a unique index or primary key, an update of the old row occurs.
364
365
  *
365
366
  * This is only implemented by some dialects like MySQL. On most dialects you should
366
- * use {@link onConflictUpdate} instead.
367
+ * use {@link onConflict} instead.
367
368
  *
368
369
  * ### Examples
369
370
  *
@@ -456,9 +457,9 @@ export declare class InsertQueryBuilder<DB, TB extends keyof DB, O> implements R
456
457
  * .selectAll()
457
458
  * .call((qb) => {
458
459
  * if (something) {
459
- * return qb.onConflictDoNothing('something')
460
+ * return qb.onConflict((oc) => oc.column('something').doNothing())
460
461
  * } else {
461
- * return qb.onConflictDoNothing('something_else')
462
+ * return qb.onConflict((oc) => oc.column('something_else').doNothing())
462
463
  * }
463
464
  * })
464
465
  * .execute()
@@ -7,13 +7,14 @@ const insert_query_node_js_1 = require("../operation-node/insert-query-node.js")
7
7
  const query_node_js_1 = require("../operation-node/query-node.js");
8
8
  const update_set_parser_js_1 = require("../parser/update-set-parser.js");
9
9
  const prevent_await_js_1 = require("../util/prevent-await.js");
10
- const on_conflict_parser_js_1 = require("../parser/on-conflict-parser.js");
11
10
  const object_utils_js_1 = require("../util/object-utils.js");
12
11
  const on_duplicate_key_node_js_1 = require("../operation-node/on-duplicate-key-node.js");
13
12
  const insert_result_js_1 = require("./insert-result.js");
14
13
  const no_result_error_js_1 = require("./no-result-error.js");
15
14
  const complex_expression_parser_js_1 = require("../parser/complex-expression-parser.js");
16
15
  const column_node_js_1 = require("../operation-node/column-node.js");
16
+ const index_js_1 = require("../index.js");
17
+ const on_conflict_builder_js_1 = require("./on-conflict-builder.js");
17
18
  class InsertQueryBuilder {
18
19
  #props;
19
20
  constructor(props) {
@@ -85,14 +86,6 @@ class InsertQueryBuilder {
85
86
  }),
86
87
  });
87
88
  }
88
- onConflictDoNothing(target) {
89
- return new InsertQueryBuilder({
90
- ...this.#props,
91
- queryNode: insert_query_node_js_1.InsertQueryNode.cloneWith(this.#props.queryNode, {
92
- onConflict: (0, on_conflict_parser_js_1.parseOnConflictDoNothing)(target),
93
- }),
94
- });
95
- }
96
89
  /**
97
90
  * Changes an `insert into` query to an `insert ignore into` query.
98
91
  *
@@ -103,7 +96,7 @@ class InsertQueryBuilder {
103
96
  * occurs.
104
97
  *
105
98
  * This is only supported on some dialects like MySQL. On most dialects you should
106
- * use the {@link onConflictDoNothing} method.
99
+ * use the {@link onConflict} method.
107
100
  *
108
101
  * ### Examples
109
102
  *
@@ -122,11 +115,153 @@ class InsertQueryBuilder {
122
115
  }),
123
116
  });
124
117
  }
125
- onConflictUpdate(target, updates) {
118
+ /**
119
+ * Adds an `on conflict` clause to the query.
120
+ *
121
+ * `on conflict` is only supported by some dialects like PostgreSQL and SQLite. On MySQL
122
+ * you can use {@link ignore} and {@link onDuplicateKeyUpdate} to achieve similar results.
123
+ *
124
+ * ### Examples
125
+ *
126
+ * ```ts
127
+ * await db
128
+ * .insertInto('pet')
129
+ * .values({
130
+ * id: db.generated,
131
+ * name: 'Catto',
132
+ * species: 'cat',
133
+ * })
134
+ * .onConflict((oc) => oc
135
+ * .column('name')
136
+ * .doUpdateSet({ species: 'hamster' })
137
+ * )
138
+ * .execute()
139
+ * ```
140
+ *
141
+ * The generated SQL (PostgreSQL):
142
+ *
143
+ * ```sql
144
+ * insert into "pet" ("name", "species")
145
+ * values ($1, $2)
146
+ * on conflict ("name")
147
+ * do update set "species" = $3
148
+ * ```
149
+ *
150
+ * You can provide the name of the constraint instead of a column name:
151
+ *
152
+ * ```ts
153
+ * await db
154
+ * .insertInto('pet')
155
+ * .values({
156
+ * id: db.generated,
157
+ * name: 'Catto',
158
+ * species: 'cat',
159
+ * })
160
+ * .onConflict((oc) => oc
161
+ * .constraint('pet_name_key')
162
+ * .doUpdateSet({ species: 'hamster' })
163
+ * )
164
+ * .execute()
165
+ * .execute()
166
+ * ```
167
+ *
168
+ * The generated SQL (PostgreSQL):
169
+ *
170
+ * ```sql
171
+ * insert into "pet" ("name", "species")
172
+ * values ($1, $2)
173
+ * on conflict on constraint "pet_name_key"
174
+ * do update set "species" = $3
175
+ * ```
176
+ *
177
+ * You can also specify an expression as the conflict target in case
178
+ * the unique index is an expression index:
179
+ *
180
+ * ```ts
181
+ * await db
182
+ * .insertInto('pet')
183
+ * .values({
184
+ * id: db.generated,
185
+ * name: 'Catto',
186
+ * species: 'cat',
187
+ * })
188
+ * .onConflict((oc) => oc
189
+ * .expression(db.raw('lower(name)'))
190
+ * .doUpdateSet({ species: 'hamster' })
191
+ * )
192
+ * .execute()
193
+ * ```
194
+ *
195
+ * The generated SQL (PostgreSQL):
196
+ *
197
+ * ```sql
198
+ * insert into "pet" ("name", "species")
199
+ * values ($1, $2)
200
+ * on conflict (lower(name))
201
+ * do update set "species" = $3
202
+ * ```
203
+ *
204
+ * You can add a filter for the update statement like this:
205
+ *
206
+ * ```ts
207
+ * await db
208
+ * .insertInto('pet')
209
+ * .values({
210
+ * id: db.generated,
211
+ * name: 'Catto',
212
+ * species: 'cat',
213
+ * })
214
+ * .onConflict((oc) => oc
215
+ * .column('name')
216
+ * .doUpdateSet({ species: 'hamster' })
217
+ * .where('excluded.name', '!=', 'Catto'')
218
+ * )
219
+ * .execute()
220
+ * ```
221
+ *
222
+ * The generated SQL (PostgreSQL):
223
+ *
224
+ * ```sql
225
+ * insert into "pet" ("name", "species")
226
+ * values ($1, $2)
227
+ * on conflict ("name")
228
+ * do update set "species" = $3
229
+ * where "excluded"."name" != $4
230
+ * ```
231
+ *
232
+ * You can create an `on conflict do nothing` clauses like this:
233
+ *
234
+ * ```ts
235
+ * await db
236
+ * .insertInto('pet')
237
+ * .values({
238
+ * id: db.generated,
239
+ * name: 'Catto',
240
+ * species: 'cat',
241
+ * })
242
+ * .onConflict((oc) => oc
243
+ * .column('name')
244
+ * .doNothing()
245
+ * )
246
+ * .execute()
247
+ * ```
248
+ *
249
+ * The generated SQL (PostgreSQL):
250
+ *
251
+ * ```sql
252
+ * insert into "pet" ("name", "species")
253
+ * values ($1, $2)
254
+ * on conflict ("name") do nothing
255
+ * ```
256
+ */
257
+ onConflict(callback) {
126
258
  return new InsertQueryBuilder({
127
259
  ...this.#props,
128
260
  queryNode: insert_query_node_js_1.InsertQueryNode.cloneWith(this.#props.queryNode, {
129
- onConflict: (0, on_conflict_parser_js_1.parseOnConflictUpdate)(this.#props.parseContext, target, updates),
261
+ onConflict: callback(new on_conflict_builder_js_1.OnConflictBuilder({
262
+ onConflictNode: index_js_1.OnConflictNode.create(),
263
+ parseContext: this.#props.parseContext,
264
+ })).toOperationNode(),
130
265
  }),
131
266
  });
132
267
  }
@@ -137,7 +272,7 @@ class InsertQueryBuilder {
137
272
  * a duplicate value in a unique index or primary key, an update of the old row occurs.
138
273
  *
139
274
  * This is only implemented by some dialects like MySQL. On most dialects you should
140
- * use {@link onConflictUpdate} instead.
275
+ * use {@link onConflict} instead.
141
276
  *
142
277
  * ### Examples
143
278
  *
@@ -180,9 +315,9 @@ class InsertQueryBuilder {
180
315
  * .selectAll()
181
316
  * .call((qb) => {
182
317
  * if (something) {
183
- * return qb.onConflictDoNothing('something')
318
+ * return qb.onConflict((oc) => oc.column('something').doNothing())
184
319
  * } else {
185
- * return qb.onConflictDoNothing('something_else')
320
+ * return qb.onConflict((oc) => oc.column('something_else').doNothing())
186
321
  * }
187
322
  * })
188
323
  * .execute()