Do transaction automatically rollback on error?

I was reading the docs about transactions and it is not clear whether the transaction is rolled back when an error is thrown.
Which is:
const db = drizzle(...)

await db.transaction(async (tx) => {
  const [account] = await tx.select({ balance: accounts.balance }).from(accounts).where(eq(users.name, 'Dan'));
  if (account.balance < 100) {
    await tx.rollback()
    // Can I use throw MyCustomError(); here instead of tx.rollback()?
    // Will it also rollback the transaction?
    return
  }

  await tx.update(accounts).set({ balance: sql`${accounts.balance} - 100.00` }).where(eq(users.name, 'Dan'));
  await tx.update(accounts).set({ balance: sql`${accounts.balance} + 100.00` }).where(eq(users.name, 'Andrew'));
});
Was this page helpful?