rok-db-codegen
rok-db-gen turns .sql files into a Rust crate for rok-db:
- models and enums from
CREATE TABLE/CREATE TYPE; - typed async functions from sqlc-style annotated queries;
- migrations computed from schema changes.
-- db/user.sql
(
id BIGSERIAL PRIMARY KEY,
email TEXT NOT NULL UNIQUE,
name TEXT
);
-- name: find_by_email :one
SELECT * FROM users WHERE email = $1;
becomes db-gen/src/user.rs, with this usage:
up.await?; // migrations
let user: = find_by_email.await?;
let named = filter.all.await?;
Query types are checked by PostgreSQL. Set DATABASE_URL when queries change: a temporary
database is created and dropped, and the results are cached in db-gen/queries.json.
See the design and full reference and the example project.
License: MIT OR Apache-2.0.