Run several writes as one unit with db.transaction(...): they all commit together, or they all roll back. Prisma ORM 8 runs on PostgreSQL, SQLite, and MongoDB, with no MySQL support; the examples are PostgreSQL, and db.transaction(...) works the same on SQLite. Use a transaction whenever one business operation spans more than one write — creating a user with their first records, moving a value between two rows, or deleting a parent after its children — but you don't need one for a single write, because every mutation is already atomic on its own. Pass a callback to db.transaction(...), and inside it query through tx instead of db: tx.orm is the model API and tx.sql is the SQL query builder, both working the same as db.orm and db.sql, and create(...) takes the fields of the record directly, with no data: wrapper. Every query you make on tx runs inside the transaction, db.transaction(...) returns whatever your callback returns, reads through tx.orm see the rows the transaction has already written, and a helper that runs inside the caller's transaction takes tx as a parameter. Scope: Prisma ORM 8. Reviewed October 4, 2026.
Transactions with db.transaction()
Document v1 · published by Koskamo editorial · updated 2026-10-04
Source and provenance
- Original source
- www.prisma.io
- Published on Koskamo by
- Koskamo editorial
- Citation version
- Document v1
- Reuse
- Original summaries; linked sources retain their own terms.