Show HN: Kysely, a type-safe SQL query builder for TypeScript
1–10 of 65 posts
Re: Show HN: Kysely, a type-safe SQL query builder for TypeScript
#2Re: Show HN: Kysely, a type-safe SQL query builder for TypeScript
#3Re: Show HN: Kysely, a type-safe SQL query builder for TypeScript
#4Also, a query builder with generated types that match the DB schema has many of the advantages of an ORM, with IMO few of the disadvantages. I’m not spending so much time trying to figure out how to translate what I want to do in SQL into the ORM language, as it’s basically a thin, more type safe and composable layer over SQL.
Re: Show HN: Kysely, a type-safe SQL query builder for TypeScript
#5This 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.
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 TypeScript
#6For Java, JOOQ is great and offers better type safety than this. Additionally, JOOQ generates data model classes from the DB schema.
Re: Show HN: Kysely, a type-safe SQL query builder for TypeScript
#7This 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.
Re: Show HN: Kysely, a type-safe SQL query builder for TypeScript
#8Re: Show HN: Kysely, a type-safe SQL query builder for TypeScript
#9This 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…
Nice to know it's implemented better though.
Re: Show HN: Kysely, a type-safe SQL query builder for TypeScript
#10How does it compare to zapatos? https://jawj.github.io/zapatos/
The solution we use right now is ts-sql-query [1] which supports automatic type-safety for complex joins, CTEs, subselects etc. I evaluated Kysely as well but found the sql feature set coverage of ts-sql-query better at the time.
I maintain a code-generator [2] for this project that can generate the table mappers from database schema similar to how zapatos.
We don't have as good support for lateral joins and deriving json from database though, which zapatos does really well.