home / skills / tlabs-xyz / tbtc-v2-performance / backend-queries
/.claude/skills/backend-queries
This skill helps you write secure, efficient backend queries using parameterized queries, ORM builders, and proper optimization strategies.
npx playbooks add skill tlabs-xyz/tbtc-v2-performance --skill backend-queriesReview the files below or copy the command above to add this skill to your agents.
---
name: Backend Queries
description: Write efficient, secure database queries using parameterized queries, eager loading, and performance optimizations. Use this skill when writing database queries, implementing data retrieval logic, using ORM query builders, writing raw SQL queries, implementing eager loading or joins, preventing N+1 query problems, implementing query filters or search functionality, using transactions for data consistency, implementing pagination queries, optimizing slow queries, implementing query caching, working with query builder methods, or writing repository/DAO layer code. Use when working with SQL queries, ORM query builders like Sequelize, TypeORM, Prisma, SQLAlchemy, ActiveRecord, Django ORM query APIs, or raw database access code.
---
## When to use this skill
- When writing database queries using ORM query builders
- When writing raw SQL queries
- When implementing data retrieval or search logic
- When implementing eager loading or joins to prevent N+1 queries
- When optimizing slow or inefficient queries
- When implementing query filters, sorting, or pagination
- When using transactions to ensure data consistency
- When implementing query caching for expensive queries
- When working with query builder methods (where, select, join, etc.)
- When writing repository, service, or DAO layer code
- When preventing SQL injection with parameterized queries
- When working with complex queries involving multiple tables
- When implementing query timeouts or performance monitoring
- When working with ORMs like Sequelize, TypeORM, Prisma, SQLAlchemy, ActiveRecord, Django ORM
# 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.
## Instructions
For details, refer to the information provided in this file:
[backend queries](../../../agent-os/standards/backend/queries.md)
This skill guides writing efficient, secure database queries and data-access logic in TypeScript backends. It emphasizes parameterized queries, eager loading, transaction safety, and query performance optimizations to reduce latency and prevent common pitfalls like N+1 queries and SQL injection. Use it to standardize repository/DAO code and ORM usage across services.
The skill inspects query intent and suggests concrete query patterns: parameterized SQL, ORM query-builder calls, eager-loading or join strategies, and pagination/caching techniques. It recommends specific performance improvements such as indexing hints, selecting only needed columns, using transactions where required, and applying query timeouts or monitoring. Outputs include code snippets, refactor suggestions, and checklist-style validations tailored to TypeScript ORMs like Prisma, TypeORM, and Sequelize.
Which is better: eager loading or lazy loading?
Prefer eager loading when you know related data is required for the response to avoid N+1 queries. Use lazy loading only when related data is rarely needed to reduce unnecessary joins.
How do I choose pagination style?
Use offset/limit for simple UIs and small datasets. Use cursor-based pagination for large or frequently changing datasets to ensure stable and performant paging.