Reylo
Import .sql files into TypeScript with full type inference from your live Postgres, MySQL, or SQLite database.
Reylo is a powerful SQL type inference engine designed to bridge the gap between relational databases and TypeScript. By allowing developers to import .sql files directly into their TypeScript code, Reylo provides full type safety without the overhead of manual type definitions or traditional code generation. It was created by Colin McDonnell to address the challenges of maintaining type-safe database queries in the modern era of TypeScript development.
Reylo acts as a TypeScript content mapper that inspects your database schema at compile time. It analyzes SQL queries by preparing them against a live database connection to determine parameter types, return column types, nullability, and cardinality. This enables IDEs to provide accurate type information and error reporting directly within .sql files and the TypeScript code that executes them.
Some of the key features are:
- Full SQL Support: Leverage the complete power of your database's syntax, functions, and operators without abstraction limitations.
- Dry Development: Eliminate redundant hand-written types by inferring them directly from your database catalog.
- Database Checked: Queries are verified against your live schema; misspelled columns or incorrect types trigger compilation errors.
- Framework Agnostic: Works seamlessly with Postgres, MySQL, and SQLite databases including services like Neon, PlanetScale, and Cloudflare D1.
- Zero Codegen: Operates without generated files or watchers, keeping your codebase clean and reducing build complexity.
- Agent-Friendly: Provides maintainable and explicitly typed queries that are easy for coding agents and LLMs to understand and refactor.
- Flexible Driver Support: Compatible with a wide variety of popular database drivers including pg, postgres.js, mysql2, better-sqlite3, and more.
To use Reylo, you configure it as a content mapper in your tsconfig.json file. During the build process or while developing in an IDE that supports TypeScript 7.1 content mappers, Reylo connects to your development database using credentials provided in an environment variable or a configuration file. It uses this connection to prepare your SQL queries, mapping the resulting metadata into precise TypeScript types. At runtime, the Reylo engine handles query execution through your chosen database driver, ensuring that the database interactions remain type-safe throughout the entire lifecycle of your application.
Some common use cases include:
- Type-Safe API Routes: Building backends where database query results are automatically typed for frontend consumers.
- Complex Data Transformations: Handling intricate SQL joins and nested JSON aggregation with automatic mapping to TypeScript interfaces.
- Database Migrations: Refactoring schema definitions while relying on the compiler to identify breaking changes in queries.
- Bulk Operations: Managing typed bulk inserts and dynamic filtering with complex constraints validated by Reylo's inference engine.