runInTransaction method

dynamic runInTransaction(
  1. Function function
)

Run a function inside a transaction.

If the transaction is not open, the method also opens it. In case of exception a rollback is performed. If the function finishes properly, the transaction is closed.

Implementation

dynamic runInTransaction(Function function) {
  if (!_transactionOpen) {
    openTransaction();
  }
  try {
    dynamic result = function(_db);
    closeTransaction();
    return result;
  } on Exception catch (e, s) {
    SLogger().e("Error during transaction.", e, s);
    rollback();
  }
  return null;
}