正在加载视频...

视频加载失败

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

393,206 次观看 • 18 天前 •via X (Twitter)

48 条评论

colinhacks 的头像
colinhacks18 天前

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

Drizzle ORM 的头像
Drizzle ORM18 天前

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

colinhacks 的头像
colinhacks18 天前

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 的头像
Igal Klebanov18 天前

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 的头像
colinhacks18 天前

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

Kazi Ahmed ⚡ 的头像
Kazi Ahmed ⚡18 天前

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 的头像
colinhacks18 天前

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 ⚡ 的头像
Kazi Ahmed ⚡18 天前

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 的头像
colinhacks18 天前

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 ⚡ 的头像
Kazi Ahmed ⚡18 天前

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 的头像
Matija Sosic18 天前

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 的头像
Chris Griffing18 天前

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

Francisco Hermida PRO 的头像
Francisco Hermida PRO18 天前

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

Matsu 的头像
Matsu18 天前

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

Aditya Deshlahre 的头像
Aditya Deshlahre18 天前

Wow, it works out of the box nice

Lachy 的头像
Lachy18 天前

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 的头像
colinhacks18 天前

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 的头像
Lubos @heyapi.dev18 天前

I want some of what you’re on

Kizuno18 的头像
Kizuno1818 天前

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 的头像
Rajat18 天前

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

colinhacks 的头像
colinhacks18 天前

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 的头像
Rajat18 天前

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

colinhacks 的头像
colinhacks18 天前

@atcb that's supported in Motherload!

ucixrn 的头像
ucixrn18 天前

Looks cool

freddie 的头像
freddie18 天前

query builders* ORMs are fine

Jaga santagostino 的头像
Jaga santagostino18 天前

bittersweet to have this after agents 🥲

klitty 的头像
klitty18 天前

please i cant keep up anymore

Wessel E 的头像
Wessel E17 天前

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

Rapid 的头像
Rapid18 天前

ORM in 2026 😅 what

TheOneHong阿康 的头像
TheOneHong阿康17 天前

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

Europäische Aktion 🇪🇺 🇩🇪 的头像
Europäische Aktion 🇪🇺 🇩🇪17 天前

Is it compatible with Bun?

diip3sh 的头像
diip3sh18 天前

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

el jesu 😎 的头像
el jesu 😎18 天前

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 的头像
Stephen18 天前

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

Łukasz Jagodziński 的头像
Łukasz Jagodziński18 天前

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 ★ 的头像
Hussein Kizz ★18 天前

Are we to throw away our ORMs now?

Matija Sosic 的头像
Matija Sosic18 天前

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

Chud 的头像
Chud18 天前

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

David Klingenberg 的头像
David Klingenberg18 天前

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

zlumer.eth 的头像
zlumer.eth18 天前

amazing! does it use pgtyped or how it compares?

smallshen 的头像
smallshen18 天前

What about use prql?

Alberto Díaz 的头像
Alberto Díaz18 天前

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

colinhacks 的头像
colinhacks18 天前

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 的头像
Alberto Díaz18 天前

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 的头像
colinhacks18 天前

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 的头像
Alberto Díaz18 天前

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 的头像
Sacha18 天前

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

Jon Åslund 的头像
Jon Åslund18 天前

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

相关视频