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 ruleP1stack specificStack: sql
databaseperformanceorm
Use exists() rather than count() > 0 for existence checks
When you only need to know whether any matching row exists, use an exists/limit-1 query instead of counting all matches, which scans more rows than necessary.
PR: hegnar-user-ws · org-mining-2026-06Created: Jun 17, 2026
Bad example
Old codetypescript
| 1 | const count = await repo.count({ where: { portfolioId } }); |
| 2 | return count > 0; |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetypescript
| 1 | return repo.exists({ where: { portfolioId } }); |
Explanation (EN)
Objašnjenje (HR)