Skip to content

noDrizzleDbObjectInsideTransaction (JavaScript)

Language JavaScript (and super languages)
biome.json
{
"linter": {
"rules": {
"nursery": {
"noDrizzleDbObjectInsideTransaction": "error"
}
}
}
}

Disallow using a Drizzle ORM instance inside its own transaction callback.

Inside db.transaction(async (tx) => { ... }), queries must use the transaction object tx. Queries made with db run outside the transaction: they aren’t rolled back when the transaction fails, they don’t see its uncommitted changes, and they can wait forever for rows that the transaction has locked.

Use the drizzleObjectName option to specify the variable names that represent Drizzle ORM instances. This option has no default value, and the rule reports nothing until it’s set.

biome.json
{
"linter": {
"rules": {
"nursery": {
"noDrizzleDbObjectInsideTransaction": {
"level": "on",
"options": {
"drizzleObjectName": [
"db"
]
}
}
}
}
}
}
await db.transaction(async (tx) => {
await db.insert(users).values({ name: "John" });
});
code-block.js:2:11 lint/nursery/noDrizzleDbObjectInsideTransaction ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

ℹ db is used inside db.transaction().

1 │ await db.transaction(async (tx) => {
> 2 │ await db.insert(users).values({ name: "John" });
│ ^^
3 │ });
4 │

ℹ Queries made with db run outside the transaction, so they aren't rolled back with it and can deadlock waiting for its locks.

ℹ Use the transaction object passed to the callback instead.

ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

await db.transaction(async (tx) => {
await tx.insert(users).values({ name: "John" });
});