AI NewsDev toolsAnnouncement

Reylo imports SQL files into TypeScript with full type inference, no codegen

Colin McDaniel, the author of Zod, released Reylo, a TypeScript library that reads a .sql file at compile time, queries the dev database for the resulting row and parameter shapes, and gives the import a static type, with no code generation step.

AI News

Editorial2 min read

LinkedInX
GitHub social card for colinhacks/reylo, a tool that imports SQL files into TypeScript with full type inference and no codegen

Image: GitHub

Why it mattersA SQL file an engineer edits now participates in the same type check as the rest of the codebase, so a dropped column or a renamed field becomes a tsc error at the call site rather than a runtime failure in production.

Colin McDaniel, the maintainer of Zod, published a TypeScript library called Reylo that lets a TypeScript project import a .sql file and get back a fully typed query, with no code generation step in the middle. The repository is one day old and already has 186 stars.

The README says Reylo is built on content mappers, a feature TypeScript 7.1 is adding in beta. A content mapper lets a tool "dynamically define static types for external file types and integrate them directly into TypeScript compilation." Reylo uses that hook to read the SQL file at compile time, send it to a development database for a prepare step, and feed the resulting row shape and parameter shape straight into the type checker.

What is different from a code generator

Today the common way to get typed SQL in TypeScript is a code generator. SQLC, Prisma and Drizzle all read the schema, write a TypeScript file to disk with the types, and the application imports from that file. The generated file lives in the repo, needs a watcher or a build step to stay current, and shows up in pull requests.

Reylo does not write any file. The project description on GitHub says it offers "full type inference and zero codegen." When the compiler sees import { getUser } from "./queries/get-user.sql", Reylo introspects the dev database, resolves the column types for the SELECT clause and the parameter types for the WHERE clause, and the import binding has the exact row type. A dropped column or a renamed field now produces a tsc error at the call site in the same pass that type-checks the rest of the TypeScript.

What it costs

The approach is tied to a very recent TypeScript feature. The README says Reylo requires TypeScript 7.1, which was in beta at the time of writing, and Node 24 or later. The type checker also needs a live connection to a development database at compile time, because the type information comes from asking the database itself.

Supported dialects according to the README are PostgreSQL, MySQL from version 8.0.22 onward, and SQLite, with drivers for pg, postgres.js, mysql2 and better-sqlite3. The license is MIT.

For a team that already runs a dev database on every developer machine and in CI, trading a generated file for a compile-time query is cheap. For a team whose CI runners do not have database access, the trade is harder, and a code generator may stay the better fit. Either way, SQL in TypeScript now has a design option that does not involve a file on disk, which is new.

Source

colinhacks/reylo on GitHub.

SourceGitHub

This item was written by an AI system from the linked source. Reveneau is responsible for what it publishes.

Share
LinkedInX
Start a project