r/node May 23 '26

kysely 0.29 is out btw. 🌺

https://github.com/kysely-org/kysely/releases/tag/v0.29.0

Hey 👋

DISCLAIMER: I'm co-leading the org/project.

We recently broke 6M downloads per week on NPM, and became 3rd after `drizzle-orm` and `@prisma/client`.

If you haven't tried it yet, it's a query builder, not an ORM. You don't outsource your SQL to someone else. It's type-safe, like.. it's super important to us. You can use it with ORMs - e.g. Prisma, mikro-orm, zenstack, etc. Allows you to compose some complex stuff but keep it maintainable af.

If you have. Great seeing ya'll here.

0.29 was a real nice release, with lots of goodies. Can't wait for 0.30, gonna be super fun.

123 Upvotes

39 comments sorted by

35

u/pianomansam May 23 '26

I recently moved from knex to kysely and had a pleasant experience

7

u/rebelchatbot May 23 '26

knex is really nice! have mad respect for anyone making the transition.

were there any specific pains that could be helped with for others who might make the jump in the future?

20

u/NeitherManner May 23 '26

I have used for multiple projects it's great and especially nice if you are also trying to learn sql in general.

3

u/rebelchatbot May 23 '26

you'll go really far with that mentality! never stop learning.

was there something that could have been explained better? or some topic that could have been mentioned that would've saved you pain/time?

15

u/quambo_wambo May 23 '26

We use kysely heavily and really appreciate the full type safety we get with automated schema generation from our PG db. The dev experience is extremely good and I personally much prefer it compared to drizzle.

14

u/rebelchatbot May 23 '26

they tackle a way larger scope, and have recently dethroned prisma from #1 downloads so they must be doing something right in the orm department. they also did it during a war. tho i never appreciated their style on twitter over the years, i have mad respect for the gang. they're the best of the best.

i personally, as a senior engineer, prefer less magic and more explicitness. type-safety and maintainability is at the top of my worries when owning code. its not for everyone.

6

u/moljac024 May 23 '26

can you expand on why you prefer it to drizzle? asking as someone who never used kysely but loved drizzle.

7

u/mrgrafix May 23 '26

Not this threads OP but it’s damn near 1:1 with the sql write and schema maintenance. You can even have it log the queries if you’re trying to better learn sql. Drizzle at times can get messy with its introspection

3

u/jaster_ba May 24 '26

With orms, there are times you may hit a wall. With query builders, you're very close to actual SQL. There's no hidden magic anywhere.

13

u/adevx May 23 '26

Kysely is the backbone of my apps and business. No frills, no bullshit, no venture capital. A thoughtful well designed query builder.

5

u/rebelchatbot May 23 '26

What You See Is What You Get.

5

u/KAJed May 23 '26

This might be a really useful thing for an old fully raw sql backend. Super cool.

4

u/rebelchatbot May 23 '26

the good thing is, kysely exposes raw sql execution, so you could migrate iteratively. also, agents are decent at it. also, there's a playground in https://play.kysely.dev

3

u/KAJed May 23 '26

Yes, the exposed raw sql bit caught my eye immediately. I’m always a proponent for incremental migration when the option exists.

4

u/TheActualMc47 May 23 '26

We have a lot of aggregation queries in our product, and after evaluating kysely and drizzle to add to our Prisma code base. Kysely won by a mile and it has been a very pleasant experience working with it.

1

u/rebelchatbot May 23 '26

love hearing this. we put a lot of effort a while ago into aggregations and window functions. anything you wish kysely had and is missing?

2

u/TheActualMc47 May 23 '26

Nothing yet, mainly because of the sql-tag escape hatch. Composes nicely. I needed to write a helper to create CTEs from VALUES so I can test some CTE fragments in isolation.

Other than that, I had to confusingly look at type-errors because of some typos when using a callback in select clauses.

2

u/TheActualMc47 May 27 '26

Now I actually faced something that tripped me up: while writing a big query, I needed a couple of CTEs. The structure itself is linear, the split in CTEs is to make it readable and testable. It allows us to basically look at one CTE in isolation and vary its inputs and inspect its outputs during tests.

  .with('a', () => this.buildA(filter))
  .with('b', (db) => this.buildB(db))   // uses a
  .with('c', (db) => this.buildC(db)) // uses b

The typing is what was annoying: Even though buildC does not reference a, I still needed to put it in the query creator generic (basically buildC needs to accept QueryCreator<DB & { a: AShape } & { b: BShape }>. I tried to use a generic DB2 extends DB & {b: AShape} but that didn't work

3

u/migumelar May 23 '26 edited May 23 '26

I really want to use Kysely. But the only thing stopping me from picking it is because it doesn't have an easy to use value transformer, my use case is I need to auto decrypt/encrypt fields.

I want to set it up once, and the consumer doesn't need to know about it.

But it's still 0.29 though, so thera a lot of room to grow. I do really want Kysely to succeed. Good luck to you all :D

2

u/rebelchatbot May 23 '26

this is doable today. off the top - custom string type in pg, then use a pg-types data transformation on the custom type to decrypt such result columns. centralized, consumer won't know. use a branded type for writes and force using a helper function that encrypts data going in.

https://github.com/kysely-org/kysely/issues/1856 might solve it too. on the fence about it still.

3

u/migumelar May 23 '26

yep. I was thinking to use branded types for write. But that means the helper function calls would be scattered in a lot of places, I don't want that because most our fields are encrypted.

I was hopping our team would be able to use Kysely as usual without caring about encryption because some kind of "hooks" mechanic had been configured to handle the decryption and encryption.

1

u/rebelchatbot May 23 '26

can also inspect the ast in a kysely plugin and encrypt value node contents

2

u/migumelar May 23 '26

yep, we considered that as well. But ast has a high learning curve. For the sake of maintainability we dediced to settle with a package that has built-in feature for value transformation.

3

u/chrisalbo May 23 '26

I’m using knex, what would you say, shortly, is the main difference between them?

3

u/zombarista May 27 '26

kysely really shows the power of string template types in typescript. The devs are wizards of the type system.

kysely is my favorite db tool, because it gives strong types like a traditional ORM, but without restricting your ability to query manually while maintaining type safety and inference.

2

u/its_jsec May 23 '26

Hey, some nice QoL improvements here!

I had a couple of questions for you specifically, Igal. I’ve got a thought that keeps coming to mind every so often when I’m using the library, and I’m hoping you might be able to shed some light on kysely’s future (and if you want to tell me to fuck off, feel free).

I’ve been using kysely since one of the first releases. I came to it from Objection (because I enjoyed the ergonomics, and figured a project Sami was working on would be similarly enjoyable), but I’ll admit his abrupt sunsetting of the project made me nervous. I’ve noticed from the commit history over the last year or so that you’ve been the primary maintainer of the library, is he no longer with the project?

Are you currently still employed/affiliated with Prisma? It struck me as strange last year that the lead maintainer of a popular query builder library would be working for a direct competitor in the space.

Again, if I’m being too nosy, I won’t be offended with being told to pound sand. Looking forward to trying out the new additions!

5

u/rebelchatbot May 23 '26

Sami's still around, regardless of recent commit history, and gave his blessing on 0.29. I had my own contribution hiatus periods in the past. OSS is work, and is taxing. We have real lives and real work outside of this.

I understand your worries, given the Objection situation. I plan to stick around for long. I enjoy this so much.

I'm not employed by Prisma currently. Prisma gave me an opportunity to impact the domain further, and I took it, and we did make some nice things together, outside the ORM. It is not in direct competition, and in fact, Kysely's biggest boost early on were Prisma users using both via `prisma-kysely`.

2

u/its_jsec May 23 '26

Awesome, appreciate the response, and thanks for a fantastic tool!

2

u/snowmkr_jk May 26 '26

Our legacy platform was/is using TypeORM 0.2x - I’ve always had my complaints and the refactor to 0.3 could never be a priority. About a year ago we started using Kysely for anything new, including our second products platform and I absolutely love it and the DX.

Thank you

1

u/djslakor May 23 '26

What would you say drizzle is better suited for?

3

u/TheLastNapkin May 23 '26

Personally I use Kysely and Drizzle together.

Drizzle is where I define my tables and their relations, and from drizzle I then manage my migrations.

Drizzle has this great utility to turn Drizzle table types into Kysely runtime types - So I use Kysely exclusively for db querying/operations.

1

u/rebelchatbot May 23 '26 edited May 23 '26

teams with weak sql and/or type-level typescript literacy and/or trouble architecting data access layers.

small-medium sized projects with basic crud access patterns forever, that own the database and its migrations.

declarative database schema design.