A SQL compiler that reads your SQL queries and generates type-safe Go, Kotlin, Python and TypeScript code for them.
colinhacks/reylo
Import .sql files into TypeScript with full type inference, checked against your dev database, with no code generation step.
- Stars
- 1,536
- Forks
- 17
- Open issues
- 20
- Last commit
- 3 hours ago
What is it?
Reylo lets you import a SQL query from a .sql file into TypeScript and call it like a function. Types for the result rows and parameters are derived from the SQL itself by preparing the query against your development database, so there are no hand-written row types and no generated files to keep in sync.
Because the type checker queries Reylo directly, a misspelled column, a wrong parameter or a dropped table shows up as a type error in tsc and in the editor. Reylo infers nullability, whether a query returns one row, zero or one row, or many, and unions from enums or check constraints. It supports Postgres, MySQL and SQLite, and works with drivers such as pg, postgres.js, mysql2, better-sqlite3 and Bun.sql. It relies on TypeScript 7.1 content mappers, which are currently in beta.
Key features
- 01Imports .sql files as typed, callable query functions.
- 02Derives row and parameter types from the SQL against a dev database.
- 03Reports SQL mistakes as TypeScript errors in tsc and the editor.
- 04Infers nullability, cardinality and enum unions.
- 05Works with Postgres, MySQL and SQLite and bring-your-own driver.
Use cases
- Keeping TypeScript row types in sync with a changing database schema.
- Writing hand-tuned SQL while keeping type safety without an ORM.
- Letting coding agents change queries with the type checker catching stale callers.
Quick start
- 1
Install Reylo
npm install reylo - 2
Install the engine for your database (Postgres, MySQL or SQLite)
npm install -D @reylosql/postgres - 3
Set DATABASE_URL in .env to point at your dev database
- 4
Run your code with Reylo loaded on Node
node --env-file=.env --import reylo/register main.ts
Things to know
- Requires TypeScript 7.1, which is currently in beta.
- Requires Node 24 or later and a running dev database.
- Type checking needs the --runExternalCode flag so tsc can run content mappers.
Featured in Repolode Weekly
- Issue #2 · A Rust headless browser for agents, and typed .sql imports
Import .sql files in TypeScript and get typed, callable query functions. Row and parameter types are derived against your dev database, SQL mistakes show up as tsc errors, and there is no codegen step.
In collections
Topics
FAQ
- What is reylo?
- Import .sql files into TypeScript with full type inference, checked against your dev database, with no code generation step. Reylo lets you import a SQL query from a .sql file into TypeScript and call it like a function. Types for the result rows and parameters are derived from the SQL itself by preparing the query against your development database, so there are no hand-written row types and no generated files to keep in sync.
- Is reylo free to use? What license does it have?
- reylo is open source under the MIT license. Check the license terms before using it in commercial products.
- Is reylo still maintained?
- Actively maintained. The last commit to reylo was on Nov 7, 2026.
- What can I use reylo for?
- Keeping TypeScript row types in sync with a changing database schema. Writing hand-tuned SQL while keeping type safety without an ORM. Letting coding agents change queries with the type checker catching stale callers.
- How do I install reylo?
- Install Reylo: npm install reylo Install the engine for your database (Postgres, MySQL or SQLite): npm install -D @reylosql/postgres Set DATABASE_URL in .env to point at your dev database Run your code with Reylo loaded on Node: node --env-file=.env --import reylo/register main.ts
- Where can I get reylo?
- The source code and installation instructions are on GitHub: https://github.com/colinhacks/reylo
Summary generated by AI from the project's README. GitHub stats refresh daily.
Related projects
A lightweight, headless TypeScript ORM for PostgreSQL, MySQL and SQLite that works across Node.js, Bun, Deno and edge runtimes.
A promise-based Node.js and TypeScript ORM for PostgreSQL, MySQL, MariaDB, SQLite, MS SQL Server, Snowflake, Oracle and Db2.
Cross-platform SQL editor and database manager for Linux, macOS, and Windows, supporting MySQL, PostgreSQL, SQLite, SQL Server and many more.
A type-safe TypeScript SQL query builder that autocompletes tables, columns and result types across SQL databases.
Async, pure Rust SQL toolkit with compile-time checked queries written as plain SQL, supporting PostgreSQL, MySQL/MariaDB, and SQLite.