Prisma
prisma.io › home › transactions and batch queries › transactions and batch queries › transactions and batch queries › transactions and batch queries
Transactions and batch queries (Reference) | Prisma Documentation
To create an interactive transaction, pass an async function into $transaction. The first argument passed into this async function is an instance of the Prisma Client. Below, we will call this instance tx.
DEV Community
dev.to › ashukr22 › interactive-transactions-in-prisma-a-developers-guide-4mg6
Interactive Transactions in Prisma: A Developer's Guide - DEV Community
July 10, 2025 - const result = await prisma.$transaction(async (tx) => { const user = await tx.user.create({ data: { name: "John", email: "john@example.com" } }); const profile = await tx.profile.create({ data: { userId: user.id, bio: "Software developer" } }); return { user, profile }; }); If the second operation fails (creating the profile), the user creation is also rolled back ensuring data consistency. Interactive transactions have performance costs and should be avoided when queries are unrelated or read-only.
Sequential and interactive transactions have different limits on number of statements allowed.
Both approaches have the same behavior: either they're ok with X records, or they both error out and close the transaction early. ... prisma : 4.13.0 @prisma/client : 4.13.0 Current platform : darwin-arm64 Query Engine (Node-API) : libquery-engine 1e7af066ee9cb95cf3a403c78d9aab3e6b04f37a (at ... More on github.com
API for interactive transactions with dependencies between write-operations
It should be considered whether it is helpful to add such an API to Prisma, or whether abstractions like nested mutations and the requested transactional execution of multiple independent transactions are the better approach for Prisma. More on github.com
typescript - Error to implement Interactive transactions using Prisma ORM - Stack Overflow
I'm trying to use Interactive transactions to perform a transaction in my database, but i've got an error by the compiler while writing the function. I even tried to copy and paste the same code that is on documentation, but got the same error · "Argument of type '(tx: any) => Promise' is not assignable to parameter of type 'PrismaPromise... More on stackoverflow.com
postgresql - Prisma: how to write transaction where results from one query are used by another query - Stack Overflow
I'm working on a project with Next.js and Prisma. In one of my API routes, I have a three queries. The results of the first and second queries are used in the third query. I'd like to do all three More on stackoverflow.com
How to Do Database Transactions in Prisma ORM - YouTube
How to use transactions in Prisma/Next.js/T3 Stack
07:32
Interactive Transactions in Prisma - YouTube
06:18
How to Use Transactions in Prisma - YouTube
07:33
Why I needed to add prisma transactions to my SaaS - YouTube
01:00
Prisma Makes Transactions so Easy! - YouTube
Prisma Client Python
prisma-client-py.readthedocs.io › en › stable › reference › transactions
Transactions - Prisma Client Python
Prisma Client Python supports interactive transactions, this is a generic solution allowing you to run multiple operations as a single, atomic operation - if any operation fails, or any other error is raised during the transaction, Prisma will roll back the entire transaction.
DEV Community
dev.to › this-is-learning › its-prisma-time-transactions-ji5
It's Prisma Time - Transactions - DEV Community
February 16, 2023 - since 4.7.0, this feature has been production ready, so you can remove the "interactiveTransactions" flag. after that it's necessary to update the prisma definitions, so run in your terminal this command · npx prisma generate · By doing this, we enabled the feature. Now, we'll see the previous example, rewritten in the way that the author and post are in relation. Let's see the result · const result = await prisma.$transaction(async prisma => { const authorData = { firstName: "Author from transaction", lastName: "Author from transaction", age: getRandomInt(16, 100), } as const; const author
GitHub
github.com › prisma › prisma › discussions › 14435
How can I test Interactive transactions? · prisma/prisma · Discussion #14435
Basically I'd like to throw an error in the end of the transaction to assert that the DB state is correct at the end (meaning, all changes were rolled-backed) Beta Was this translation helpful? Give feedback. ... There was an error while loading. Please reload this page. Something went wrong. There was an error while loading. Please reload this page. ... it('test', async () => { prisma.$transaction.mockImplementationOnce((cb) => cb(prisma)); prisma.entity1.create.mockResolvedValueOnce('created'); prisma.entity2.create.mockRejectedValueOnce('creation error');
Author prisma
GitHub
github.com › avan2s › prisma-transactions
GitHub - avan2s/prisma-transactions: a library for having more control in prisma's transactional behaviour including propagation types · GitHub
It is based on the idea of Java Spring Transactional Propagations. With these annotation you get full control over the transaction inside you methods. Prisma supports interactive transactions and creates a transactional client.
Author avan2s
DEV Community
dev.to › reyronald › dealing-with-open-database-transactions-in-prisma-3clk
Dealing with open database transactions in Prisma - DEV Community
February 23, 2025 - Consider increasing the interactive transaction timeout or doing less work in the transaction.' } The error message is self-explanatory but it’s also misleading at the same time. You’ll indeed see this if you open a transaction with Prisma and don’t finish it or close it before the timeout interval, but what it doesn’t say is that open transactions can get stuck and never be closed by Prisma itself when certain conditions are met.
GitHub
github.com › prisma › prisma › issues › 19345
Sequential and interactive transactions have different limits on number of statements allowed. · Issue #19345 · prisma/prisma
May 19, 2023 - Bug description Experimentally, I've noticed that the interactive $transaction API limits the amount of queries before it'll forcefully end the transaction. Roughly pseudocoding: const arrayWith3000Records = [...Array(3000)].map(i => i) ...
Author prisma
GitHub
github.com › prisma › prisma › issues › 1844
API for interactive transactions with dependencies between write-operations · Issue #1844 · prisma/prisma
January 10, 2019 - However, this feature does not allow for creating a transaction where the mutations depend on each other. Here is an example where the second operation depends on the first: prisma.transaction(async tx => { const user = await tx.createUser({ name, }) // compute some stuff await tx.updateOrder(user.id) await tx.commit() })
Author prisma
GitHub
github.com › prisma › prisma › discussions › 17373
Performance Comparison Using Interactive transactions VS multiple prisma.$transaction · prisma/prisma · Discussion #17373
Prisma supports multiple ways of handling transactions, either directly through the API or by supporting your ability to introduce optimistic concurrency control through interactive transactions.
Author prisma
Stack Overflow
stackoverflow.com › questions › 74562722 › error-to-implement-interactive-transactions-using-prisma-orm
typescript - Error to implement Interactive transactions using Prisma ORM - Stack Overflow
# code that i write static async transfer(transaction: Transcation) { return await client.$transaction(async (ts) => { // There is a account model in my db, with balance and ID properties const sender = await ts.account.update({ data: { balance: { decrement: transaction.value } }, where: { id: transaction.debitedAccountId } }) const recipient = await ts.account.update({ data: { balance: { increment: transaction.value } }, where: { id: transaction.creditedAccountId } }) // Those will check a conditional and throw an error if true validateBalanceToTransaction(sender.balance) validateTransactionDestination(sender.id, recipient.id) return recipient; }) } I added previewFeatures to my generator on schema.prisma as the docs say · generator client { provider = "prisma-client-js" previewFeatures = ["interactiveTransactions"] }
GitHub
github.com › prisma › prisma › discussions › 20016
Prisma Client Extensions and Interactive Transactions · prisma/prisma · Discussion #20016
The timeout for this transaction was 5000 ms, however 5029 ms passed since the start of the transaction. Consider increasing the interactive transaction timeout or doing less work in the transaction." } } It appears that the Prisma client extension is attempting to insert audit log records using the base client (prisma) rather than the transaction client tx.
Author prisma
Answer Overflow
answeroverflow.com › m › 1288515224613425224
Question about interactive transactions - Prisma
September 25, 2024 - 2. Use a Transaction to Create the Playlist Entry: Once the image is successfully uploaded, start a transaction to create the playlist entry and update it with the thumbnail URL. for example: const AWS = require('aws-sdk'); const s3 = new AWS.S3(); async function uploadThumbnailToS3(file, playlistId) { const params = { Bucket: 'your-bucket-name', Key: `thumbnails/${playlistId}.jpg`, Body: file, ContentType: 'image/jpeg' }; return s3.upload(params).promise(); } async function createPlaylistWithThumbnail(prisma, file) { try { // Step 1: Create a new playlist entry to get the playlist ID const ne