Loading video...

Video Failed to Load

Go Home

type inference from .sql files has been achieved internally ORMs are toast

392,691 views • 14 days ago •via X (Twitter)

48 Comments

colinhacks's profile picture
colinhacks14 days ago

this is still beta but you can play with it here 👉

Drizzle ORM's profile picture
Drizzle ORM14 days ago

Wow, nice Is that fundamentally different from what prisma’ve done?

colinhacks's profile picture
colinhacks14 days ago

I have a hundred issues with TypedSQL but tl;dr I think content mappers in TS 7.1 change the calculus for something like this 👍

Igal Klebanov's profile picture
Igal Klebanov14 days ago

very cool use of the new ts stuff! the ecosystem had these author-raw-get-something-typechecked things for a while now. some with codegen, some through ide extensions - so removing the need for something extra in process or dependencies is dope.

colinhacks's profile picture
colinhacks14 days ago

game changer for sure! I'm happy for an excuse to start my next database tooling era ✨

Kazi Ahmed ⚡'s profile picture
Kazi Ahmed ⚡14 days ago

Maannnnn how. How can it know the union? That blew me away. I'm sold. I'm all for type safety, so much so that I have made Tanstack Router like back-end API router that knows layout params or auth state with type safety for that layout branch.

colinhacks's profile picture
colinhacks14 days ago

a LOT of work went into inference engine. check out the Inference docs here for a bunch of examples, you'll dig it 👇

Kazi Ahmed ⚡'s profile picture
Kazi Ahmed ⚡14 days ago

Sorry it suddenly hit me. Does the mappers also work as a module loader or transformer during build or bundle? Inferring types is one thing but wrapping the contents of the SQL file with custom adapter is different. Looks like ts prescribing to use bundlers like vite?

colinhacks's profile picture
colinhacks14 days ago

good question, you need to configure Reylo in tsconfig.json and in your bundler/runtime config to have agreement. it's similar to using tsconfig "paths" Reylo is one package containing lots of plugins lol

Kazi Ahmed ⚡'s profile picture
Kazi Ahmed ⚡14 days ago

Thanks. That makes perfect sense. I was reading the Reylo codebase and found the plugins. There's a lot of goodies in the codebase.

Matija Sosic's profile picture
Matija Sosic14 days ago

I was wondering how/why to use Reylo instead of a "regular" ORM like @prisma or @DrizzleORM, so I put together a quick explainer. TL;DR: - This is possible due to a new mechanism in TS 7.1 - It's a way to get type-safe SQL without codegen - It actually talks to your db, at compile time, to check the types

Chris Griffing's profile picture
Chris Griffing14 days ago

Its not about the lack of ORMs at the end, it's about the ORMs we made along the way.

Francisco Hermida PRO's profile picture
Francisco Hermida PRO14 days ago

this for sqlfu @mmkalmmkal ? would you still recommend it?

Matsu's profile picture
Matsu14 days ago

How does this differ from something like Kysely? By allowing you to import sql files instead of using a tagged template literal?

Aditya Deshlahre's profile picture
Aditya Deshlahre14 days ago

Wow, it works out of the box nice

Lachy's profile picture
Lachy14 days ago

if types come from the .sql file itself, how does it resolve a column's type for a join across two tables? does it read the live database schema at build time, or a schema file checked into the repo?

colinhacks's profile picture
colinhacks14 days ago

good question, Reylo's inference engine sends the query to your database, extracts out the type descriptors from the prepared query, and cross-references against catalog (Postgres) or information_tables (other dialects) so the type information always comes from the database itself 👍

Lubos @heyapi.dev's profile picture
Lubos @heyapi.dev14 days ago

I want some of what you’re on

Kizuno18's profile picture
Kizuno1814 days ago

skipping the codegen step and having direct compiler inference from raw .sql is huge. how does the parser handle complex jsonb projections or cte unions?

Rajat's profile picture
Rajat14 days ago

Damn 🔥 Is it possible to write SQL inside .ts files and get the same type inference?

colinhacks's profile picture
colinhacks14 days ago

