Repository navigation
Conversation
(postgres and sqlite only)
wbourne0
left a comment
There was a problem hiding this comment.
Looks good. A few long lines that imo should be split into multiple but given as there isn't any enforcement of that e.g. prettier, not a big deal.
| @@ -0,0 +1,40 @@ | |||
| import { DataTypes, Sequelize } from 'sequelize'; | |||
There was a problem hiding this comment.
small nit here: can you add some tests for invalid typing and use // @ts-expect-error comment explaining why the typing is invalid?
| User.bulkCreate(data, { | ||
| fields: ['uniqueName', 'secretValue', 'intVal'], | ||
| updateOnDuplicate: ['secretValue', 'intVal'] | ||
| }); |
There was a problem hiding this comment.
nit: this should probably have some sort check for the return type of this.
| - MSSQL - Implemented with MERGE statement | ||
|
|
||
| _<ins>Note for Postgres users:</ins>_ If upsert payload contains PK field, then PK will be used as the conflict target. Otherwise first unique constraint will be selected as the conflict key. | ||
| _<ins>Note for Postgres and SQLite users:</ins>_ If the upsert payload contains a primary key field, then it will be used as the conflict target. Otherwise the first unique constraint will be selected as the conflict target. Also, since v6.7.0, you can provide a where condition with the new `conflictWhere` option. |
There was a problem hiding this comment.
make sure that this is still accurate when you merge it.
edit: to clarify, the version number.
conflictWhere optionconflictWhere option
wbourne0
left a comment
There was a problem hiding this comment.
Actually it looks like this PR also adds this functionality to upsert, there just isn't any tests or docs on it. Can you remove that or add in tests? I'll throw up another PR for this if its removed.
removed the changes to QueryGenerator.prototype.insertQuery
There was a problem hiding this comment.
Well, just learned something! Apparently there's a difference in ON CONFLICT WHERE (...) DO UPDATE ... and ON CONFLICT DO UPDATE ... WHERE.
The first one will use indices, and can only target the current rows, e.g. "isUnique" = true not "table"."isUnique" = true, and the second one won't affect how indices are handled.
Because of this, it makes more sense (IMO) for this to be onConflictDoUpdateWhere vs onConflictWhere.
Rework of #13155 adding documentation and TypeScript tests (and with less unrelated changes)