Reylo

An engine that infers the types of your SQL queries

License: MITnpm version

1.7k

Reylo is a type inference engine for SQL. It lets you import SQL queries into your TypeScript files with full type information.

If you have a query like this:

get_author.sql
-- hover a table to see its declaration
select u.id, u.name, count(p.id)::int as post_count
from  u
left join  p on p.user_id = u.id
where u.id = :id::int
group by u.id

You can import it like this. Hover over author to see the inferred type!

main.ts
import  from "postgres";
import  from "./get_author.sql";

const  = (..);
const  = await .(, { : 1 });

Reylo infers type information about both the parameters and the return types. Throughout the docs, you will see "inference cards" like this where you can quickly see both a query and its inferred type information.

Query
select id, name, email from  where id = :id::int
Params
{ id: number }
Returns
{ id: number; name: string; email: string | null } | null
Query
select id, name, email from  where id = :id::int
Params
{ id: number }
Returns
{ id: number; name: string; email: string | null } | null
Query
select id, name, email from  where id = :id::int
Params
{ id: number }
Returns
{ id: number; name: string; email: string | null } | null

Reylo gets type information about a query by sending it to a live dev database and getting back the database's own type descriptors. It then maps these to TypeScript types.

How Reylo types a .sql import. TypeScript 7.1 hands the .sql file to Reylo, its content mapper. Reylo has your database (Postgres, MySQL or SQLite) prepare the statement without running it, reads the catalog, and gives TypeScript the types of its parameters and result.TypeScript 7.1tsc and the editorReylocontent mapperyour databasePostgres, MySQL or SQLitea .sql fileits typesprepare, not runcatalog

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 compile error
  • 🤖 Agent-friendly — DRY code is more maintainable for agents
  • 🧩 Postgres, MySQL and SQLite — Neon, PlanetScale, Cloudflare D1, Turso and more
  • 🔌 Your own driver — pg, postgres.js, mysql2, better-sqlite3 and more in TypeScript