Skip to content

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

Merged
sushantdhiman merged 1 commit into
sequelize:masterfrom
gazoakley:feat-update-bind
Jun 7, 2018
Merged

sushantdhiman merged 1 commit into
sequelize:masterfrom
gazoakley:feat-update-bind

Conversation

@gazoakley

@gazoakley gazoakley commented May 30, 2018 •

Copy link
Copy Markdown
Contributor

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

codecov Bot commented May 31, 2018 •

Copy link
Copy Markdown

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

@sushantdhiman sushantdhiman left a comment

Copy link
Copy Markdown
Contributor

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

it('calls parse and stringify/bindParam for STRING', () => {
const Type = new Sequelize.STRING();

if (dialect === 'mssql') {

Copy link
Copy Markdown
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
Copy Markdown
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.

Comment thread test/integration/model/create.test.js Outdated
test = true;
expect(sql).to.contain('ARRAY[]::INTEGER[]');
expect(sql).to.contain('ARRAY[]::VARCHAR(255)[]');
expect(sql).not.to.contain('ARRAY[]::INTEGER[]');

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor Author

@sushantdhiman @janmeier Thanks 🎉

@sushantdhiman

Copy link
Copy Markdown
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.

3 participants