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(upsert): return upserted record with options.returning=true #8924
Conversation
lib/model.js
Outdated
* @param {Transaction} [options.transaction] Transaction to run query under | ||
* @param {Function} [options.logging=false] A function that gets executed while running the query to log the sql. | ||
* @param {Boolean} [options.benchmark=false] Pass query execution time in milliseconds as second argument to logging function (options.logging). | ||
* @param {String} [options.searchPath=DEFAULT] An optional parameter to specify the schema search_path (Postgres only) | ||
* | ||
* @return {Promise<created>} Returns a boolean indicating whether the row was created or updated. | ||
* @return {Promise<created>} Returns a boolean indicating whether the row was created or updated. For Postgres with (options.returning=true), it returns record and created boolean with signature `<Model, created>`. |
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.
In v5, we can set this Promise<record, created>
by setting returning=true
by default. One caveat is null
is now first argument for other dialects. May be should set this as Promise<created, record>
, but that doesn't match with other method's API. Any ideas?
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 have added support for MSSQL as well, so now may be current order make sense.
In issue #3354 there is discussion about MySQL support, but I find that Currently we support MSSQL and Postgres for this feature |
392ba45
to
81dd103
Compare
If they're using non-incrementing primary keys, they most probably won't need LAST_INSERTED_ID. Those who use auto-incremented primary keys (absolute majority) on MySql (#1 rdbms) have no use of the current upsert method. Please fix it! :) |
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
Close #3354
Sequelize still doesnot support
ON CONFLICT
, but with usingRETURNING
its now possible for return upserted record.