


To use interactive transactions, you can pass an async function into $transaction.
#TRANSACTION GENERATOR#
If you use interactive transactions in preview from version 2.29.0 to 4.6.1 (included), you need to add the interactiveTransactions preview feature to the generator block of your Prisma schema. From version 2.29.0 to version 4.5, interactive transactions were available in preview, but did not support the Data Proxy.In version 4.6, Data Proxy support for interactive transactions was available in preview.Interactive transactions are generally available from version 4.7.0.Interactive transactions are available in the following versions of Prisma: Interactive transactions are meant to provide you with an escape hatch. Sometimes you need more control over what queries execute within a transaction. The following example demonstrates a nested write with create: Prisma Client ensures that all operations succeed or fail as a whole. For example, creating a user together with a post or updating an order together with an invoice.

#TRANSACTION CODE#
Interactive transactions: pass a function that can contain user code including Prisma Client queries, non-Prisma code and other control flow to be executed in a transaction, using $transaction(fn: (prisma: PrismaClient) => R, options?: object): RĪ nested write lets you perform a single Prisma Client API call with multiple operations that touch multiple related records.Sequential operations: pass an array of Prisma Client queries to be executed sequentially inside a transaction, using $transaction(queries: PrismaPromise): Promise.Batch / bulk transactions: process one or more operations in bulk with updateMany, deleteMany, and createMany.Nested writes: use the Prisma Client API to process multiple operations on one or more related records inside the same transaction.Prisma provides the following options for using transactions: For information about transactions in general and the reasoning behind Prisma's current solutions, see ✍ Blog: How Prisma supports transactions.For more in-depth examples and use cases, refer to the 📖 transactions guide.This section describes the ways in which the Prisma Client API supports transactions. A database transaction refers to a sequence of read/write operations that are guaranteed to either succeed or fail as a whole.
