Schema#
CREATE TABLE users (
id SERIAL PRIMARY KEY,
name TEXT NOT NULL,
email TEXT NOT NULL,
created_at TIMESTAMPTZ NOT NULL DEFAULT now()
);
CREATE TABLE orders (
id SERIAL PRIMARY KEY,
user_id INTEGER NOT NULL REFERENCES users(id),
total NUMERIC NOT NULL,
status TEXT NOT NULL DEFAULT 'pending',
created_at TIMESTAMPTZ NOT NULL DEFAULT now()
);Queries#
Five operations cover the core CRUD surface plus one join:
-- @name GetUser
-- @returns :one
SELECT * FROM users WHERE id = $1;
-- @name CreateUser
-- @returns :one
INSERT INTO users (name, email) VALUES ($1, $2) RETURNING *;
-- @name UpdateUserEmail
-- @returns :exec
UPDATE users SET email = $2 WHERE id = $1;
-- @name DeleteUser
-- @returns :exec
DELETE FROM users WHERE id = $1;
-- @name ListOrdersByUser
-- @returns :many
SELECT o.id, o.total, o.status, u.name AS user_name
FROM orders o
JOIN users u ON u.id = o.user_id
WHERE o.user_id = $1;Generated code, per language#
Rust (rust-sqlx) — functions use async/await with sqlx macros and return Result types; row structs derive sqlx::FromRow.
Python (python-asyncpg) — dataclasses handle row mapping with frozen slots. Parameters are keyword-only (the trailing *,), and :one queries return Row | None.
Go (go-pgx) — fields and parameters are PascalCase (Id, not ID), and the connection type is *pgxpool.Pool.
TypeScript (typescript-postgres, using the postgres driver) — fields are snake_case (created_at, not createdAt), the connection type is Sql imported from postgres, and :one queries return Promise<Row | null>.
Each backend's naming convention (PascalCase fields in Go, snake_case in this TypeScript driver) comes from that backend's manifest, not from a global setting — see field_case if you want to override it for the backends that support it.
Try it yourself#
Drop this schema and these queries into your own sql/ directory, point a scythe.toml at them with the backend of your choice, and run:
scythe generate
scythe checkRelated#
- Quickstart — the same generate/check/lint flow, one schema at a time.
- Backend Overview — every other language and driver combination available.