name: rust-database
description: "Rust database skill for SQLx/Diesel/SeaORM design, transaction boundaries, migration safety, query performance, and operational reliability."---
Rust Database Skill
Core Question
How do we guarantee data correctness while keeping queries and migrations operationally safe?
Persistence Architecture
Keep repository/data-access layer separate from business logic.
Define explicit transaction boundaries around business invariants.
Choose stack by need:
sqlx: explicit SQL and compile-time query checks.
diesel: typed query builder with strong schema coupling.
sea-orm: async ORM convenience with rapid CRUD iteration.
Transaction and Consistency Rules
Keep transactions short.
Do not perform network calls inside transactions.
Handle deadlock/serialization retries with bounded policy.
Query Performance
Use indexes based on real access patterns.
Detect and remove N+1 query behavior.
Inspect query plans for slow paths.
Migration Safety
Prefer additive migrations for rolling deployments.
Separate destructive changes into phased rollouts.
Verify backward/forward compatibility windows.
Common Pitfalls
Long-lived transactions causing lock contention.
Schema changes incompatible with old app versions.
Inconsistent timezone/nullability handling across layers.
Pool exhaustion under burst traffic.
Review Checklist
Transaction boundaries align with domain invariants.
Retry/timeout policy is explicit for DB operations.
Migrations are safe for rolling deploy.
Query plans and indexes are validated.
Metrics cover pool usage, latency, and error rates.
Verification Commands
cargo check
cargo test
cargo clippy
cargo sqlx prepare
cargo sqlx migrate run
Related Skills
rust-web
rust-cache
rust-observability
Localized Reference
Original Chinese version is preserved in SKILL_ZH.md.
1---2name: rust-database3description: ---4---5---6name: rust-database7description: "Rust database skill for SQLx/Diesel/SeaORM design, transaction boundaries, migration safety, query performance, and operational reliability."---89# Rust Database Skill1011## Core Question1213**How do we guarantee data correctness while keeping queries and migrations operationally safe?**1415## Persistence Architecture1617- Keep repository/data-access layer separate from business logic.18- Define explicit transaction boundaries around business invariants.19- Choose stack by need:20 - `sqlx`: explicit SQL and compile-time query checks.21 - `diesel`: typed query builder with strong schema coupling.22 - `sea-orm`: async ORM convenience with rapid CRUD iteration.2324## Transaction and Consistency Rules2526- Keep transactions short.27- Do not perform network calls inside transactions.28- Handle deadlock/serialization retries with bounded policy.2930## Query Performance3132- Use indexes based on real access patterns.33- Detect and remove N+1 query behavior.34- Inspect query plans for slow paths.3536## Migration Safety3738- Prefer additive migrations for rolling deployments.39- Separate destructive changes into phased rollouts.40- Verify backward/forward compatibility windows.4142## Common Pitfalls4344- Long-lived transactions causing lock contention.45- Schema changes incompatible with old app versions.46- Inconsistent timezone/nullability handling across layers.47- Pool exhaustion under burst traffic.4849## Review Checklist5051- [ ] Transaction boundaries align with domain invariants.52- [ ] Retry/timeout policy is explicit for DB operations.53- [ ] Migrations are safe for rolling deploy.54- [ ] Query plans and indexes are validated.55- [ ] Metrics cover pool usage, latency, and error rates.5657## Verification Commands5859```bash60cargo check61cargo test62cargo clippy63cargo sqlx prepare64cargo sqlx migrate run65```6667## Related Skills6869- `rust-web`70- `rust-cache`71- `rust-observability`7273## Localized Reference7475- Original Chinese version is preserved in `SKILL_ZH.md`.
Run npx skillmds@latest add huiali/rust-database in your terminal (requires Node.js), paste this page's agent-chat prompt into Claude, Cursor, or any MCP-connected agent, or download the SKILL.md file and copy it into your agent's skills directory.
--- It is listed under Coding & Dev Tools on SkillMD.
This skill has not completed SkillMD's automated safety review yet. SkillMD never runs a skill's scripts for you; review the SKILL.md before installing.
This skill is tagged as working with Claude Code, Claude.ai, OpenAI Codex. SKILL.md is an open format, so most agents that read a skills directory can load it too.
Yes. Installing skills from SkillMD is free, and the skill stays under its author's original license.
huiali (@huiali) published this skill. Their other Agent Skills are listed on their SkillMD profile.