Repository navigation
feat(sqlite/query-generator): sqlite delete supporting limit via rowid - #8494
Conversation
13488e7 to
2eb8dc1
Compare
2eb8dc1 to
83f2aa7
Compare
|
@netsgnut Some tests fail, but overall looks good to me |
83f2aa7 to
f254ddb
Compare
|
How about a integration test that verifies the functionality? |
Sounds like a good idea, although frankly I am not sure how to implement a proper integration test apart from the modified test cases... |
sushantdhiman
left a comment
There was a problem hiding this comment.
Dont set limit if its undefined.
You need to add a unit test for both cases
- limit is set, rowId based query
- limit is not set, old delete query
| if (options.limit) { | ||
| return `DELETE FROM ${this.quoteTable(tableName)} WHERE rowid IN (SELECT rowid FROM ${this.quoteTable(tableName)}${whereClause} LIMIT ${this.escape(options.limit)})`; | ||
| } else { | ||
| return `DELETE FROM ${this.quoteTable(tableName)}${whereClause}`; |
There was a problem hiding this comment.
This case will never run, if limit is undefined you are setting is to 1, which will always trigger if case.
I suggest just remove options.limit/isUndefined part, switch query only when limit is supplied by user
There was a problem hiding this comment.
OK. Although I am still curious on why we would need the options.limit/isUndefined part from dialect/mysql.js, I guess we really should drop the conditional here. Updating it.
That said, is there a case where limit is 0, though? If so that would be a case that triggers the else clause.
There was a problem hiding this comment.
In that case it would be better to check for isDefined in if expression, because we want to limit DELETE even if its set to 0.
There was a problem hiding this comment.
In that case it would be better to check for
isDefinedin if expression, because we want to limit DELETE even if its set to 0.
Do you want that to reflect on other dialects as well? Because I am afraid this is not how the current implementation for all other dialects is. That includes MySQL, PostgreSQL and MSSQL.
16cab14 to
9366da0
Compare
By default SQLite is compiled with SQLITE_ENABLE_UPDATE_DELETE_LIMIT off. That means the DELETE statements would not support an optional LIMIT clause. By using `DELETE ... WHERE rowid IN (SELECT rowid FROM ... WHERE ... LIMIT n)` instead it can provide support in environments without such feature.
9366da0 to
3001741
Compare
|
I have updated the PR for a little refactoring of the code (3001741), but on second thought in order to maintain the consistency with other implementations here I did not change much of the logic. Regarding @sushantdhiman's comments:
This is essential for the SQLite implementation to behave like other dialects. Without setting the limit the
The cases are already covered with the current test That said, I think there should be a standard behavior defined for all the dialects facing the common cases where the |
|
(Not sure why the AppVeyor build failed though for 3001741...) |
|
@netsgnut Its clear that if you don't supply limit, whatever the where condition may be code will end up deleting only first row. No matter how I process it, it feels wrong. Investigated and found this line has been saving us till now. I agree changing other dialect is not a part of this PR, but this is a potential mishap in waiting. This code section is old so I dont know the reason behind this, probably implementer(s) just copied code from first dialect to others. Since we default to limit |
Pull Request check-list
Please make sure to review and check all of these items:
npm run testornpm run test-DIALECTpass with this change (including linting)?Description of change
By default SQLite is compiled with
SQLITE_ENABLE_UPDATE_DELETE_LIMIToff. That means theDELETEstatements would not support an optionalLIMITclause. By usingDELETE ... WHERE rowid IN (SELECT rowid FROM ... WHERE ... LIMIT n)instead it can provide support in environments without such feature.(This is a companion PR to #8450.)