Re:Show HN: Kysely, a type-safe SQL query builder for TypeSc...
by bzzzt on Wednesday June 21, 2023 @10:29AM
(#36418901)
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.
[ Parent
| on HN ]
Re:Show HN: Kysely, a type-safe SQL query builder for TypeSc...
by yashap on Wednesday June 21, 2023 @10:41AM
(#36419056)
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 easily make typos.
Re:Show HN: Kysely, a type-safe SQL query builder for TypeSc...
by bzzzt on Wednesday June 21, 2023 @10:57AM
(#36419311)
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.
Re:Show HN: Kysely, a type-safe SQL query builder for TypeSc...
by johnfn on Wednesday June 21, 2023 @11:27AM
(#36419765)
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 TypeSc...
by yashap on Wednesday June 21, 2023 @11:21AM
(#36419674)
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 TypeSc...
by thangngoc89 on Wednesday June 21, 2023 @11:26AM
(#36419760)
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 TypeSc...
by a_humean on Wednesday June 21, 2023 @12:41PM
(#36420898)
These are literal string types. Its a feature of at least two languages that I know of:
Typescript: https://www.typescriptlang.org/docs/handbook/literal-types.h...
Scala: https://docs.scala-lang.org/sips/42.type.html
Typescript goes a step further has has things like template literal types: https://www.typescriptlang.org/docs/handbook/2/template-lite...
They are a little bit more than string mappings, and the mapping you do see is all codegen generated from the DB schema.
Re:Show HN: Kysely, a type-safe SQL query builder for TypeSc...
by byproxy on Wednesday June 21, 2023 @11:40AM
(#36419975)
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 TypeSc...
by igalklebanov on Wednesday June 21, 2023 @02:49PM
(#36422656)
It was also requested in prisma-kysely recently.
Might be a good idea to check kysely-codegen's issues section and open an issue if it wasn't requested yet.