| name | sql-best-practices |
| description | Guidance for writing safe, fast SQL/Prisma queries against the TaskFlow Postgres database. Use whenever reading or shaping database queries. |
SQL Best Practices
When writing queries for TaskFlow:
- Read-only by default. Never write destructive SQL unless explicitly asked.
- Always paginate. Add
LIMIT/take to any list query (default 50).
- Index awareness. Filter on indexed columns (
user_id, status, created_at).
If a query needs a non-indexed column, flag that a migration may be required.
- No N+1. Prefer Prisma
include/select over per-row queries.
- Parameterize. Never string-concatenate user input into SQL.
Output format
Return: (1) the exact query, (2) an EXPLAIN-level note on which index is used,
(3) the result summary. Example:
SELECT id, title, status FROM tasks
WHERE user_id = $1 AND status = 'open'
ORDER BY created_at DESC
LIMIT 50;