-
I've got a table where I keep log entries. I try to keep table under certain amount of rows (e.g. 50,000). Documentation demonstrates simple delete: https://drift.simonbinder.eu/dart_api/writes/#updates-and-deletes (delete(todos)..where((t) => t.id.isSmallerThanValue(10))).go(); but that's just a delete with where condition. SQLite supports DELETE with LIMIT and ORDER BY: https://www.sqlite.org/lang_delete.html#optional_limit_and_order_by_clauses Is it possible to achieve similar in Drift? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Only with a compile-time option that is not commonly enabled (and also not enabled by But you can select the oldest todo items (and apply a limit there) and then use a subquery as a condition to only delete those: Future<void> deleteOld(int itemsToDelete) async {
final oldItems = selectOnly(todoItems)
..addColumns([todoItems.id])
..orderBy([OrderingTerm.asc(todoItems.creationDate)])
..limit(itemsToDelete);
final stmt = todoItems.delete()..where((t) => t.id.isInQuery(oldItems));
await stmt.go();
} |
Beta Was this translation helpful? Give feedback.
Only with a compile-time option that is not commonly enabled (and also not enabled by
sqlite3_flutter_libs
).But you can select the oldest todo items (and apply a limit there) and then use a subquery as a condition to only delete those: