I'm trying to think what happens when a column gets deleted or added in the prod, ci, or dev db tier. Ideally those db schema changes should happen at the same time but real life doesn't work like that.
Show HN: Kysely, a type-safe SQL query builder for TypeScript
41–50 of 65 posts
Re: Show HN: Kysely, a type-safe SQL query builder for TypeScript
#42Another "almost" like SQL library that I've heard floating around: https://github.com/drizzle-team/drizzle-orm I think I've reached the limits of Prisma and embarrassingly I'm thinking about ripping it out. The benefits of not having to constantly reference your DB schema and having IDE guidance is not matching up to the idiosyncrasy and incomplete DB support of Prisma.
Re: Show HN: Kysely, a type-safe SQL query builder for TypeScript
#43Doesn'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…
Have you read this recipe? https://kysely.dev/docs/recipes/relations
Re: Show HN: Kysely, a type-safe SQL query builder for TypeScript
#44How does it compare to zapatos? https://jawj.github.io/zapatos/
We moved away from zapatos because the generated types are good only when selecting from single table. The moment we start selecting some subset of columns from a join of multiple tables, it is upto the developer to provide the right combination of pick and intersection of generated types and type safety takes a hit. The solution we use right now is ts-sql-query [1] which supports automatic type-safety for complex jo…
Kysely also provides "automatic type-safety for complex joins, CTEs, subselects etc.".
Gotta love how toxic some open-source maintainers are, bashing other libraries while self-promoting.
Re: Show HN: Kysely, a type-safe SQL query builder for TypeScript
#45for the db schema definition for this tool, where does the source of truth lives? I'm trying to think what happens when a column gets deleted or added in the prod, ci, or dev db tier. Ideally those db schema changes should happen at the same time but real life doesn't work like that.
kysely-codegen can introspect all core dialects. prisma-kysely can generate straight from Prisma schemas.
We recommend using these in production apps. You could verify everything is aligned in your CICD workflows.
Re: Show HN: Kysely, a type-safe SQL query builder for TypeScript
#46If you want to run SQL, write SQL. The majority of your SQL will not require building dynamic where clauses or (dog forbid) dynamic joins. Having your SQL as plain statements with simple placeholders (to create safe prepared statements) is the saner approach. Not only can you pluck them into your favorite SQL tools and analyzers, but you will not be surprised by terribly performing queries, because you created them d…
Re: Show HN: Kysely, a type-safe SQL query builder for TypeScript
#47Has anyone used this and compared to the types provided by Knex? I’m largely very happy with Knex but when you start dealing with subqueries and the like the types fall apart. Suspect this kind of thing is pushing TS types to their limit, though.
We care a lot about our TypeScript compilation performance and Developer eXperience in general.
v0.25 introduced internal changes that doubled the possible complexity of CTEs, joins and conditional selects.
We also provide helper methods that "reset" the stack in a type-safe way.
Re: Show HN: Kysely, a type-safe SQL query builder for TypeScript
#48Fun fact: "Kysely" is "query" in Finnish.
Re: Show HN: Kysely, a type-safe SQL query builder for TypeScript
#49Igal from Kysely here (I did not create it, Sami did).
Our site is a constant WIP. We've recently revamped "Getting Started" and added a lot of examples. If you can't find something there, check the API docs site or JS docs in your IDE - everything is documented.
We respond quite fast on discord if you've got any questions.
Feel free to ask me questions here too. :)
Re: Show HN: Kysely, a type-safe SQL query builder for TypeScript
#50Earlier 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…
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!
Might be a good idea to check kysely-codegen's issues section and open an issue if it wasn't requested yet.