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

More Drizzle ORM tasks

Back to the full Drizzle ORM cheat sheet