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: sql
data-modellingtypessqlcorrectness
Cast values in the query rather than coercing strings to numbers in app code
If numeric values arrive as strings, cast them in SQL/select so the app does not pepper code with unary-plus conversions risking NaN.
PR: vinify-backend · org-mining-deep-2026-06Created: Jun 17, 2026
Bad example
Old codetypescript
| 1 | const total = +row.a + +row.b + +row.c; // many + ops, NaN risk |
Explanation (EN)
Objašnjenje (HR)
Good example
New codesql
| 1 | SELECT CAST(a AS DECIMAL) AS a, CAST(b AS DECIMAL) AS b FROM t |
Explanation (EN)
Objašnjenje (HR)