-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
feat(query-generator): Generate UPDATEs using bind parameters #9492
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
Conversation
c8b94c1
to
52aecbc
Compare
52aecbc
to
d9cf786
Compare
62ec295
to
432f567
Compare
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.
Looks good overall, would like comments from other members
test/integration/data-types.test.js
Outdated
const Type = new Sequelize.STRING(); | ||
|
||
if (dialect === 'mssql') { |
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.
Why only mssql?
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.
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[]'); |
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.
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[]
?
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.
432f567
to
207c6d3
Compare
@sushantdhiman @janmeier Thanks 🎉 |
Thanks for this contribution @gazoakley , This is an important missing feature from Sequelize |
Pull Request check-list
Please make sure to review and check all of these items:
npm run test
ornpm run test-DIALECT
pass with this change (including linting)?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'
and2
)