sqlx-query-safety-review

Review Rust SQLx database code for injection, binding, decoding, and cardinality defects.

2|Updated May 6, 2026
One-click install
npx skills add https://github.com/bpcakes/jig-skills --skill sqlx-query-safety-review-bpcakes
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: sqlx-query-safety-review
Source: https://github.com/bpcakes/jig-skills/tree/main/plugins/jig-rust/skills/sqlx-query-safety-review
Command: npx skills add https://github.com/bpcakes/jig-skills --skill sqlx-query-safety-review-bpcakes

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Rust database access code can hide SQL injection paths, query/schema mismatches, incorrect nullability handling, wrong fetch cardinality, N+1 query patterns, and database rows leaking into public API responses. This Skill provides a structured review workflow that traces concrete consequences before reporting findings, so reviews stay precise and actionable. ## Core Features & Use Cases - SQLx-first review workflow: Inspects query macros, runtime query APIs, parameter binding, result decoding, fetch semantics, and rows_affected handling with severity-ranked findings. - Fallback database stacks: Applies equivalent rules for Diesel, SeaORM, and raw drivers (tokio-postgres, rusqlite, mysql) when SQLx is not the active stack. - DTO boundary checks: Detects database row types (FromRow, *Row, *Record) leaking into HTTP/GraphQL response DTOs with sensitive fields. - Use Case: A reviewer runs the skill on a pull request touching repository code and receives line-specific findings such as an interpolated ORDER BY clause, a fetch_one on a non-unique predicate, or an unbounded fetch_all behind a public endpoint, each with a concrete safer rewrite. ## Quick Start Ask the agent to review your current Rust working changes for SQLx query safety issues and report findings with file locations without editing code.

Frequently Asked Questions about sqlx-query-safety-review

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I review Rust SQLx queries for SQL injection?

Trace every value reaching SQL text and confirm user input never alters SQL structure. Values must use bind parameters like $1 or QueryBuilder push_bind, while dynamic structure such as sort columns must come from allow-listed enums, never format! interpolation.

Should I always use SQLx compile-time checked macros?

No. Runtime APIs like sqlx::query are legitimate for static and dynamic SQL when schema, binding, and caller contracts are correct. Macro adoption is an optional improvement; report only demonstrated mismatches that query checking would have prevented.

Does this review support Diesel or SeaORM instead of SQLx?

Yes. When the reviewed code uses Diesel, SeaORM, or raw drivers like tokio-postgres or rusqlite, the skill applies equivalent injection, binding, cardinality, and DTO-boundary rules from its fallback reference without recommending SQLx macros.

When is fetch_one versus fetch_optional correct in SQLx?

Use fetch_one only when exactly one row is guaranteed by a unique predicate, aggregate, or LIMIT 1. Use fetch_optional for zero-or-one lookups, but the query must still guarantee at most one meaningful row, with ORDER BY when selecting a first or latest row.

Why is returning a sqlx::FromRow struct as a JSON response risky?

A database row type returned directly as an API DTO can expose internal fields like password hashes, tenant IDs, or soft-delete markers. The review flags this unless the projection is a deliberate public contract, and recommends an explicit mapping to a separate response type.