Rules Hub
Code Ruleset
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
Do not open a transaction for a single statement
A single INSERT/UPDATE/DELETE is already atomic; wrapping one statement in an explicit transaction adds overhead and noise without any consistency benefit.
Bad example
| 1 | await db.transaction(async tx => { |
| 2 | await repo.update(values, { where: { id }, transaction: tx }); |
| 3 | }); |
Explanation (EN)
A truly standalone atomic statement may not need an extra explicit transaction wrapper.
Objašnjenje (HR)
Good example
| 1 | await repo.update(values, { where: { id } }); |
Explanation (EN)
Objašnjenje (HR)
Notes (EN)
Remove an explicit wrapper only when the actual database operation is one atomic statement and no isolation level, session-local settings, row locks, hooks or surrounding unit of work depend on it.
Exceptions / Tradeoffs (EN)
An ORM method can emit several statements. A single statement can participate in a larger transaction and must use its transaction-scoped connection.