colinhacks/reylo

★ 1,374⑂ 15

Import .sql files into TypeScript with full type inference and zero codegen.

About colinhacks/reylo

colinhacks/reylo is an open-source project on GitHub, mainly written in Rust. Import .sql files into TypeScript with full type inference and zero codegen. It currently holds 1,374 stars and 15 forks with 0 open issues, and was last pushed on an unknown date (repository created unknown).

Project Overview

Git Homed tracks it on the Today's Trending board.

GitHub Repository Details

Repository colinhacks/reylo · default branch - · size 0 KB · watchers 0 · source: GitHub REST API and repository README

README

https://github.com/colinhacks/reylo/blob/HEAD/Reylo

Import .sql files into your TypeScript code with full type inference

https://github.com/colinhacks/reylo/blob/HEAD/test status https://github.com/colinhacks/reylo/blob/HEAD/License: MIT https://github.com/colinhacks/reylo/blob/HEAD/npm version https://github.com/colinhacks/reylo/blob/HEAD/GitHub stars

Read the docs →


https://github.com/colinhacks/reylo/blob/HEAD/An editor: hovering a query's result shows its type, which follows the SQL as the SQL changes


If you have a file like this:

-- get_author.sql
select u.id, u.name, count(p.id)::int as post_count
from users u
left join posts p on p.user_id = u.id
where u.id = :id::int
group by u.id

You can import it directly from a TypeScript file like this:

// main.ts
import postgres from "postgres";
import getAuthor from "./get_author.sql";

const db = postgres(process.env.DATABASE_URL);

const author = await getAuthor.run(db, { id: 1 }); // { id: number; name: string; post_count: number } | null

Reylo is powered by TypeScript content mappers, introduced in TypeScript 7.1 (currently in beta), which let you dynamically define static types for external file types and integrate them directly into TypeScript compilation.

Reylo is the perfect option for the agent era:

Setup

To install Reylo, you'll need:

Install Reylo, the engine for your database and TypeScript 7.1:

npm install reylo
npm install -D @reylosql/postgres  # or mysql, sqlite
npm install -D typescript@beta

Add Reylo to tsconfig.json, for .sql files and for its project file, .reylo.yaml or .reylo.yml:

// tsconfig.json
{
  "compilerOptions": { / ... / },
  "contentMappers": [
    { "package": "reylo", "extensions": [".sql", ".reylo.yaml", ".reylo.yml"] }
  ]
}

Then type-check with --runExternalCode, which lets tsc run content mappers:

// package.json
{
  "scripts": {
    "typecheck": "tsc --noEmit --runExternalCode"
  }
}

Point Reylo at your dev database with DATABASE_URL, in your environment or in .env. Its scheme tells Reylo which database you use:

# .env
DATABASE_URL=postgres://localhost:5432/app  # or mysql://…, or file:./app.db for SQLite

To make .sql imports work at run time too, load Reylo where your code runs. On Node:

node --env-file=.env --import reylo/register main.ts

For Bun, Nub, Vite, Next.js, esbuild, webpack, Rspack, Cloudflare Workers and Jest, add the plugin for your setup, or copy its complete example project. To see the types as you type, set up your editor.

Usage

Write a query in a .sql file, import it, and run it with your database driver:

-- get_user.sql
select id, name, email from users where id = :id::int
import getUser from "./get_user.sql";

const user = await getUser.run(db, { id: 1 }); // { id: number; name: string; email: string | null } | null

Name each parameter with a colon, and give it a type with a cast where the query doesn't pin one down. Pass .run() your driver's client: a pool, a client, or a connection or transaction taken from one.

It resolves to the rows, shaped by how many the query can return:

| The query | Resolves to | | --- | --- | | A match on a primary or unique key, or limit 1 | Row \| null | | An aggregate without group by, a one-row insert … returning | Row | | An insert, update or delete without returning | void | | Anything else | Row[] |

An imported query also has .runSync(), .try(), .with(), .sql, .raw and .source (Usage). Every query Reylo runs is published on Node's tracing channel reylo:query, for a tracer or a logger to subscribe to (Tracing).

What Reylo infers

To type a query, Reylo has your dev database prepare it, without running it, and reads back the type of every column and parameter. On top of that, it infers:

Each has examples in Inference.

Supported drivers

Reylo is bring-your-own-driver. Pass .run() a client from any of these, or a Drizzle database over one:

Documentation

reylo.dev covers the rest: every plugin and editor, configuration, errors, each database's data types and edge cases, and advanced examples. Agents can read it all as Markdown at reylo.dev/llms.txt.

License

MIT

GitHub Stars & Activity

1,374Stars
15Forks
0Open issues
RustLanguage

GitHub Popularity

GitHub stars1,374
Forks15
Open issues0
Primary languageRust
License-
Stars gained today0
Created-
Last pushed-

Trending History

Weekly boardrank #22 · ▲ 0 stars

Related GitHub Projects

1

anomalyco / hokum

Rust★ 134⑂ 2
→
2

QuixiAI / QuixiDesk

Rust★ 109⑂ 31
→
3
→
4

crystalmasta / unbihex

Rust★ 103⑂ 5
→
5

anhao / ai-pose-gallery-zh

HTML★ 2,551⑂ 668
→
6

andyhuo520 / digital-human-koubo

TypeScript★ 1,400⑂ 323
→
7

Motionsites-AI / claude-skill

Python★ 1,021⑂ 106
→
8

kargulstudio / calender-app-design

TypeScript★ 795⑂ 96
→

More Trending Repositories