mirror of https://github.com/AMT-Cheif/drift.git
Support async batch callbacks (#483)
This commit is contained in:
parent
72e65611a7
commit
424c2febda
|
@ -405,8 +405,13 @@ mixin QueryEngine on DatabaseConnectionUser {
|
|||
final engine = _resolvedEngine;
|
||||
|
||||
final batch = Batch._(engine, engine is! Transaction);
|
||||
runInBatch(batch);
|
||||
return batch._commit();
|
||||
final result = runInBatch(batch);
|
||||
|
||||
if (result is Future) {
|
||||
return result.then((_) => batch._commit());
|
||||
} else {
|
||||
return batch._commit();
|
||||
}
|
||||
}
|
||||
|
||||
/// Runs [calculation] in a forked [Zone] that has its [_resolvedEngine] set
|
||||
|
|
|
@ -94,6 +94,25 @@ void main() {
|
|||
'js': [Skip('Blocked by https://github.com/dart-lang/mockito/issues/198')]
|
||||
});
|
||||
|
||||
test('supports async batch functions', () async {
|
||||
await db.batch((batch) async {
|
||||
batch.insert(
|
||||
db.categories, CategoriesCompanion.insert(description: 'first'));
|
||||
|
||||
await Future.delayed(Duration.zero);
|
||||
|
||||
batch.insert(
|
||||
db.categories, CategoriesCompanion.insert(description: 'second'));
|
||||
});
|
||||
|
||||
verify(executor.transactions.runBatched([
|
||||
BatchedStatement('INSERT INTO categories (`desc`) VALUES (?)', [
|
||||
['first'],
|
||||
['second']
|
||||
]),
|
||||
]));
|
||||
});
|
||||
|
||||
test('updates stream queries', () async {
|
||||
await db.batch((b) {
|
||||
b.insert(db.todosTable, TodoEntry(id: 3, content: 'content'));
|
||||
|
|
Loading…
Reference in New Issue