call<R> method

Future<R> call<R>(
  1. Future<R> fn(
    1. T tx
    ), {
  2. int maxWait = 2000,
  3. int timeout = 5000,
  4. TransactionIsolationLevel? isolationLevel,
})

Interactive transactions.

Example

prisma.$transaction((prisma) async {
  final user = await prisma.user.create(...);
  await prisma.user.update(...);
  return user;
});

Implementation

Future<R> call<R>(
  Future<R> Function(T tx) fn, {
  int maxWait = 2000,
  int timeout = 5000,
  TransactionIsolationLevel? isolationLevel,
}) async {
  final client = await start(
    maxWait: maxWait,
    timeout: timeout,
    isolationLevel: isolationLevel,
  );

  try {
    final result = await fn(client);
    await commit();

    return result;
  } catch (e) {
    await rollback();

    rethrow;
  }
}