-- get_author.sqlselect u.id, u.name, count(p.id)::int as post_countfrom users uleft join posts p on p.user_id = u.idwhere u.id = :id::intgroup by u.id
You can import it directly from a TypeScript file like this:
// main.tsimport postgres from "postgres";import getAuthor from "./get_author.sql";const db = postgres(process.env.DATABASE_URL);const author = await getAuthor.run(db, { id: 1 });// { id: number; name: string; post_count: number } | null
Reylo is powered by TypeScript content mappers, introduced in TypeScript 7.1 (currently in beta), which let you dynamically define static types for external file types and integrate them directly into TypeScript compilation.
Reylo is the perfect option for the agent era:
💪 The full power of SQL — any syntax, function or operator your database supports
🌵 DRY — no redundant hand-written types
🎯 Checked against your database — a misspelled column is a type error
🤖 Agent-friendly — DRY code is more maintainable for agents
🧩 Postgres, MySQL, SQLite and DuckDB — Neon, PlanetScale, Cloudflare D1, Turso and more
🔌 Bring your own driver — pg, postgres.js, mysql2, better-sqlite3 and more
⚡ No codegen — no generated files, no watcher
Setup
To install Reylo, you'll need:
TypeScript 7.1 (currently in beta). The first release with content mappers.
Node 24 or later.
A running dev database. Postgres, MySQL 8.0.22 or later, or a SQLite or DuckDB file: Reylo reads your current schema from it.
Install Reylo, which brings its engine for your machine, and TypeScript 7.1:
npm install reylonpm install -D typescript@beta
Add Reylo to tsconfig.json, for .sql files and for its project file, .reylo.yaml or .reylo.yml:
Name each parameter with a colon, and give it a type with a cast where the query doesn't pin one down. Pass .run() your driver's client: a pool, a client, or a connection or transaction taken from one.
It resolves to the rows, shaped by how many the query can return:
The query
Resolves to
A match on a primary or unique key, or limit 1
Row | null
An aggregate without group by, a one-row insert … returning
Row
An insert, update or delete without returning
void
Anything else
Row[]
An imported query also has .runSync(), .try(), .with(), .sql, .raw and .source (Usage). Every query Reylo runs is published on Node's tracing channel reylo:query, for a tracer or a logger to subscribe to (Tracing).
What Reylo infers
To type a query, Reylo has your dev database prepare it, without running it, and reads back the type of every column and parameter. On top of that, it infers:
Nulls — a column is nullable unless its schema, a join or a where test rules null out.
Cardinality — a match on a unique key is one row or null, and an aggregate is exactly one row.
Unions — an enum, or a column whose check constraint lists its values, is a union of them.
JSON — JSON the query builds, and a JSON column with a JSON Schema check, keep their shape.
DuckDB — @duckdb/node-api, which also types DuckDB's statements
Documentation
reylo.dev covers the rest: every plugin and editor, configuration, errors, each database's data types and edge cases, and advanced examples. Agents can read it all as Markdown at reylo.dev/llms.txt.