# Optimize Backend Database Queries

Backend query code can create security gaps and slow applications. This skill guides safer query structure, ORM usage, indexing, caching, and transactions.

## Install

```bash
npx skillstore add eis-its/backend-queries
```

## Metadata

- Status: approved
- Slug: eis-its-backend-queries
- Skillstore revision: r1
- Version status: missing
- Tree hash: 1a3fb436e66fcbd419544d91922abcede3530cb78204464d76e2922862b4ecab
- Author: EIS-ITS
- GitHub username: EIS-ITS
- License: MIT
- Repository: https://github.com/EIS-ITS/vss-cli/tree/main/.claude/skills/backend-queries
- Ref: 26421118b848d9f1efc0aa169d8a7a9e7e0a877e
- Supported tools: Claude, Codex, Claude Code
- Audit status: complete
- Agent install advisory: allowed
- Manual install advisory: allowed
- Artifact signature: available
- Audit attestation: unavailable
- Human verification: not\_verified
- Risk factors: filesystem
- Quality score: 78
- Quality tier: bronze
- Public page: https://skillstore.pages.dev/skills/eis-its-backend-queries
- Manifest: https://skillstore.pages.dev/api/skills/eis-its-backend-queries/manifest

## Capabilities

- Guides use of parameterized queries to reduce SQL injection risk.
- Highlights eager loading patterns to avoid N\+1 query problems.
- Recommends filtering, sorting, pagination, and selected column practices.
- Supports review of joins, related data access, and repository methods.
- Suggests index, timeout, caching, and monitoring considerations.
- Promotes transaction handling for related database operations.

## Use Cases

- Review Repository Queries: Check repository methods for parameter safety, selected columns, pagination, and maintainable data access.
- Fix Slow Endpoints: Identify N\+1 loading, missing indexes, expensive joins, and caching opportunities in service queries.
- Design Safe Transactions: Plan transaction boundaries, rollback behavior, timeouts, and error handling for related database changes.

## Prompt Templates

### Improve a Simple Query

```
Review this database query for safe parameters, selected columns, and clear filtering. Explain each change in plain language.
```

### Fix N\+1 Loading

```
Find N+1 query risks in this repository method. Recommend eager loading and pagination changes that match the existing ORM.
```

### Design Transaction Handling

```
Design transaction handling for these related database updates. Include rollback behavior, timeout choices, and error handling boundaries.
```

### Audit Query Layer Performance

```
Audit this service query layer for injection risk, slow joins, missing indexes, caching candidates, and monitoring points.
```

## Limitations

- It provides guidance only and does not execute database queries.
- It needs project schema, ORM, and performance context from the user.
- It does not include the referenced external standards file.
- It cannot verify production performance without logs or metrics.

## Best Practices

- Share the ORM, schema shape, and expected query volume before asking for recommendations.
- Ask for parameterized alternatives when reviewing raw SQL or dynamic filters.
- Validate suggested indexes and caching changes against real workload metrics.

## Anti Patterns

- Do not paste production secrets, credentials, or customer data into prompts.
- Do not ask for broad rewrites without schema, constraints, or performance symptoms.
- Do not accept caching recommendations without freshness and invalidation requirements.

## Security Audit

- Audited at: 2026-07-09T14:09:09.469\+00:00
- Summary: The static filesystem finding is confirmed. SKILL.md directs the agent to follow a ../../../ relative link outside the skill package, which can load unreviewed instructions.

## Stats

- Views: 185
- Downloads: 12
- Favorites: 1
- Popularity score: 0
