backend-queries

使用ORM或原始SQL编写高效、安全的数据库查询,防止N+1问题、SQL注入和性能问题。编写数据库查询、实施数据访问层、创建存储库模式或在服务文件、查询构建器或数据访问对象中优化查询性能时,使用此技能。在使用参数化查询、实现急切加载以避免N+1查询、仅选择所需列、添加WHERE/JOIN/ORDER BY子句,或处理查询优化、索引和数据库性能调整时应用此技能。此技能确保查询使用适当的SQL注入预防,为数据一致性实现事务,适当缓存昂贵的查询,并遵循查询超时、连接池和数据库资源管理的最佳实践。

📖 中文导读:使用ORM或原始SQL编写高效、安全的数据库查询,防止N+1问题、SQL注入和性能问题。编写数据库查询、实施数据访问层、创建存储库模式或在服务文件、查询构建器或数据访问对象中优化查询性能时,使用此技能。在使用参数化查询、实现急切加载以避免N+1查询、仅选择所需列、添加WHERE/JOIN/ORDER BY子句,或处理查询优化、索引和数据库性能调整时应用此技能。此技能确保查询使用适当的SQL注入预防,为数据一致性实现事务,适当缓存昂贵的查询,并遵循查询超时、连接池和数据库资源管理的最佳实践。 以下正文为该技能的原始 SKILL.md 内容(英文),上方安装命令可直接使用。

name: Backend Queries description: Write efficient, secure database queries using ORMs or raw SQL, preventing N+1 problems, SQL injection, and performance issues. Use this skill when writing database queries, implementing data access layers, creating repository patterns, or optimizing query performance in service files, query builders, or data access objects. Apply this skill when using parameterized queries, implementing eager loading to avoid N+1 queries, selecting only needed columns, adding WHERE/JOIN/ORDER BY clauses, or working with query optimization, indexes, and database performance tuning. This skill ensures queries use proper SQL injection prevention, implement transactions for data consistency, cache expensive queries appropriately, and follow best practices for query timeouts, connection pooling, and database resource management.

Backend Queries

This Skill provides Claude Code with specific guidance on how to adhere to coding standards as they relate to how it should handle backend queries.

When to use this skill

  • When writing database queries using ORM methods or query builders
  • When implementing raw SQL queries with proper parameterization
  • When creating repository patterns or data access layers
  • When optimizing queries to prevent N+1 query problems using eager loading
  • When adding JOINs, WHERE clauses, or complex query logic
  • When selecting specific columns instead of using SELECT * for performance
  • When implementing query pagination, filtering, or sorting logic
  • When wrapping related database operations in transactions
  • When adding query timeouts or implementing query performance monitoring
  • When working with query optimization, EXPLAIN plans, or index usage analysis
  • When implementing query caching strategies for expensive or frequent queries
  • When preventing SQL injection through parameterized queries and input validation
  • When working with files like queries.py, repositories/, dao/, or service layer query logic

Instructions

For details, refer to the information provided in this file: backend queries