You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* feat(upsert): add conflictFields option
Adds support for the `conflictFields` option to `Model.upsert`.
This is used for `options.upsertKeys` in `QueryInterface.prototype.upsert` if provided for specifying the fields
used at `ON CONFLICT({fields})` rather than relying on the default logic.
* add conflictFields to the right type
Co-authored-by: Sascha Depold <[email protected]>
Copy file name to clipboardExpand all lines: lib/model.js
+11-10Lines changed: 11 additions & 10 deletions
Original file line number
Diff line number
Diff line change
@@ -2445,16 +2445,17 @@ class Model {
2445
2445
*
2446
2446
* **Note** that Postgres/SQLite returns null for created, no matter if the row was created or updated
2447
2447
*
2448
-
* @param {object} values hash of values to upsert
2449
-
* @param {object} [options] upsert options
2450
-
* @param {boolean} [options.validate=true] Run validations before the row is inserted
2451
-
* @param {Array} [options.fields=Object.keys(this.attributes)] The fields to update if the record already exists. Defaults to all changed fields. If none of the specified fields are present on the provided `values` object, an insert will still be attempted, but duplicate key conflicts will be ignored.
2452
-
* @param {boolean} [options.hooks=true] Run before / after upsert hooks?
2453
-
* @param {boolean} [options.returning=true] If true, fetches back auto generated values
2454
-
* @param {Transaction} [options.transaction] Transaction to run query under
2455
-
* @param {Function} [options.logging=false] A function that gets executed while running the query to log the sql.
2456
-
* @param {boolean} [options.benchmark=false] Pass query execution time in milliseconds as second argument to logging function (options.logging).
2457
-
* @param {string} [options.searchPath=DEFAULT] An optional parameter to specify the schema search_path (Postgres only)
2448
+
* @param {object} values hash of values to upsert
2449
+
* @param {object} [options] upsert options
2450
+
* @param {boolean} [options.validate=true] Run validations before the row is inserted
2451
+
* @param {Array} [options.fields=Object.keys(this.attributes)] The fields to update if the record already exists. Defaults to all changed fields. If none of the specified fields are present on the provided `values` object, an insert will still be attempted, but duplicate key conflicts will be ignored.
2452
+
* @param {boolean} [options.hooks=true] Run before / after upsert hooks?
2453
+
* @param {boolean} [options.returning=true] If true, fetches back auto generated values
2454
+
* @param {Transaction} [options.transaction] Transaction to run query under
2455
+
* @param {Function} [options.logging=false] A function that gets executed while running the query to log the sql.
2456
+
* @param {boolean} [options.benchmark=false] Pass query execution time in milliseconds as second argument to logging function (options.logging).
2457
+
* @param {string} [options.searchPath=DEFAULT] An optional parameter to specify the schema search_path (Postgres only)
2458
+
* @param {Array<string>} [options.conflictFields] Optional override for the conflict fields in the ON CONFLICT part of the query. Only supported in Postgres >= 9.5 and SQLite >= 3.24.0
2458
2459
*
2459
2460
* @returns {Promise<Array<Model, boolean | null>>} returns an array with two elements, the first being the new record and the second being `true` if it was just created or `false` if it already existed (except on Postgres and SQLite, which can't detect this and will always return `null` instead of a boolean).
0 commit comments