@boring-stack-pkg/eslint-plugin-db-transactions
v0.1.2
Published
ESLint rules enforcing transactional correctness in Drizzle / any ORM with `db.transaction(...)`-style APIs.
Downloads
1,083
Maintainers
Readme
eslint-plugin-db-transactions
ESLint rules enforcing transactional correctness in Drizzle (or any ORM
with db.transaction(async (tx) => ...) APIs):
multi-write-must-be-transactional— two or more DB writes in the same function must run inside a single transaction. Catches the partial-failure split-brain that comes from ad-hoc multi-write service methods.transaction-uses-tx-not-db— inside a transaction callback, write calls must use thetxhandle, not the outerdb. Catches the classic transaction-leak bug where a write runs on the outer connection and silently bypasses rollback.
Install
pnpm add -D @boring-stack-pkg/eslint-plugin-db-transactionsPeer deps: eslint >= 8.57, @typescript-eslint/parser >= 8,
typescript >= 5.
Use (flat config)
import tsParser from "@typescript-eslint/parser";
import dbTransactions from "@boring-stack-pkg/eslint-plugin-db-transactions";
export default [
{
files: ["**/*.{ts,tsx}"],
languageOptions: { parser: tsParser },
plugins: { "db-transactions": dbTransactions },
rules: {
"db-transactions/multi-write-must-be-transactional": "error",
"db-transactions/transaction-uses-tx-not-db": "error",
},
},
];Or use the bundled config:
import dbTransactions from "@boring-stack-pkg/eslint-plugin-db-transactions";
export default [dbTransactions.configs.recommended];Notes
The "split across two adjacent transactions" warning in
multi-write-must-be-transactional reflects the most common refactor
bug — when splitting a service method, you separate writes that must
roll back together. If your project genuinely uses multiple small
transactions per function, raise thresholdWrites or remove the
relevant methods from writeMethods.
Rules
| Rule | Description | Fixable |
| -------------------------------------------------------------------------------------- | ---------------------------------------------------------------------- | ------- |
| multi-write-must-be-transactional | Multi-step writes in one function must run inside a single transaction | – |
| transaction-uses-tx-not-db | Inside a transaction, write calls must use tx, not the outer db | – |
License
MIT.
