Transactions
Transactions are explicit in tsql.
Manual transaction
const tx = await db.begin();
try {
await tx
.insert("users")
.values({
email: "alice@example.com",
name: "Alice",
createdAt: new Date("2026-01-01T00:00:00.000Z"),
})
.execute();
await tx.commit();
} catch (error) {
await tx.rollback();
throw error;
}
await using pattern
await using tx = await db.begin();
await tx.insert("users").values({
email: "alice@example.com",
name: "Alice",
createdAt: new Date("2026-01-01T00:00:00.000Z"),
}).execute();
await tx.commit();
If scope exits without commit(), transaction auto-rolls back.
Behavior guarantees
- Committed/rolled-back transactions cannot be reused.
rollback()aftercommit()is a no-op.- Nested transactions are not supported (
tx.begin()throws). - Running
migrate()inside a transaction is not supported.