Skip to content

Commit

Permalink
feat(sqlite/query-generator): support restart identity for truncate-t…
Browse files Browse the repository at this point in the history
…able (#10522)
  • Loading branch information
SavageCore authored and sushantdhiman committed Mar 9, 2019
1 parent 3cd3891 commit 0c68590
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 5 additions & 2 deletions lib/dialects/sqlite/query-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,11 @@ class SQLiteQueryGenerator extends MySqlQueryGenerator {
return { query, bind };
}

truncateTableQuery(tableName) {
return `DELETE FROM ${this.quoteTable(tableName)}`;
truncateTableQuery(tableName, options = {}) {
return [
`DELETE FROM ${this.quoteTable(tableName)}`,
options.restartIdentity ? `; DELETE FROM ${this.quoteTable('sqlite_sequence')} WHERE ${this.quoteIdentifier('name')} = ${Utils.addTicks(Utils.removeTicks(this.quoteTable(tableName), '`'), "'")};` : ''
].join('');
}

deleteQuery(tableName, where, options = {}, model) {
Expand Down
2 changes: 1 addition & 1 deletion test/unit/sql/delete.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ describe(Support.getTestDialectTeaser('SQL'), () => {
mssql: 'TRUNCATE TABLE [public].[test_users]',
mariadb: 'TRUNCATE `public`.`test_users`',
mysql: 'TRUNCATE `public.test_users`',
sqlite: 'DELETE FROM `public.test_users`'
sqlite: 'DELETE FROM `public.test_users`; DELETE FROM `sqlite_sequence` WHERE `name` = \'public.test_users\';'
}
);
});
Expand Down

0 comments on commit 0c68590

Please sign in to comment.