Does Prisma consider a transaction as one operation?

await prisma.$transaction (async (tx) => {
await tx.user.create(...);
await tx.password.create(...);
});
await prisma.$transaction (async (tx) => {
await tx.user.create(...);
await tx.password.create(...);
});
Is this one or two operations accoridng to Prisma for billing purposes?
1 Reply
Prisma AI Help
You selected the bot's instantaneous insights. Let me compile your answer right away! In Prisma, when you use an interactive transaction like this:
await prisma.$transaction(async (tx) => {
await tx.user.create(...);
await tx.password.create(...);
});
await prisma.$transaction(async (tx) => {
await tx.user.create(...);
await tx.password.create(...);
});
each query inside the interactive transaction is counted separately for billing purposes. So, in your example, this would count as two operations—one for the user creation and one for the password creation. The transaction itself (start, commit, rollback) is not billed, only the individual queries inside it are. If you want the transaction to count as a single operation for billing, you would need to use the sequential operations form:
await prisma.$transaction([
prisma.user.create(...),
prisma.password.create(...),
]);
await prisma.$transaction([
prisma.user.create(...),
prisma.password.create(...),
]);
This array-based form counts as one billable query regardless of the number of operations inside the array. Interactive transactions, on the other hand, bill each query separately Are each of the queries within an interactive transaction counted separately for billing?. ✅ Great, thanks for letting us know that this solved your question!

Did you find this page helpful?