What problem does it solve?
Backend queries often suffer from SQL injection risks, N+1 query problems, and performance bottlenecks due to unparameterized inputs, missing joins, or improper data loading strategies. This skill provides guidelines and best practices to write secure, efficient queries across ORM and raw SQL contexts.
Core Features & Use Cases
- Parameterized queries: Use parameterized statements to prevent SQL injection across ORM and raw SQL.
- Eager loading & joins: Employ joins and eager loading to minimize N+1 queries and fetch related data efficiently.
- Indexing & optimization: Recommend indexing strategies, query plan analysis, caching, and transaction-aware patterns to improve performance.
- Use Case: Example: fetching a user and their related records in a single, well-parameterized query to avoid multiple round-trips.
Quick Start
Refactor a representative query to use parameterized statements and eager loading to prevent injection flaws and N+1 problems.