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
|
||||
/// [action] function.
|
||||
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 {
|
||||
await action(transaction);
|
||||
} finally {
|
||||
await transaction.complete();
|
||||
}
|
||||
try {
|
||||
await action(transaction);
|
||||
} finally {
|
||||
await transaction.complete();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -50,4 +50,10 @@ void main() {
|
|||
verify(streamQueries.handleTableUpdates({db.users})).called(1);
|
||||
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