unfortunately not, I heard @atcb may have some early plans cooking for that but I actually prefer for stuff like this to happen at an import boundary. Reylo is implemented as a content mapper (basically a plugin for TypeScript)

Rajat's profile picture
Rajat14 days ago

@atcb can you make a plugin for jsonc too? its been a while since people asking for a support in typescript repo

colinhacks's profile picture
colinhacks14 days ago

@atcb that's supported in Motherload!

ucixrn's profile picture
ucixrn14 days ago

Looks cool

freddie's profile picture
freddie14 days ago

query builders* ORMs are fine

Jaga santagostino's profile picture
Jaga santagostino14 days ago

bittersweet to have this after agents 🥲

klitty's profile picture
klitty14 days ago

please i cant keep up anymore

Wessel E's profile picture
Wessel E14 days ago

Give us six months and we'll put an ORM back on top of those.sql files.

Rapid's profile picture
Rapid14 days ago

ORM in 2026 😅 what

TheOneHong阿康's profile picture
TheOneHong阿康14 days ago

if type inference can be done with embedded sql statement, will be goated

Europäische Aktion 🇪🇺 🇩🇪's profile picture
Europäische Aktion 🇪🇺 🇩🇪14 days ago

Is it compatible with Bun?

diip3sh's profile picture
diip3sh14 days ago

does the inference track a left join becoming effectively inner when a where clause rules out nulls on the joined table?

el jesu 😎's profile picture
el jesu 😎14 days ago

Hi! question from a humble java Dev watching your video made me realize that you'd add one SQL file for every query wou use is it something standard in typescript/JavaScript backbends? it seems to me that's only appropriate for micro micro services

Stephen's profile picture
Stephen14 days ago

This is similar to what SQLC does in Golang...

Łukasz Jagodziński's profile picture
Łukasz Jagodziński14 days ago

ORMs are not toasted as you can’t build type safe dynamic queries this way. I built an SQL code generator in the past and it was the biggest issue with that kind of solution. I guess you could have more complex logic in SQL but most people will prefer building their queries with query builders.

Hussein Kizz ★'s profile picture
Hussein Kizz ★14 days ago

Are we to throw away our ORMs now?

Matija Sosic's profile picture
Matija Sosic14 days ago

Why is this better than using an ORM like Prisma or Drizzle?

Chud's profile picture
Chud14 days ago

this is actually crazy, great things coming typescript’s way

David Klingenberg's profile picture
David Klingenberg14 days ago

Wow, that's pretty cool. It reminds me Type Providers in F# :)

zlumer.eth's profile picture
zlumer.eth14 days ago

amazing! does it use pgtyped or how it compares?

smallshen's profile picture
smallshen14 days ago

What about use prql?

Alberto Díaz's profile picture
Alberto Díaz14 days ago

What do ORMs provide over this? I guess that some people prefer to write queries using ORMs rather than SQL?

colinhacks's profile picture
colinhacks14 days ago

declarative schema & migrations are nice! Reylo doesn't do that (probably never will) but with content mappers enabling direct .sql imports from TypeScript files, I don't really see why anyone would use an ORM over Reylo for actually writing queries

Alberto Díaz's profile picture
Alberto Díaz14 days ago

Any chance that we get type inference from inline queries? Or must they be a separate SQL file? I am eager to try Reylo, but I am wondering if I can truly apply it to a project where every query is inline (within TS files)

colinhacks's profile picture
colinhacks14 days ago

it's not possible with content mappers. you could probably use Reylo's engine and integrate it into some kind of build step, but I'm pretty allergic to that kind of thing...lots of thorny edge cases when it comes to static analysis like this

Alberto Díaz's profile picture
Alberto Díaz14 days ago

Thanks! I would have to extract every single SQL query into a companion SQL file. Tbh, I may give it a try. I was planning to move everything to kysely or drizzle, but... Reylo looks kinda neat :D

Sacha's profile picture
Sacha14 days ago

This 97 year old diner still serves their Coke the old-fashioned way.

Jon Åslund's profile picture
Jon Åslund14 days ago

Why does it infer return type | null after you add the email where clause?

Related Videos