-
Notifications
You must be signed in to change notification settings - Fork 74
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
use 'returning: true' for postgres to keep patch and its response atomic #93
Conversation
Does this only work for Postgres? |
Yes.
|
src/index.js
Outdated
if (this.dialect === 'postgres') { | ||
options.returning = true; | ||
return this.Model.update(omit(data, this.id), options) | ||
.then((results) => { |
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.
.then(results => results[1])
src/index.js
Outdated
if (id !== null) { | ||
where[this.id] = id; | ||
} | ||
|
||
const options = Object.assign({}, params.sequelize, { where }); | ||
|
||
// This is the best way to implement patch in sql, the other dialects 'should' use a transaction. | ||
if (this.dialect === 'postgres') { |
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.
I'd check options.Model.sequelize.options.dialect
here and remove setting it in the constructor
Released as |
Summary
This PR utilizes the Sequelize returning option for update to do PATCH, in a single action.
This is a non-breaking change.
Other Information
The PATCH procedure for the other dialects should probably also be reworked to use transactions, this may only cause problems on large scale deployments, but it is a potential issue.