News for hackers. Stuff that matters.
Re:Kysely: TypeScript SQL Query Builder by jakewins on Tuesday January 24, 2023 @01:51PM (#34508176)
Dang, how do they implement the “parse text strings and generate types immediately available in auto-complete” thing?? I can see how you could do that with Rust Macros, but how do they do it in TS?

Eg. this thing:

blah.select(['pet.name as pet_name'])

is inferred to return a type with a `pet_name` field, parsing the contents of the SQL expression?

[Update]: whatafak lol TS has way more juice in it than I realized: https://github.com/koskimas/kysely/blob/master/src/parser/se...

Re:Kysely: TypeScript SQL Query Builder by kamilafsar on Tuesday January 24, 2023 @02:02PM (#34508357)
The relevant TS feature is called template literal types:

https://www.typescriptlang.org/docs/handbook/2/template-lite...

Re:Kysely: TypeScript SQL Query Builder by nikeee on Tuesday January 24, 2023 @05:43PM (#34511659)
You can use these template literal types + infer to build an entire SQL parser. I did a POC that infers SQL query types by parsing the SQL query on a type level:

https://github.com/nikeee/sequelts

Building this parser is pretty cumbersome and supporting multiple SQL dialects would be lots of pain. While I'm not a fan of query builders per se, Kysely pretty much covers everything that my POC tried to cover (except that 0 runtime overhead). However, you get the option to use different DBMs in tests than in production (pg in prod, sqlite in tests), which is a huge benefit for a lot of people. sequelts was designed to work with sqlite only. And it's a hack.

Re:Kysely: TypeScript SQL Query Builder by eddsh1994 on Wednesday January 25, 2023 @01:53AM (#34515228)
The typescript type system is insane, I solved quite a few project Euler tasks with it in the type system itself (From peano numbers up). I learned to never question the TS community