Explainers

TypeScript 7.1 Beta: Typed SQL Files with Content Mappers (Reylo)

Published
Duration
Language
English

Watch on YouTube ↗

Summary

TypeScript 7.1 beta content mappers: import a .sql file and get typed parameters and rows.

This cut covers Reylo (by Colin McDonnell, creator of Zod) — a TypeScript content mapper + runtime loader for Postgres, MySQL and SQLite. Register it in contentMappers, point DATABASE_URL at a live development database, run tsc --runExternalCode. Reylo prepares the query on the database and builds the types. It does not type inline sql`…` strings.

Caveats: TS 7.1 is beta; Reylo is 0.6.0 (pre-1.0). No GraphQL content mapper yet — gql.tada still uses template literal types. Stable TypeScript today is 7.0 (native Go port, typically 8–12× faster full builds).

Install (on screen only): npm install reylo && npm install -D @reylosql/postgres typescript@beta

Chapters

  1. 0:00 Hook — .sql import, typed params and rows
  2. 0:05 How Reylo / content mappers work
  3. 0:28 Caveats (beta, 0.6, live DB, files not strings)
  4. 0:42 GraphQL one-liner
  5. 0:48 TypeScript 7.0 context
  6. 0:55 Try the beta

Transcript

Text of the video's narration.

Write your query in a SQL file. Import it into TypeScript. Get typed parameters and typed rows. That is Reylo, a content mapper for the TypeScript 7.1 beta, by Colin McDonnell, the creator of Zod. You register Reylo in your tsconfig, point it at a running development database, and type-check with the run external code flag.

Reylo asks the database to prepare the query, then builds the types from what comes back. Postgres, MySQL, and SQLite are supported. Caveats. TypeScript 7.1 is still beta. Reylo is at version 0.6, before 1.0. You need a live development database.

And it works on SQL files you import, not on inline SQL strings in your TypeScript. No GraphQL content mapper yet; libraries like gql.tada still use template literal types. Quick context: TypeScript 7.0 is the stable native Go port, typically eight to twelve times faster on full builds. Try the TypeScript beta with Reylo, and report what breaks.

Sources

Credits and notes

  • Narrated with Phonon; motion in Remotion.

More in this series · Explainers