mirror of https://github.com/AMT-Cheif/drift.git
Ensure the database is open before executing transactions
This commit is contained in:
parent
93d292cff1
commit
bbf12ff5ec
|
@ -157,13 +157,15 @@ mixin QueryEngine on DatabaseConnectionUser {
|
||||||
/// queries and updates must be sent to the [QueryEngine] passed to the
|
/// queries and updates must be sent to the [QueryEngine] passed to the
|
||||||
/// [action] function.
|
/// [action] function.
|
||||||
Future transaction(Future Function(QueryEngine transaction) action) async {
|
Future transaction(Future Function(QueryEngine transaction) action) async {
|
||||||
final transaction = Transaction(this, executor.beginTransaction());
|
await executor.doWhenOpened((executor) async {
|
||||||
|
final transaction = Transaction(this, executor.beginTransaction());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await action(transaction);
|
await action(transaction);
|
||||||
} finally {
|
} finally {
|
||||||
await transaction.complete();
|
await transaction.complete();
|
||||||
}
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -50,4 +50,10 @@ void main() {
|
||||||
verify(streamQueries.handleTableUpdates({db.users})).called(1);
|
verify(streamQueries.handleTableUpdates({db.users})).called(1);
|
||||||
verify(executor.transactions.send());
|
verify(executor.transactions.send());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('the database is opened before starting a transaction', () async {
|
||||||
|
await db.transaction((t) async {
|
||||||
|
verify(executor.doWhenOpened(any));
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue