# AI use cases for Reylo (colinhacks/reylo)

Repo: [colinhacks/reylo](https://github.com/colinhacks/reylo) | Use cases: 3 | Page: https://dedupedai.com/use-cases/colinhacks-reylo/

Reylo, from Zod author Colin McDonnell, lets you import .sql files straight into TypeScript with full type inference and no codegen. It uses TypeScript 7.1 content mappers to have your dev database prepare each query and read back column and parameter types, so a misspelled column or wrong parameter becomes a type error in tsc and your editor. It supports Postgres, MySQL and SQLite with your own driver.

This file holds every use case of this repo. Each one starts with a "## " heading and ends with its URL.

- Import .sql files into TypeScript with real types: https://dedupedai.com/use-cases/colinhacks-reylo/import-sql-files-into-typescript/
- Catch broken SQL in tsc before it ships: https://dedupedai.com/use-cases/colinhacks-reylo/catch-broken-sql-in-tsc/
- Let coding agents edit SQL without leaving stale types: https://dedupedai.com/use-cases/colinhacks-reylo/let-coding-agents-edit-sql-without-stale-types/

## How to import .sql files into TypeScript with real types with Reylo

Repo: [colinhacks/reylo](https://github.com/colinhacks/reylo) | Difficulty: Intermediate | Time: 30 minutes | Basis: From the README

Write queries in .sql files, import them, and get row and parameter types from your database.

**Who it is for:** A TypeScript developer tired of hand-writing row types that drift out of sync with their raw SQL.

**The problem:** Raw SQL means hand-written types that go stale; an ORM means giving up some of the power of SQL.

**The outcome:** Typed query imports, like a row or null for a unique-key match, with no generated files and no watcher.

### Steps

1. Install: `npm install reylo`, then `npm install -D @reylosql/postgres` (or mysql or sqlite) and `npm install -D typescript@beta`
2. Add a contentMappers entry for Reylo to tsconfig.json covering .sql, .reylo.yaml and .reylo.yml
3. Set DATABASE_URL in your environment or .env; its scheme tells Reylo which database you use
4. Write a query in a .sql file with named parameters such as :id::int, import it and call `.run(db, { id: 1 })` with your driver's client
5. Load Reylo at run time on Node with `node --env-file=.env --import reylo/register main.ts`, or add the plugin for Bun, Vite, Next.js or your setup

### Prompt to paste into your agent

```text
Add colinhacks/reylo to <project> using <database> and <driver>. Move the query in <file> into a .sql file, import it, and show me the inferred return type. Use TypeScript 7.1 beta and keep the existing behavior identical.
```

### Caveat

It depends on TypeScript 7.1, which is still in beta, and needs a live dev database for type checks.

Disclaimer: Third-party repos we don't own or vouch for. AI-generated use cases can be wrong: review everything and run at your own risk. Full text: https://dedupedai.com/disclaimer/

URL: https://dedupedai.com/use-cases/colinhacks-reylo/import-sql-files-into-typescript/

## How to catch broken SQL in tsc before it ships with Reylo

Repo: [colinhacks/reylo](https://github.com/colinhacks/reylo) | Difficulty: Intermediate | Time: 20 minutes | Basis: From the README

Type-check SQL against your dev database so a dropped table or misspelled column fails the build.

**Who it is for:** A team that has shipped a renamed column to production because nothing checked the queries.

**The problem:** SQL in strings or files is invisible to the type checker, so schema changes break at run time.

**The outcome:** A typecheck script that reports a misspelled column, a wrong parameter or a dropped table as a type error.

### Steps

1. Add a typecheck script: `tsc --noEmit --runExternalCode`, which lets tsc run content mappers
2. Point DATABASE_URL at a dev database that has your current schema
3. Run the typecheck locally and in CI after every migration
4. Set up your editor from the Reylo docs to see the same errors as you type

### Prompt to paste into your agent

```text
In <project>, add a typecheck script that runs tsc with --noEmit --runExternalCode against the dev database in DATABASE_URL. Then rename <column> in a scratch migration and show me every .sql query and caller that now fails.
```

### Caveat

--runExternalCode lets tsc execute content mapper code, and CI needs access to a database with the current schema.

Disclaimer: Third-party repos we don't own or vouch for. AI-generated use cases can be wrong: review everything and run at your own risk. Full text: https://dedupedai.com/disclaimer/

URL: https://dedupedai.com/use-cases/colinhacks-reylo/catch-broken-sql-in-tsc/

## How to let coding agents edit SQL without leaving stale types with Reylo

Repo: [colinhacks/reylo](https://github.com/colinhacks/reylo) | Difficulty: Intermediate | Time: 20 minutes | Basis: From the README

Keep each query in one .sql file so an agent cannot leave an old type behind, and let tsc find every caller.

**Who it is for:** A developer whose agent changes a query but forgets to update the matching TypeScript type.

**The problem:** When types live apart from queries, agents fix one and leave the other stale.

**The outcome:** Agent edits that are checked end to end: change the SQL, and the type check flags every caller it missed.

### Steps

1. Set up Reylo as in its README so queries live in .sql files and types come from the SQL itself
2. Point your agent at the docs as Markdown at Reylo.dev/llms.txt
3. Ask the agent to change a query and then run the typecheck script
4. Have it fix every caller the type check reports before it calls the task done

### Prompt to paste into your agent

```text
Read reylo.dev/llms.txt, then in <project> change <query>.sql to <change>. Run the typecheck with --runExternalCode and fix every caller it reports. Do not hand-write any row types.
```

### Caveat

The agent still needs access to the dev database for the type check to mean anything.

Disclaimer: Third-party repos we don't own or vouch for. AI-generated use cases can be wrong: review everything and run at your own risk. Full text: https://dedupedai.com/disclaimer/

URL: https://dedupedai.com/use-cases/colinhacks-reylo/let-coding-agents-edit-sql-without-stale-types/
