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

feat(query-generator): Generate UPDATEs using bind parameters #9492

Merged
merged 1 commit into from
Jun 7, 2018

Conversation

gazoakley
Copy link
Contributor

@gazoakley gazoakley commented May 30, 2018

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 follow the commit message conventions explained in CONTRIBUTING.md?

Description of change

Changes to allow UPDATEs to use bind parameters instead of directly included values. For example, instead of:

UPDATE `myTable` SET `name`='foo',`birthday`='2011-03-27 10:01:55' WHERE `id` = 2

Generate:

UPDATE `myTable` SET `name`=$1,`birthday`=$2 WHERE `id` = $3

(with parameters 'foo', '2011-03-27 10:01:55' and 2)

@codecov
Copy link

codecov bot commented May 31, 2018

Codecov Report

Merging #9492 into master will decrease coverage by 0.02%.
The diff coverage is 100%.

@gazoakley gazoakley force-pushed the feat-update-bind branch 3 times, most recently from 62ec295 to 432f567 Compare May 31, 2018 10:13
@gazoakley gazoakley changed the title [WIP] feat(query-generator): Generate UPDATEs using bind parameters feat(query-generator): Generate UPDATEs using bind parameters May 31, 2018
Copy link
Contributor

@sushantdhiman sushantdhiman left a comment

Choose a reason for hiding this comment

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

Looks good overall, would like comments from other members

const Type = new Sequelize.STRING();

if (dialect === 'mssql') {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why only mssql?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

mssql has a _bindParam function that outputs either a Buffer or a normal string dependent on whether or not the STRING data type uses the binary param. This override isn't needed for other dialects - I've added a comment.

@@ -984,8 +984,8 @@ describe(Support.getTestDialectTeaser('Model'), () => {
return user.save({
logging(sql) {
test = true;
expect(sql).to.contain('ARRAY[]::INTEGER[]');
expect(sql).to.contain('ARRAY[]::VARCHAR(255)[]');
expect(sql).not.to.contain('ARRAY[]::INTEGER[]');
Copy link
Contributor

Choose a reason for hiding this comment

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

These tests should be moved to unit tests, but that is too much work, should be tackled in different PR. Please add some assertion which covers what is expected here, like may be just ARRAY[]?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@sushantdhiman sushantdhiman merged commit 9b1ca37 into sequelize:master Jun 7, 2018
@gazoakley
Copy link
Contributor Author

@sushantdhiman @janmeier Thanks 🎉

@sushantdhiman
Copy link
Contributor

Thanks for this contribution @gazoakley , This is an important missing feature from Sequelize

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants