Database Transactions
Atomic database operations with Prisma including interactive transactions, batch operations, optimistic locking, error handling, and nested transaction patterns.
What's Included#
- Interactive transactions with business logic (e.g., credit transfers with balance checks)
- Sequential operations with inventory validation and order creation
- Transaction options (maxWait, timeout, isolation level)
- Batch update operations using $transaction arrays
- Optimistic locking with version checking
- Nested transactions using shared TransactionClient
- Error handling wrapper with Prisma error code mapping (P2002, P2003, P2025)
Usage#
Via CLI#
Loading code block...
Via AI Assistant#
Ask your AI assistant:
- "Use the database transactions pattern from Bootspring"
- "Apply the Bootspring transactions pattern to my project"
Key Considerations#
- Keep transactions as short as possible since long transactions block other operations
- Always catch and handle transaction failures with specific Prisma error codes
- Choose the appropriate isolation level based on consistency vs performance needs
- Avoid external API calls inside transactions; keep them database-only
- Test rollback scenarios to ensure failed transactions clean up properly
Related Patterns#
- Prisma - Prisma setup and basics
- Soft Delete - Soft delete with transactions
- Pooling - Connection management