commit method

Future<List<Object?>> commit({
  1. bool? exclusive,
  2. bool? noResult,
  3. bool? continueOnError,
})

Runs the queued statements.

exclusive wraps them in one transaction and defaults to true. A SQL error rolls that transaction back unless continueOnError is true, in which case the slot holds the SqlException. noResult returns an empty list after the statements run.

Implementation

Future<List<Object?>> commit({
  bool? exclusive,
  bool? noResult,
  bool? continueOnError,
}) async {
  final keepGoing = continueOnError ?? false;
  Future<List<Object?>> run(Transaction txn) async {
    final results = <Object?>[];
    for (final operation in _operations) {
      try {
        results.add(await operation(txn));
      } on SqlException catch (error) {
        if (!keepGoing) rethrow;
        results.add(error);
      }
    }
    if (noResult ?? false) return const [];
    return results;
  }

  if (exclusive ?? true) return _commands.transaction(run);
  return run(Transaction._(_commands));
}