GB-Power-Market-JJ sqlx-code-review
Reviews sqlx database code for compile-time query checking, connection pool management, migration patterns, and PostgreSQL-specific usage. Use when reviewing Rust code that uses sqlx, database queries, connection pools, or migrations. Covers offline mode, type mapping, and transaction patterns.
install
source · Clone the upstream repo
git clone https://github.com/GeorgeDoors888/GB-Power-Market-JJ
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/GeorgeDoors888/GB-Power-Market-JJ "$T" && mkdir -p ~/.claude/skills && cp -r "$T/openclaw-skills/skills/anderskev/sqlx-code-review" ~/.claude/skills/georgedoors888-gb-power-market-jj-sqlx-code-review && rm -rf "$T"
OpenClaw · Install into ~/.openclaw/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/GeorgeDoors888/GB-Power-Market-JJ "$T" && mkdir -p ~/.openclaw/skills && cp -r "$T/openclaw-skills/skills/anderskev/sqlx-code-review" ~/.openclaw/skills/georgedoors888-gb-power-market-jj-sqlx-code-review && rm -rf "$T"
manifest:
openclaw-skills/skills/anderskev/sqlx-code-review/SKILL.mdsource content
sqlx Code Review
Review Workflow
- Check Cargo.toml — Note sqlx features (
,runtime-tokio
/tls-rustls
,tls-native-tls
/postgres
/mysql
,sqlite
,uuid
,chrono
,json
)migrate - Check query patterns — Compile-time checked (
,query!
) vs runtime (query_as!
,query
)query_as - Check pool configuration — Connection limits, timeouts, idle settings
- Check migrations — File naming, reversibility, data migration safety
- Check type mappings — Rust types align with SQL column types
Output Format
Report findings as:
[FILE:LINE] ISSUE_TITLE Severity: Critical | Major | Minor | Informational Description of the issue and why it matters.
Quick Reference
| Issue Type | Reference |
|---|---|
| Query macros, bind parameters, result mapping | references/queries.md |
| Migrations, pool config, transaction patterns | references/migrations.md |
Review Checklist
Query Patterns
- Compile-time checked queries (
,query!
) used where possiblequery_as! -
orsqlx.toml
configured for offline compile-time checkingDATABASE_URL - No string interpolation in queries (SQL injection risk) — use bind parameters (
,$1
)$2 -
maps to named structs, not anonymous records, for public APIsquery_as! -
,.fetch_one()
,.fetch_optional()
chosen appropriately.fetch_all() -
(streaming) used for large result sets.fetch()
Connection Pool
-
shared viaPgPool
or framework state (not created per-request)Arc - Pool size configured for the deployment (not left at defaults in production)
- Connection acquisition timeout set
- Idle connection cleanup configured
Transactions
-
used for multi-statement operationspool.begin() - Transaction committed explicitly (not relying on implicit rollback on drop)
- Errors within transactions trigger rollback before propagation
- Nested transactions use savepoints (
) if neededtx.begin()
Type Mapping
-
derives match database column typessqlx::Type - Enum representations consistent between Rust, serde, and SQL
-
,Uuid
,DateTime<Utc>
types used (not strings for structured data)Decimal -
used for nullable columnsOption<T> -
used for JSONB columnsserde_json::Value
Migrations
- Migration files follow naming convention (
)YYYYMMDDHHMMSS_description.sql - Destructive migrations (DROP, ALTER DROP COLUMN) are reversible or have data backup plan
- No data-dependent schema changes in same migration as data changes
-
called at application startupsqlx::migrate!()
Severity Calibration
Critical
- String interpolation in SQL queries (SQL injection)
- Missing transaction for multi-statement writes (partial writes on error)
- Connection pool created per-request (connection exhaustion)
- Missing bind parameter escaping
Major
- Runtime queries (
) where compile-time (query()
) could verify correctnessquery!() - Missing transaction rollback on error paths
- Enum type mismatch between Rust and database
- Unbounded
on potentially large tables.fetch_all()
Minor
- Pool defaults used in production without tuning
- Missing
(using.fetch_optional()
then handling error for "not found").fetch_one() - Overly broad
when only specific columns neededSELECT * - Missing indexes for queried columns (flag only if query pattern is clearly slow)
Informational
- Suggestions to use
for type-safe result mappingquery_as! - Suggestions to add database-level constraints alongside Rust validation
- Migration organization improvements
Valid Patterns (Do NOT Flag)
- Runtime
for dynamic queries — Compile-time checking doesn't work with dynamic SQLquery()
derive — Valid alternative tosqlx::FromRow
for reusable row typesquery_as!
columns for enum storage — Valid withTEXT
derive, simpler than custom SQL typessqlx::Type
ignoring row count — Acceptable for idempotent operations (upserts, deletes).execute()- Shared DB with other languages — e.g., Elixir owns migrations, Rust reads. This is a valid architecture.
Before Submitting Findings
Load and follow
beagle-rust:review-verification-protocol before reporting any issue.