Reylo, a new developer tool, is making waves by allowing TypeScript developers to import .sql files directly into their code with full type inference. This approach bypasses the traditional codegen step, where developers would manually write interfaces or run generators to sync database schemas with application types. Instead, Reylo acts as a content mapper for TypeScript 7.1, asking the live database to prepare statements and infer types based on the actual schema.

How It Works

The core innovation lies in Reylo's integration with TypeScript 7.1's new content mapper system. When the type checker encounters a .sql import, it hands the file to Reylo. Reylo then connects to your development database (supporting Postgres, MySQL 8.0.22+, and SQLite) and prepares the statement without executing it. By reading the database catalog, it determines parameter types, column types, nullability, and cardinality. For example, a query selecting a primary key is inferred to return a single object or null, while a join might introduce nullable fields based on the join type.

No Codegen, Just Type Checking

One of the biggest pain points in modern web development is keeping generated types in sync with the database. Reylo eliminates this by caching type information in a local .reylo/ directory, keyed by a fingerprint of the schema. This means that if a migration drops a column, the next type check will fail in the specific .sql file that references it, and in any TypeScript code that tries to read that property. This provides a safety net that is often missing in projects relying on manual type definitions or outdated generated files.

Agent-Friendly Architecture

Reylo positions itself as ideal for the 'agent era' of software development. Because the types are derived from a single source of truthβ€”the SQL file and the database schemaβ€”AI coding agents cannot accidentally create stale types. If an agent modifies a query, the type checker immediately validates the change against the database. The tool supports a wide range of drivers, including postgres.js, mysql2, and better-sqlite3, and integrates with popular frameworks like Next.js, Vite, and Cloudflare Workers.

Key Takeaways

  • Reylo requires TypeScript 7.1 (currently in beta) and Node 24 or later.
  • It supports Postgres, MySQL, and SQLite by connecting to a live dev database or reading schema dumps.
  • No codegen is required; types are inferred dynamically during the tsc type-checking process.
  • Nullability and cardinality are inferred from SQL constraints like NOT NULL, primary keys, and joins.

The Bottom Line

Reylo is a bold move toward making SQL a first-class citizen in the TypeScript ecosystem. By leveraging the new content mapper API, it solves the eternal problem of schema drift and type synchronization, though its reliance on a live database for type checking during development might add friction to some CI pipelines.