transaction<T> abstract method
Runs action in a transaction.
The transaction is committed when action completes and rolled back
when it throws (the error is then rethrown). Return a value from
action to get it as the result.
Calls in action must only be done using the transaction object using the database will trigger a dead-lock.
await database.transaction((txn) async {
// Ok
await txn.execute('CREATE TABLE Test1 (id INTEGER PRIMARY KEY)');
// DON'T use the database object in a transaction
// this will deadlock!
await database.execute('CREATE TABLE Test2 (id INTEGER PRIMARY KEY)');
});
Implementation
Future<T> transaction<T>(
Future<T> Function(Transaction txn) action, {
bool? exclusive,
});