# Optimize Backend Database Queries

Backend query code often becomes slow, unsafe, or hard to maintain. This skill guides Claude, Codex, and Claude Code toward safer parameters, eager loading, indexes, caching, and transactions.

## Install

```bash
npx skillstore add devanb/backend-queries
```

## Metadata

- Status: approved
- Slug: devanb-backend-queries
- Skillstore revision: r1
- Version status: missing
- Tree hash: eabf2a96c81e2a110b9a2faf341ccbea96854d3b6d88cfc31ef4790e8edc0415
- Author: DevanB
- GitHub username: DevanB
- License: MIT
- Repository: https://github.com/DevanB/lucidlog/tree/master/.claude/skills/backend-queries
- Ref: 0519034dad657fb1f7706e0550e962beeda73fdf
- 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: 79
- Quality tier: bronze
- Public page: https://skillstore.pages.dev/skills/devanb-backend-queries
- Manifest: https://skillstore.pages.dev/api/skills/devanb-backend-queries/manifest

## Capabilities

- Guides use of parameterized queries for raw SQL and query builders.
- Prompts eager loading to reduce N\+1 query problems.
- Encourages selecting needed columns instead of broad SELECT usage.
- Supports filtering, sorting, pagination, joins, subqueries, and aggregations.
- Covers database indexes, query caching, query timeouts, and transaction boundaries.

## Use Cases

- Secure Repository Queries: Create repository methods that use parameterized filters and avoid unsafe raw SQL handling.
- Reduce Slow ORM Access: Review controllers and services for N\+1 query patterns and missing eager loading.
- Plan Query Performance Work: Identify useful indexes, timeouts, caching points, and pagination boundaries before implementation.

## Prompt Templates

### Review a Query

```
Review this backend query for security, performance, and maintainability. Check parameters, selected columns, eager loading, and pagination.
```

### Fix N Plus One Access

```
Find N+1 query risks in this code path. Recommend eager loading or query restructuring that preserves the existing response shape.
```

### Design Filtering and Pagination

```
Design safe filtering, sorting, and pagination for this endpoint. Include validation rules, parameterized query patterns, and index considerations.
```

### Optimize a Transactional Workflow

```
Review this multi-step database workflow. Propose transaction boundaries, timeout handling, cache invalidation, and query optimizations.
```

## Limitations

- Depends on an external parent-directory standards file for full instructions.
- Does not include database-specific syntax examples in the packaged file.
- Does not run benchmarks, migrations, or automated query analysis.
- Requires project context to choose exact indexes or transaction scope.

## Best Practices

- Provide the relevant model, table, endpoint, and expected data volume.
- Ask for both security and performance review when raw SQL is present.
- Confirm suggested indexes and cache rules against real query plans.

## Anti Patterns

- Do not paste secrets, credentials, or production connection strings.
- Do not request broad rewrites without sharing current query behavior.
- Do not accept index suggestions without checking write impact and storage cost.

## Security Audit

- Audited at: 2026-07-09T12:41:41.004\+00:00
- Summary: The skill provides database query guidance but delegates key instructions to a parent-directory Markdown path. That out-of-package reference is a real filesystem boundary risk for marketplace distribution.

## Stats

- Views: 233
- Downloads: 8
- Favorites: 0
- Popularity score: 0
