๐ We've found a great alternative to TypeORM, Prisma, and Knex ๐
It's like, 2023, and Node JS is one of the most hyped and fastest-growing stacks, but damn, there's still no clear answer to: "What good ORM / Query Builder should I choose?"
Until recently, I would have said: "They're all crap, go with Go (just kidding)"
TypeORM is buggy, unpredictable, unoptimized, and inconvenient (creating a class and then assigning values to parameters through ... what's the point of using TypeScript then?)
Prisma is not bad, but its syntax is so far from SQL that I'd call it "PrismaQL", and it's also unpredictable. The Rust binding required to run and interpret "PrismaQL" in SQL also consumes resources and is not available in some environments (e.g., serverless), and its own schema is limiting, making it hard to use any special PostgreSQL features.
Knex is more or less okay (I used it myself), but for some reason, there are almost no answers on StackOverflow, and most importantly, it has very poor TypeScript support (when .leftJoin returns T[] instead of T[] | null, that's a red flag for me).
After a long search and many doubts, the answer has finally been found!!!
**๐ **Kysely **๐
**It's a truly amazing Query Builder:
โ Its typing is incredibly strong: .with, subquery, json_agg, parametric condition, CASE WHEN โ all of this and much more is automatically and correctly typed.
โ Its syntax is very intuitive and similar to SQL (the syntax for expressions and predicates is the best I've seen).
โ It only needs type introspection from the database to start working (we use kysely-codegen), so it's very easy to integrate into any existing project (we're using it in new features and refactoring old ones, while legacy code still uses TypeORM / Knex).
โ It's super easy to extend column introspection with custom types (e.g., branded types).
โ You can fully customize the connection pool (we simply reuse the pool from TypeORM itself for integration into our project).
In short, if you want a cool Query Builder, I can now 100% recommend Kysely.
P.S.
I've been sick for the past couple of months, but I'm finally recovering, so I'll start writing more posts gradually. We've recently launched a large High Load project and are gradually transferring the load from our legacy system.
So, wait for some powerful content ๐ช
#nodejs #ts #orm #postgresql #top #hot