AgentSkillsCN

Backend Queries

使用参数化查询、急加载和恰当索引策略编写优化且安全的数据库查询。在编写数据库查询、构造SQL语句、使用ORM查询方法、实现数据获取逻辑、防止SQL注入攻击、优化查询性能、避免N+1查询问题、选择特定列而非全部数据、为相关操作实施事务、设置查询超时、缓存昂贵查询或处理WHERE子句、JOIN和ORDER BY语句时使用。在从数据库获取数据、优化慢查询、重构数据访问代码或审查查询安全性和性能时应用此技能。

SKILL.md
--- frontmatter
name: Backend Queries
description: Write optimized and secure database queries using parameterized queries, eager loading, and proper indexing strategies. Use this skill when writing database queries, constructing SQL statements, using ORM query methods, implementing data fetching logic, preventing SQL injection attacks, optimizing query performance, avoiding N+1 query problems, selecting specific columns instead of all data, implementing transactions for related operations, setting query timeouts, caching expensive queries, or working with WHERE clauses, JOINs, and ORDER BY statements. Apply this skill when fetching data from databases, optimizing slow queries, refactoring data access code, or reviewing query security and performance.

Backend Queries

When to use this skill

  • When writing database queries in any file that interacts with the database
  • When constructing SQL statements or using ORM query builders (Prisma, Sequelize, ActiveRecord, etc.)
  • When preventing SQL injection by using parameterized queries
  • When optimizing queries to avoid N+1 query problems (use eager loading or joins)
  • When selecting only needed columns instead of using SELECT * or fetching all fields
  • When adding indexes to columns used in WHERE, JOIN, or ORDER BY clauses
  • When implementing database transactions for related operations
  • When setting query timeouts to prevent runaway queries
  • When caching results of complex or frequently-run queries
  • When writing JOIN operations to fetch related data efficiently
  • When implementing pagination, filtering, or sorting with query parameters
  • When reviewing query performance and optimization opportunities

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.

Instructions

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