rust-database
Skill1 starsChanged 5 days agoMITView on GitHub
Design, implement, migrate, test, and operate Rust database access, including SQLx, Diesel, SeaORM, schema evolution, transaction boundaries, connection pools, retries, type mapping, concurrency control, and real-database verification. Use when users ask about Rust SQL or ORM code, migrations, transactions, PostgreSQL or MySQL integration, connection pools, query safety, or database production readiness.
5 other projects use a version of this, 1 of them edited.
Adopted by
Most recently taken up by
- po4yka/rust-skillstheir own version, first seen Nov 2, 2026
- adxptived/Rust-Skillstheir own version, first seen Oct 17, 2026
- full-stack-skills/rust-skillsedited, first seen Oct 15, 2026
- dawidpereira/rust-skillstheir own version, first seen Mar 22, 2026
- huiali/rust-skillstheir own version, first seen Feb 9, 2026
Used with
Projects with it also use rust-macros.
Other files people use alongside this one.
Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
dawidpereiraSkillrust-macros
Rust macros — macro_rules!, proc macros, derive macros, attribute macros, fragment specifiers, repetition, hygiene, cargo expand, when to use macros vs generics. Use when writing or debugging declarative or procedural macros, choosing between macros and other abstractions, understanding expansion errors, or generating repetitive code.
Also in 3 projects that use this
Other versions5 projects use a version of this.
Word for word · 0
None found.
Edited · 1
- full-stack-skills/rust-skills★ 899% same
Wrote their own version · 4
- huiali/rust-skills★ 47same name
- po4yka/rust-skills★ 7same name
- adxptived/Rust-Skills★ 1same name
- dawidpereira/rust-skills★ 0same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository16 other files it gives its agents.
- accessibilitySkill
- cargo-fuzzSkill
- core-web-vitalsSkill
- impeccableSkill
- property-based-testingSkill
- rust-best-practicesSkill
- rust-cargo-buildSkill
- rust-cliSkill
- rust-concurrencySkill
- rust-http-clientSkill
- rust-performanceSkill
- rust-testingSkill
- rust-web-securitySkill
- rust-webSkill
- sonjoo-auditSkill
- sonjoo-auditSkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
14 rules. 0 are common, 14 are distinctive, and 0 are very specific to this project.
0
Common
Most of the 5 edited versions we read keep these.
14
Distinctive
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 24
Document credential sources, TLS configurations, tenant boundaries, row-level permissions, and audit requirements.
- Distinctive: line 27
When real database access is unavailable, distinguish between "code/offline metadata validation" and "real dialect validation." Do not …
- Distinctive: line 41
Avoid rewriting solely based on preference among SQLx, Diesel, or SeaORM.
- Distinctive: line 70
Ensure atomic success of writes within a single shared transaction and connection set.
- Distinctive: line 71
Avoid unbounded user interactions outside the transaction scope, including unnecessary external HTTP waits inside transactions.
- Distinctive: line 74
Commit failures are possible.
- Distinctive: line 90
Avoid N+1 queries. Validate performance under realistic data scales when pre-fetching joins or batching is required.
- Distinctive: line 99
Verify repository success, missing records, constraint conflicts, and type boundaries.
- Distinctive: line 100
Test transaction commits, rollbacks, commit failures, and retryable concurrency issues.
- Distinctive: line 101
Ensure invariants hold under concurrent writes.
- Distinctive: line 104
Verify logs, metrics, and traces do not leak bound values or credentials.
- Distinctive: line 106
Test execution and operation lists are provided in Testing and Operations.
- Distinctive: line 116
Run repository-specific migration validation, SQLx offline metadata checks, Diesel schema audits, or real database integration tests.
- Distinctive: line 120
All queries use parameterization with dynamic identifiers filtered via allowlists.
“Common” is measured: kept by at least 6 in 10 of the 5 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Rust Database Layer Delivery
Deliver a migration-compatible, rollback-capable, and observable data access layer based on the actual dialects, schemas, and transaction semantics of databases. Do not treat HTTP handlers as repositories; do not use mocks to validate real database behavior.
Confirming Database Contracts
Before modifications:
- Collect information about the database product, exact version, extensions, deployment topology, read/write nodes;
- Gather current schema constraints, indexes, triggers, views, and migration history;
- Identify locked versions of SQLx, Diesel, SeaORM (or other access stacks) along with their features;
- Determine Rust toolchain/MSRV, synchronous or asynchronous execution models;
- Establish connection limits, instance counts, timeouts, transaction isolation levels, and consistency requirements;
- Define data volume profiles, hot query patterns, pagination strategies, retention policies, and archival needs;
- Document credential sources, TLS configurations, tenant boundaries, row-level permissions, and audit requirements;
- Clarify whether deployments allow downtime, double writes, backfills, or destructive DDL operations.
When real database access is unavailable, distinguish between "code/offline metadata validation" and "real dialect validation." Do not conflate these two approaches in reporting.
Workflow
1. Establish Current Baseline
rustc --version --verbose
cargo metadata --format-version 1
cargo tree -e features
cargo test --all-targetsLocate connection initialization, pool configuration, repository implementations, queries, migrations, test fixtures, and CI database connections. Execute existing migration status/check commands; do not run operations that modify shared databases without explicit authorization.
2. Preserve Existing Access Stacks
Avoid rewriting solely based on preference among SQLx, Diesel, or SeaORM. Select the appropriate stack according to current codebase and task requirements:
- SQLx: Requires direct SQL access, asynchronous querying, and optional compile-time query validation;
- Diesel: Utilizes typed DSL queries, synchronous connections, or existing Diesel schemas;
- SeaORM: Leverages async ORM/entity models with corresponding migration systems;
- Native database drivers: Reserved for cases where protocol or functionality does not support a generic layer, though expanding maintenance and security review scope.
Specific selection criteria and type boundaries are documented in Access Stack and Types. All APIs must align with the versioned documentation from Cargo.lock, avoiding direct application of latest examples to legacy projects.
3. Let Schema Constraints Enforce Facts
- Define primary keys, uniqueness constraints, foreign keys, non-null checks, and check constraints as immutable invariants guaranteed by the database;
- Rust types express domain semantics but cannot replace cross-process concurrency guarantees provided by databases;
- Explicitly specify integer widths, decimal precision, timezones, UUIDs, JSON formats, nullability mappings;
- Bind parameters to all queries. Use dynamic identifiers or sort fields only via allowlists and type mapping—not as regular bind values pretending to be safe;
- Restrict column selection to necessary columns to avoid reliance on unstable
SELECT *layouts; - Prioritize stable sorting strategies and keyset-based pagination over unbounded offset operations under high data volumes.
4. Design Migrations Before Code Changes
For each schema change, document:
- Forward DDL statements;
- Compatibility windows between old and new versions for applications;
- Data backfill methods, batch sizes, and rollback points;
- Index construction risks and lock contention implications;
- Rollback or forward recovery strategies;
- Validation queries, monitoring metrics, and termination conditions.
Adopt the sequence: expand → backfill → switch → contract. Destructive operations—column deletion, type changes, large table reconstruction, data clearing, irreversible backfills—require explicit target parsing and authorization details found in Migrations and Schema Evolution.
5. Place Transactions Within Complete Use Cases
- Initiate transactions via application services or repository unit-of-work units; do not commit transactionally across HTTP handlers indiscriminately;
- Ensure atomic success of writes within a single shared transaction and connection set;
- Avoid unbounded user interactions outside the transaction scope, including unnecessary external HTTP waits inside transactions;
- Select isolation levels per database documentation to identify risks such as lost updates, write skew, phantom reads;
- Retry only transient errors explicitly identified by the database. Set retry counts, backoff strategies, and idempotency boundaries;
- Commit failures are possible; do not treat "last SQL statement success" as transactional completion;
- Drop/rollback serves as a safety net but does not replace explicit control flow design or testing practices.
Connection pooling, isolation levels, and retry mechanisms are detailed in Transactions and Pooling.
6. Design Stable Data Access Interfaces
application use case
-> repository / unit of work port
-> SQL/ORM adapter
-> database- Repository methods should accept domain parameters and results without leaking Web DTOs;
- Classify errors into categories: not found, uniqueness conflicts, foreign key violations, serialization failures, timeouts, unavailability;
- Preserve full error chains for logging and diagnostics while preventing sensitive SQL parameter exposure in user responses;
- Batch interfaces must define ordering semantics, partial failure handling, idempotency guarantees, and return row counts;
- Avoid N+1 queries. Validate performance under realistic data scales when pre-fetching joins or batching is required.
7. Configure Limited Connection Budgets
Validate total connection budgets using the formula: (per-instance pool limit × maximum instance count) + operational connections. Set acquire, connect, statement, and transaction timeouts; define idle/max lifetimes, health checks, and graceful shutdown procedures. Do not instantiate a new pool per request nor let indefinite waits mask resource exhaustion issues.
8. Validate with Real Engines
Conduct at least the following validations:
- Execute all migrations from an empty database;
- Upgrade schema versions supported by existing databases;
- Verify repository success, missing records, constraint conflicts, and type boundaries;
- Test transaction commits, rollbacks, commit failures, and retryable concurrency issues;
- Ensure invariants hold under concurrent writes;
- Confirm query plans, index hits, and representative data volumes;
- Assess pool exhaustion scenarios, database restarts/disconnections, and graceful shutdown behaviors;
- Verify logs, metrics, and traces do not leak bound values or credentials.
Test execution and operation lists are provided in Testing and Operations.
Common Gates (Gateways)
cargo fmt --all -- --check
cargo check --all-targets
cargo test --all-targets
cargo clippy --all-targets -- -D warningsRun repository-specific migration validation, SQLx offline metadata checks, Diesel schema audits, or real database integration tests. Commands and features may vary by version; consult project configuration first.
Completion Criteria
- Database versions, schemas, access stacks, and consistency assumptions are clearly defined;
- All queries use parameterization with dynamic identifiers filtered via allowlists;
- Migration compatibility windows, backfill strategies, recovery procedures, and destructive boundaries are documented;
- Transaction coverage spans complete use cases with justified connection budgets and timeouts;
- Real database testing validates migrations, constraints, rollbacks, and concurrency risks;
- fmt, check, test, Clippy pass; unvalidated real-database tests must be explicitly marked.
Handoff Boundaries
| Primary Responsibility | Assigned To |
| HTTP routing, handlers, status codes, middleware | rust-web |
| Credentials, tenant authorization, audit logs, sensitive field exposure | rust-web-security |
| Async cancellation, locks, tasks, blocking isolation | rust-concurrency |
| Test layering, coverage metrics, performance baselines | rust-testing |
| Features, build scripts, offline metadata, release pipelines | rust-cargo-build |
| Types, ownership semantics, error traits, standard library behavior | rust-best-practices |
On-Demand Resources
- Access Stack and Types: Consult when selecting or adapting SQLx, Diesel, SeaORM, or type mappings.
- Migrations and Schema Evolution: Review DDL design, compatibility backfills, and recovery strategies.
- Transactions and Pooling: Refer for atomicity guarantees, isolation levels, retry logic, and capacity management.
- Testing and Operations: Access real-database test setups, query plans, observability practices.
- Scenario Examples: Use this template when end-to-end task decomposition is required.
examples/golden-transaction/: Offline compilation and validation of transaction boundary examples available here.
References
std::error(Rust Standard Library)- SQLx documentation
- Diesel guides
- SeaORM documentation
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

