# Apply Async SQLModel Patterns

SQLModel async projects often fail from lazy loading, schema drift, and session mistakes. This skill gives focused patterns for models, queries, relationships, and ORM debugging.

## Install

```bash
npx skillstore add cjharmath/py-sqlmodel-patterns
```

## Metadata

- Status: approved
- Slug: cjharmath-py-sqlmodel-patterns
- Skillstore revision: r1
- Version status: missing
- Tree hash: 496776b07c4ffa1bac504cac02c713591bd621d60a6854a4319abd4098305a3b
- Author: CJHarmath
- GitHub username: CJHarmath
- License: MIT
- Repository: https://github.com/CJHarmath/claude-agents-skills/tree/main/skills/py-sqlmodel-patterns
- Ref: dd4a3ef9f20ddf38830950b4bb713df96b431fd6
- 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: external\_commands, network, env\_access
- Quality score: 78
- Quality tier: bronze
- Public page: https://skillstore.pages.dev/skills/cjharmath-py-sqlmodel-patterns
- Manifest: https://skillstore.pages.dev/api/skills/cjharmath-py-sqlmodel-patterns/manifest

## Capabilities

- Explains eager loading choices for async SQLAlchemy relationships.
- Shows how to separate database models from API schemas.
- Documents session state behavior around commit and refresh.
- Covers UUID, nullable field, relationship, query, and upsert patterns.
- Lists common ORM errors with likely causes and fixes.
- Provides grep-based checks for lazy loading and missing query options.

## Use Cases

- Review Async ORM Models: Check whether models, relationships, schemas, and nullable fields follow practical SQLModel patterns.
- Diagnose Query Performance: Identify likely N\+1 query risks and choose eager loading strategies for collections and single relationships.
- Standardize API Data Shapes: Create clear create, read, and update schema boundaries that avoid leaking database-only fields.

## Prompt Templates

### Review Model Basics

```
Review my SQLModel model design for async usage. Focus on relationships, schemas, nullable fields, and session behavior. Explain the first changes to make.
```

### Find N\+1 Risks

```
Find likely N+1 query risks in this repository section. Recommend eager loading choices and explain why each choice fits.
```

### Plan Data Access

```
Design a SQLModel data access pattern for this feature. Include session boundaries, pagination behavior, UUID handling, and update semantics.
```

### Debug ORM Failure

```
Debug this async SQLAlchemy failure. Map the error to likely model, relationship, query, or session causes, then propose focused fixes.
```

## Limitations

- It is guidance only and does not inspect a repository by itself.
- Examples focus on SQLModel with async SQLAlchemy and PostgreSQL patterns.
- It does not replace database migration review or production performance testing.
- Detection commands are simple text searches and may miss complex query flows.

## Best Practices

- Use eager loading whenever async code needs relationship data after a query.
- Keep database table models separate from public API schemas.
- Refresh objects after commit when database-generated values are needed.

## Anti Patterns

- Do not rely on lazy relationship access in async SQLAlchemy sessions.
- Do not expose password or internal database fields through read schemas.
- Do not compare UUID columns to raw strings in query filters.

## Security Audit

- Audited at: 2026-07-06T05:02:10.319\+00:00
- Summary: I found no evidence of malicious behavior, prompt injection, data exfiltration, or automatic command execution. The static findings are false positives from Markdown examples, public documentation links, placeholder database configuration, and read-only grep suggestions.

## Stats

- Views: 252
- Downloads: 10
- Favorites: 0
- Popularity score: 0
