noDrizzleDbObjectInsideTransaction (JavaScript)
Language JavaScript (and super languages)
Summary
Section titled “Summary”- Rule available since:
v2.6.8 - Diagnostic Category:
lint/nursery/noDrizzleDbObjectInsideTransaction - This rule doesn’t have a fix.
- The default severity of this rule is information.
- This rule belongs to the following domains:
How to configure
Section titled “How to configure”{ "linter": { "rules": { "nursery": { "noDrizzleDbObjectInsideTransaction": "error" } } }}Description
Section titled “Description”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.
Options
Section titled “Options”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.
{ "linter": { "rules": { "nursery": { "noDrizzleDbObjectInsideTransaction": { "level": "on", "options": { "drizzleObjectName": [ "db" ] } } } } }}Examples
Section titled “Examples”Invalid
Section titled “Invalid”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" });});Related links
Section titled “Related links”Copyright (c) 2023-present Biome Developers and Contributors.