Skip to content

feat(sqlite/query-generator): sqlite update queries now support limit via rowid - #8450

Merged
sushantdhiman merged 1 commit into
sequelize:masterfrom
netsgnut:sqlite-update-limit
Oct 16, 2017
Merged

sushantdhiman merged 1 commit into
sequelize:masterfrom
netsgnut:sqlite-update-limit

Conversation

@netsgnut

@netsgnut netsgnut commented Oct 10, 2017 •

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

By default SQLite is compiled with SQLITE_ENABLE_UPDATE_DELETE_LIMIT off. That means the UPDATE statements would not support an optional LIMIT clause. By using UPDATE ... WHERE rowid IN (SELECT rowid FROM ... WHERE ... LIMIT n) instead it can provide support in environments without such feature.

By default SQLite is compiled with SQLITE_ENABLE_UPDATE_DELETE_LIMIT
off. That means the UPDATE statements would not support an optional
LIMIT clause. By using `UPDATE ... WHERE rowid IN (SELECT rowid FROM
... WHERE ... LIMIT n)` instead it can provide support in environments
without such feature.
@netsgnut
netsgnut force-pushed the sqlite-update-limit branch from 23b874e to 63a4618 Compare October 10, 2017 08:52
@codecov

codecov Bot commented Oct 10, 2017 •

Copy link
Copy Markdown

Codecov Report

Merging #8450 into master will increase coverage by <.01%.
The diff coverage is 100%.

@sushantdhiman
sushantdhiman requested a review from a team October 11, 2017 16:02
@netsgnut

Copy link
Copy Markdown
Contributor Author

On a related note, it seems DELETE can be handled the same manner as well. Would you like that feature to be submitted as another PR, or as another commit on the same branch as this one? Thanks.

Comment thread lib/model.js
* @param {Boolean} [options.individualHooks=false] Run before / after update hooks?. If true, this will execute a SELECT followed by individual UPDATEs. A select is needed, because the row data needs to be passed to the hooks
* @param {Boolean} [options.returning=false] Return the affected rows (only for postgres)
* @param {Number} [options.limit] How many rows to update (only for mysql and mariadb, implemented as TOP(n) for MSSQL)
* @param {Number} [options.limit] How many rows to update (only for mysql and mariadb, implemented as TOP(n) for MSSQL; for sqlite it is supported only when rowid is present)

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.

isnt rowId always available?

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.

It is enabled by default, but can be absent if created with WITHOUT ROWID. Ref: https://sqlite.org/withoutrowid.html

@sushantdhiman

Copy link
Copy Markdown
Contributor

@netsgnut A different PR for delete works

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.

2 participants