-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
UPSERT functionality for MSSQL #6842
Conversation
@harshithkashyap, thanks for your PR! By analyzing the history of the files in this pull request, we identified @mbroadst, @felixfbecker and @sushantdhiman to be potential reviewers. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM otherwise
@@ -14,3 +14,4 @@ site | |||
docs/api/tmp.md | |||
ssce.js | |||
coverage | |||
.vscode/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Out of scope for this PR. You can add this to .git/info/exclude
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No this is ok, we are already ignoring .DS_STORE
and .idea
files
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed the parens from arrow functions. Keeping the .gitignore change for now
|
||
const updateKeys = Object.keys(updateValues); | ||
const insertKeys = Object.keys(insertValues); | ||
const insertKeysQuoted = insertKeys.map((key) => this.quoteIdentifier(key)).join(', '); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unneeded parens (applies to all arrow functions you used)
Current coverage is 93.68% (diff: 100%)
|
Great job on submitting a completed upsert for MSSQL. 👍 This is one edge case bug I found trying this: If a table has 2 non-PK unique indexes and the PK was not one of the merge attributes it will always default to use the PK and cause a SQL error. The following code always assumes that if 2 clauses were found that one must be the PK which is not strictly true.
While it is an unlikely case there is nothing stopping people from setting up their tables in this manner. Consider revising the clause generation section with this:
|
@smassin Thanks for the review. :) Yes, this would fail when there are two unique keys on table. I'll push a commit with the changes. |
Additionally, and this is not an error in your code, but we really should use a lock to ensure atomicity of the MERGE statement. See: The strong recommendation is use WITH (HOLDLOCK) to ensure atomicity in concurrent situations. Ex.
|
@harshithkashyap Please rebase and we can merge it |
…(HOLDLOCK) to prevent concurrency issues, integration test for multiple unique keys
Hi there, The check of the unique columns ignores the definitions through the model indexes option.
the upsert uniqueAttrs list will end up without the email field. The code always uses all unique columns to generate the ON condition, regardless of their presence in the upsert values parameter.
source has no column email |
@janmeier @sushantdhiman We pass |
Pull Request check-list
npm run test
ornpm run test-DIALECT
pass with this change (including linting)?Future
in the changelog?Description of change
This MR enables
upsert
query for MSSQL dialect using SQL Server MERGE statements.$action
which returns Insert/Update based on the executed query.const
in places as suggested by eslintWITH(HOLDLOCK)
hint to prevent concurrency issue