AgentSkillsCN

Backend Queries

通过使用参数化查询、急加载、合理索引以及事务,编写安全且高效的数据库查询。在编写数据库查询代码、ORM 查询方法、SQL 语句,或数据获取逻辑时,可运用此技能。利用参数化查询防范 SQL 注入,通过急加载优化查询以避免 N+1 问题,选择特定列而非使用 SELECT *,为相关操作实施数据库事务,添加查询超时机制,或对高开销查询进行缓存。适用于处理仓库文件、包含数据库访问的服务文件、查询构建器代码,以及任何从数据库中检索或操作数据的文件。

SKILL.md
--- frontmatter
name: Backend Queries
description: Write secure, performant database queries using parameterized queries, eager loading, proper indexing, and transactions. Use this skill when writing database query code, ORM query methods, SQL statements, or data fetching logic. Use this when preventing SQL injection with parameterized queries, optimizing queries to avoid N+1 problems with eager loading, selecting specific columns instead of SELECT *, implementing database transactions for related operations, adding query timeouts, or caching expensive queries. Use this when working on repository files, service files with database access, query builder code, or any file that retrieves or manipulates data from databases.

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 query code using ORM methods or query builders
  • When creating repository pattern files that encapsulate data access logic
  • When implementing service layer methods that fetch or manipulate database data
  • When writing raw SQL queries or stored procedure calls
  • When using parameterized queries to prevent SQL injection attacks
  • When implementing eager loading or joins to avoid N+1 query problems
  • When optimizing queries by selecting specific columns instead of using SELECT *
  • When wrapping related database operations in transactions for consistency
  • When adding indexes to columns used in WHERE, JOIN, or ORDER BY clauses
  • When implementing query timeouts to prevent runaway queries
  • When setting up caching strategies for frequently-run or expensive queries

Instructions

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