Ensure the database is open before executing transactions

This commit is contained in:
Simon Binder 2019-03-30 14:56:55 +01:00
parent 93d292cff1
commit bbf12ff5ec
No known key found for this signature in database
GPG Key ID: B807FDF954BA00CF
2 changed files with 14 additions and 6 deletions

View File

@ -157,6 +157,7 @@ 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 {
await executor.doWhenOpened((executor) async {
final transaction = Transaction(this, executor.beginTransaction()); final transaction = Transaction(this, executor.beginTransaction());
try { try {
@ -164,6 +165,7 @@ mixin QueryEngine on DatabaseConnectionUser {
} finally { } finally {
await transaction.complete(); await transaction.complete();
} }
});
} }
} }

View File

@ -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));
});
});
} }