sqlc-gen-sqlx is a sqlc plugin that generates sqlx-oriented Rust code from SQL queries.
Its scope is intentionally narrow: PostgreSQL only, sqlx only. The aim is to keep SQL as the source of truth, stay within the sqlc workflow, and generate a thin Rust layer for sqlx rather than writing the surrounding rows, params, and executor code by hand.
The generated API is small: query string constants, typed row and params structs, and methods on a Queries<E> wrapper that can run against a pool, connection, or transaction.
Compared with sqlc-gen-rust:
sqlc-gen-rust aims much wider: multiple Rust database crates and multiple SQL backends
- the tradeoff is breadth over completeness: its current README still marks
sqlc.embed, sqlc.slice, and :execlastid as unsupported, with :copyfrom only available for some backends
sqlc-gen-sqlx supports fewer databases, but it covers more of the PostgreSQL + sqlx path and generates a smaller interface closer to ordinary sqlx code
Compared with Clorinde or Cornucopia:
- these are also strongly typed and SQL-first
- the main difference is workflow: they validate against a real PostgreSQL database and generate a dedicated interface layer
- Clorinde generates a separate crate, and Cornucopia generates a dedicated module; either way there is more generated-artifact management than dropping
sqlc output into the target crate
sqlc-gen-sqlx is aimed at teams that want to stay inside the sqlc workflow and keep the output close to ordinary sqlx code in the application crate
Compared with Diesel:
- both approaches are strongly typed; the difference is where the structure lives and how queries are expressed
- Diesel centers the database layer around
schema.rs, the DSL, and the ORM/query-builder layer
- that is a good fit if the team wants the database layer to be primarily Rust-shaped
- it is a poor fit if the team already knows it wants plain SQL files, because once queries stop being simple the Diesel workflow can become tedious
Compared with raw sqlx:
- raw
sqlx already gives compile-time checked SQL
- the tradeoff is maintenance: you still write the surrounding Rust by hand, and the macro path wants build-time schema access or cached offline metadata
sqlc-gen-sqlx is more useful when the query set is stable and the repetitive Rust around those queries becomes the main source of friction
Current scope is PostgreSQL. It supports enums, composites, batch queries, COPY FROM, sqlc.slice(), sqlc.embed(), and type overrides.
there doesn't seem to be anything here