Live data from Hacker News

Show HN: Kysely, a type-safe SQL query builder for TypeScript

kysely.dev

11–20 of 65 posts

Re: Show HN: Kysely, a type-safe SQL query builder for TypeScript

#12
post #9
post #5

Earlier quoted context omitted.

If you use it with kysely-codegen, it generates the types from your DB schema, guaranteeing they match. And the strings are verified at compile time - you can’t typo a table name, field name, etc., it won’t compile. Plus, from an ergonomics POV, it integrates very well with auto-complete. It’s very typesafe IMO, more so than most libs that interact with the the DB, where you hand-define the schemas and can more easil…

I didn't go deep into the docs, but the 'movie' on the homepage clearly shows string-based field name mappings so I instantly saw that as a red flag... Nice to know it's implemented better though.

Yeah, TS has a very flexible/powerful type system. You can have a type like ‘full_name’, that can only be that exact string, or a type like ‘full_name’ | ‘id’ | ‘email’, that can only be those 3 strings, etc. Kysely takes advantage of those sorts of types.

Re: Show HN: Kysely, a type-safe SQL query builder for TypeScript

#13
post #9
post #5

Earlier quoted context omitted.

If you use it with kysely-codegen, it generates the types from your DB schema, guaranteeing they match. And the strings are verified at compile time - you can’t typo a table name, field name, etc., it won’t compile. Plus, from an ergonomics POV, it integrates very well with auto-complete. It’s very typesafe IMO, more so than most libs that interact with the the DB, where you hand-define the schemas and can more easil…

I didn't go deep into the docs, but the 'movie' on the homepage clearly shows string-based field name mappings so I instantly saw that as a red flag... Nice to know it's implemented better though.

It’s a string but TS is crazily powerful. The generated types would verify it’s the correct string says like table_name and the columns name also matches with table_name.

Re: Show HN: Kysely, a type-safe SQL query builder for TypeScript

#14
post #9
post #5

Earlier quoted context omitted.

If you use it with kysely-codegen, it generates the types from your DB schema, guaranteeing they match. And the strings are verified at compile time - you can’t typo a table name, field name, etc., it won’t compile. Plus, from an ergonomics POV, it integrates very well with auto-complete. It’s very typesafe IMO, more so than most libs that interact with the the DB, where you hand-define the schemas and can more easil…

I didn't go deep into the docs, but the 'movie' on the homepage clearly shows string-based field name mappings so I instantly saw that as a red flag... Nice to know it's implemented better though.

TypeScript allows strongly typed string constants. It's actually not a red flag, it's just idiomatic TypeScript.

Re: Show HN: Kysely, a type-safe SQL query builder for TypeScript

#15
post #5
post #3

This is only partially type-safe. Having a few SQL keywords abstracted into methods doesn't deliver a lot of value. I've found some value in type-safe mappings between database fields and language fields, at least you can directly see the problems in your code if some entity class has been changed. String-based field references will only fail at runtime so you need 100% unit tests to refactor with confidence.

If you use it with kysely-codegen, it generates the types from your DB schema, guaranteeing they match. And the strings are verified at compile time - you can’t typo a table name, field name, etc., it won’t compile. Plus, from an ergonomics POV, it integrates very well with auto-complete. It’s very typesafe IMO, more so than most libs that interact with the the DB, where you hand-define the schemas and can more easil…

The only nag I have with this (and it might just be a case of me doing things wrong) is that it seems you also have to create types for tables based on the operation you want to perform by wrapping them in the `Selectable`, `Insertable`, etc. Kysely types. Kinda wish kysely-codegen created all those types along with the base table types. Otherwise, it’s been working pretty well for me so far!

Re: Show HN: Kysely, a type-safe SQL query builder for TypeScript

#19

See now this is what I thought that "Selectric Typeballs" post [1] was going to be. I think it would make for a better name than "Kysely" if I'm being honest. [1] https://news.ycombinator.com/item?id=36406352

Kysely is Finnish for query. Given that the author is Finnish it makes sense

Re: Show HN: Kysely, a type-safe SQL query builder for TypeScript

#20
Doesn't seem like it performs result set nesting on joins? For example with the one to many of owner -> pet, I'd like the results to look something like `{ person: Person, pets: Pet[] }[]`. Knex doesn't do this either (afaict) - wrote a few "deep" queries with some convoluted lodash to group things up but mostly gave up and just live with raw resultsets.

I guess I still prefer that to a full on ORM, but that's really the one missing feature I want from these SQL query builder libraries

Post reply on HN