Rules Hub
Coding Rules Library
← Back to all rules
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
backend ruleP1universalStack: Node.js
databaseconnectionperformance
Reuse a single database connection, don't reconnect per call
Create the DB connection/pool once and share it, rather than instantiating a new client on each operation or script step. Repeated connections exhaust the connection limit, add latency, and defeat pooling.
PR: profico-org-corpus batch2 (all stacks/products)Created: Jul 26, 2026
Bad example
Old codets
| 1 | export async function seed() { |
| 2 | const db = new Sequelize(config); // new connection every call |
| 3 | await db.query(...); |
| 4 | } |
Explanation (EN)
Each call opens another connection instead of reusing one.
Objašnjenje (HR)
Good example
New codets
| 1 | let connection; |
| 2 | export function init() { connection ??= new Sequelize(config); return connection; } |
| 3 | export async function seed() { await init().query(...); } |
Explanation (EN)
A single shared connection is created once and reused.
Objašnjenje (HR)