Skip to content

Interactive transactions: $transaction with transaction-scoped delegates #68

Description

@teetangh

Part of the complete-ORM roadmap. executeInTransaction exists at the executor level, but typed delegates always run on the root executor — multi-step atomic flows (booking: consultation + appointment + slots) force consumers back to JQB inside hand-rolled transactions.

API (Prisma parity)

final result = await prisma.$transaction((tx) async {
  final c = await tx.consultation.create(data: ...);
  await tx.appointment.create(data: CreateAppointmentInput(consultationId: c.id, ...));
  return c;
}, isolationLevel: IsolationLevel.serializable);

Implementation sketch

  • PrismaClient.$transaction(Future<T> Function(PrismaClient tx) fn, {IsolationLevel?}): start adapter transaction, construct a PrismaClient whose BaseExecutor routes through the transaction connection, commit/rollback on completion/throw.
  • Delegates already take an executor in their constructor — generate a PrismaClient._withExecutor(...) internal constructor.
  • Postgres adapter: BEGIN ISOLATION LEVEL … already supported via startTransaction.

Unlocks the booking-algorithm migration off JQB (Practitionist/familiarise_mobile#106, #113).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions