Basic Transaction in Drizzle ORM

From the Drizzle ORM cheat sheet · Transactions · verified Jul 2026

Basic Transaction

Wrap multiple queries in an ACID transaction that auto-rolls back on error.

typescript
const result = await db.transaction(async (tx) => {
  const [user] = await tx.insert(users).values({
    name: 'Alice',
    email: 'alice@example.com',
  }).returning();

  await tx.insert(profiles).values({
    userId: user.id,
    bio: 'Hello world',
  });

  return user;
});
💡 Use tx instead of db inside transactions
⚡ Throwing an error auto-triggers rollback
📌 tx.rollback() for manual abort when needed
🟢 Transaction return value becomes result
transactionrollbackatomic

Continue with Drizzle ORM

Save the full cheat sheet or work through every related task.

More Drizzle ORM tasks

Back to the full Drizzle ORM cheat sheet