mirror of https://github.com/AMT-Cheif/drift.git
Batch: Delete method for insertables
This commit is contained in:
parent
c2ec06c1de
commit
cefa290d7e
|
@ -94,11 +94,22 @@ class Batch {
|
|||
}
|
||||
}
|
||||
|
||||
/// Deletes [row] from the [table] when this batch is executed.
|
||||
///
|
||||
/// See also:
|
||||
/// - [QueryEngine.delete]
|
||||
/// - [DeleteStatement.delete]
|
||||
void delete<T extends Table, D extends DataClass>(
|
||||
TableInfo<T, D> table, Insertable<D> row) {
|
||||
final stmt = DeleteStatement(_engine, table)..whereSamePrimaryKey(row);
|
||||
_addContext(stmt.constructQuery());
|
||||
}
|
||||
|
||||
/// Deletes all rows from [table] matching the provided [filter].
|
||||
///
|
||||
/// See also:
|
||||
/// - [QueryEngine.delete]
|
||||
void delete<T extends Table, D extends DataClass>(TableInfo<T, D> table,
|
||||
void deleteWhere<T extends Table, D extends DataClass>(TableInfo<T, D> table,
|
||||
Expression<bool, BoolType> Function(T tbl) filter) {
|
||||
final stmt = DeleteStatement(_engine, table)..where(filter);
|
||||
_addContext(stmt.constructQuery());
|
||||
|
|
|
@ -38,7 +38,8 @@ void main() {
|
|||
CategoriesCompanion(id: Value(2), description: Value('new2')),
|
||||
]);
|
||||
|
||||
b.delete(db.categories, (_) => const Constant(true));
|
||||
b.deleteWhere(db.categories, (_) => const Constant(true));
|
||||
b.delete(db.todosTable, const TodosTableCompanion(id: Value(3)));
|
||||
});
|
||||
|
||||
final transaction = executor.transactions;
|
||||
|
@ -73,6 +74,12 @@ void main() {
|
|||
'DELETE FROM categories WHERE 1;',
|
||||
[[]],
|
||||
),
|
||||
BatchedStatement(
|
||||
'DELETE FROM todos WHERE id = ?;',
|
||||
[
|
||||
[3]
|
||||
],
|
||||
),
|
||||
]));
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue