Skip to content

feat(bulk-create): add conflictWhere option - #13346

Closed
papb wants to merge 2 commits into
mainfrom
conflict-where
Closed

papb wants to merge 2 commits into
mainfrom
conflict-where

Conversation

@papb

@papb papb commented Jun 24, 2021

Copy link
Copy Markdown
Member

Rework of #13155 adding documentation and TypeScript tests (and with less unrelated changes)

(postgres and sqlite only)

@wbourne0 wbourne0 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread types/test/bulk-create.ts
@@ -0,0 +1,40 @@
import { DataTypes, Sequelize } from 'sequelize';

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

small nit here: can you add some tests for invalid typing and use // @ts-expect-error comment explaining why the typing is invalid?

Comment thread types/test/bulk-create.ts
Comment on lines +23 to +26
User.bulkCreate(data, {
fields: ['uniqueName', 'secretValue', 'intVal'],
updateOnDuplicate: ['secretValue', 'intVal']
});

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@wbourne0 wbourne0 Jun 24, 2021 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make sure that this is still accurate when you merge it.

edit: to clarify, the version number.

@papb papb changed the title feat(upsert): add conflictWhere option feat(bulk-create): add conflictWhere option Jun 26, 2021
@papb papb self-assigned this Jun 26, 2021
@papb papb added status: wip For issues and PRs. Applied when the PR is not ready yet / when work to close the issue has started. type: feature DEPRECATED: replace with the "feature" issue type labels Jun 26, 2021

@wbourne0 wbourne0 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@wbourne0
wbourne0 dismissed their stale review July 29, 2021 00:15

removed the changes to QueryGenerator.prototype.insertQuery

@wbourne0 wbourne0 left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@wbourne0 wbourne0 assigned wbourne0 and papb and unassigned papb and wbourne0 Aug 4, 2021
@github-actions github-actions Bot added the stale label Oct 27, 2021
@github-actions github-actions Bot closed this Nov 2, 2021
@sdepold
sdepold deleted the conflict-where branch December 10, 2021 03:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stale status: wip For issues and PRs. Applied when the PR is not ready yet / when work to close the issue has started. type: feature DEPRECATED: replace with the "feature" issue type

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants