Skip to content
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

fix (mssql): bulkUpdate returning values #12410

Merged
merged 5 commits into from Jun 26, 2020
Merged

Conversation

ShaharHD
Copy link
Contributor

@ShaharHD ShaharHD commented Jun 23, 2020

Pull Request check-list

Please make sure to review and check all of these items:

  • Does npm run test or npm run test-DIALECT pass with this change (including linting)?
  • Does the description below contain a link to an existing issue (Closes #[issue]) or a description of the issue you are solving?
  • Have you added new tests to prevent regressions?
  • Is a documentation update included (if this change modifies existing APIs, or introduces new ones)?
  • Did you update the typescript typings accordingly (if applicable)?
  • Did you follow the commit message conventions explained in CONTRIBUTING.md?

Description of change

Fix MSSQL returning values for bulkUpdate

The issue creates a major performance hit for v5 - as bulkUpdates right now does not work correctly and requires to run another query to get the model data - which is returning already in the update itself.

  • bulkUpdate will now return the updates if options.returning is true.
  • updateQuery removed redundant setting check
  • Fix documentation for model.update

@ShaharHD
Copy link
Contributor Author

ShaharHD commented Jun 23, 2020

The CI fails on an npm install error: mariadb requires at least version 10.13 of Node, please upgrade

@ShaharHD ShaharHD closed this Jun 23, 2020
@ShaharHD ShaharHD reopened this Jun 23, 2020
@ShaharHD ShaharHD changed the title Fix MSSQL returning values for bulkUpdate Fix (msssql) bulkUpdate returning values Jun 23, 2020
@ShaharHD ShaharHD changed the title Fix (msssql) bulkUpdate returning values Fix (mssql) bulkUpdate returning values Jun 23, 2020
@ShaharHD ShaharHD changed the title Fix (mssql) bulkUpdate returning values fix (mssql): bulkUpdate returning values Jun 23, 2020
@sushantdhiman
Copy link
Contributor

You need to submit a fix to master branch before this can be merged

@sushantdhiman sushantdhiman added the status: awaiting response For issues and PRs. OP must respond (or change something, if it is a PR). Maintainers have no action label Jun 23, 2020
@ShaharHD
Copy link
Contributor Author

ShaharHD commented Jun 23, 2020

You need to submit a fix to master branch before this can be merged

#12413 was created as requested.
But the issue has a major performance hit for v5 - as bulkUpdates right now does not work correctly and requires in the code to run another query to get the model data - which is returning already in the update itself.

@@ -393,7 +393,7 @@ class QueryGenerator {

suffix += selectFromTmp;
}
} else if (this._dialect.supports.returnValues && options.returning) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Keep this check, first check test if dialect supports returnings like MySQL which doesn't support it. Second if user is requesting to return records

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Look at line 367 - you won't even get into this if statement if this._dialect.supports.returnValues was false. why recheck for it?

@sushantdhiman
Copy link
Contributor

The issue creates a major performance hit for v5

I didn't understand this, are you saying this change will improve performance?

@ShaharHD
Copy link
Contributor Author

ShaharHD commented Jun 24, 2020

The issue creates a major performance hit for v5

I didn't understand this, are you saying this change will improve performance?

Yes.

Consider this scenario:

const [rowsUpdate, [updatedBook]] = Book.update(
   {price: 100},
   {returning: true, where: {price: 0} }
 )

Without this PR - updatedBook will be undefined (and not populated with the updated records returned by MSSQL OUTPUT INSERTED.*) which means you'll need to to issue another query to pull the data (and in some cases it is not possible as the data might have already changed)

- bulkUpdate will now return the updates if options.returning is true.
- updateQuery removed duplicate setting check
- Fix documentation for model.update
Reference for change is based on sequelize#12260

- use rowCount intead of data.length when not returning data
@ShaharHD
Copy link
Contributor Author

ShaharHD commented Jun 26, 2020

@sunshinewyin Added the new test to this branch as well as master

Look for should output the updated record in the tests.

Seems the test now fail on an unrelated issue bash : curl: (3) <url> malformed

@sushantdhiman sushantdhiman merged commit ad1c153 into sequelize:v5 Jun 26, 2020
@sushantdhiman
Copy link
Contributor

🎉 This PR is included in version 5.22.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
released status: awaiting response For issues and PRs. OP must respond (or change something, if it is a PR). Maintainers have no action
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants