Rust-skills rust-database
install
source · Clone the upstream repo
git clone https://github.com/huiali/rust-skills
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/huiali/rust-skills "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/rust-database" ~/.claude/skills/huiali-rust-skills-rust-database-4e470a && rm -rf "$T"
manifest:
skills/rust-database/SKILL.mdsource content
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:
: explicit SQL and compile-time query checks.sqlx
: typed query builder with strong schema coupling.diesel
: async ORM convenience with rapid CRUD iteration.sea-orm
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-webrust-cacherust-observability
Localized Reference
- Original Chinese version is preserved in
.SKILL_ZH.md