Kysely

6 min read Original article ↗

Show this to your boss!

Type-safety without compromises

Kysely's state-of-the-art, type-safe API provides precise result types and catches errors within queries at compile-time, giving high-performing teams the confidence to ship at greater velocity. Use `kysely-codegen` to make the database the source of types.

What you see is what you get

Kysely is a thin abstraction layer over SQL, crafted by SQL lovers for SQL lovers, focusing on familiarity through naming and structure, and predictability through 1:1 compilation. Teams proficient in SQL can pick up Kysely and be productive in minutes.

Write with great auto-completion

Your database schema types flow through Kysely's fluent API, offering a typing experience that's second only to full-blown database IDEs. Get intelligent, context-aware suggestions for functions, table names, and column names as you type.

Build SQL queries with unmatched depth

Kysely supports building a wide range of SQL queries, clauses, functions, and expressions, including SELECT, INSERT, UPDATE, DELETE, MERGE, WITH, and more. When needed, you can also use raw SQL strings, even within structured queries.

Query any SQL database

Kysely's community-driven dialect system makes it easy to implement support for any SQL database without waiting for the core team. It ships with official dialects for PostgreSQL, MySQL, MS SQL Server, and SQLite right out of the box.

Run anywhere

Kysely is lightweight, ships both CommonJS and ESM, has zero dependencies, and avoids any environment-specific APIs. It can run in any JavaScript environment, including Node.js, Deno, Bun, AWS Lambda, Cloudflare Workers, and browsers.

Take control over your migrations

Kysely includes optional up/down migration primitives, allowing you to move away from risky black box migration tools and write your own migrations. Use `kysely-ctl` to run your migrations directly in the terminal or within your CI/CD pipeline.

Extend with plugins

Kysely's plugin system allows you tap into the process, and modify queries before compilation and/or their results after execution. This opens up various use cases, such as transforming camelCase names to snake_case and vice versa.

What the internet is saying

Developers are loving Kysely for its simplicity and power.

Tim Griesser's avatar picture
👋 First just wanted to say this project looks awesome! Pretty close to what I wish Knex was if I started it now, with the affordances of modern TypeScript instead of 10 years ago when we were stuck in ES5 and Promises weren't even really an official language construct yet.
Orta Therox's avatar picture
👋 been using Kysely for a few days in Deno and Node, just wanted to say it's been going really well and it feels like a nice abstraction - kudos!
Niels Sandholt Busch's avatar picture
We are using Kysely in production at Maersk inventory control!
Lee "leerob" Robinson's avatar picture
Type-safe SQL queries with PlanetScale and Kysely 😍
Guðmundur Bjarni Olafsson's avatar picture
I made a strong recommendation internally for using Kysely for a greenfield service that's in the works. Looks very solid. 👌🏻
Marvin Hagemeister's avatar picture
We're using Kysely as an ORM here at Deno. It's quite neat.
Søren Bramer Schmidt's avatar picture
Kysely is great!
Yusuke "yusukebe" Wada's avatar picture
Kysely is great. D1 will be great. This is great.
Kevin "Egoist"'s avatar picture
Thank you kysely
Julius Marminge's avatar picture
Utterly astounded by how Kysely manages to make all of this typesafe. Seems like no matter how complex you get, it can infer it correctly.
Sean Brydon's avatar picture
We are using Kysely for some of our more complex queries in Cal.com where we needed more control of the sql generated.
Dax "thdxr" Raad's avatar picture
really excited to see Kysely get more attention - been banging this drum for a while and we've integrated pretty deeply with it at SST incidentally its codebase remains the best Typescript codebase I have ever seen - worth poking around
Gal Schlezinger's avatar picture
I love SQL, and I love migrations, most tools don't provide good migration tools and fine grained control like Kysely which is why it's my favorite.
Mathieu Acthernoene's avatar picture
Used in prod here, highly recommended
Ben Holmes's avatar picture
I really like Prisma for schemas and Kysely for querying. Drizzle feels... younger for schemas, but also quite nice
Bereket Engida's avatar picture
I don't think they have similar goals from what I see. Drizzle is more dedicated into marketing and having every user possible like prisma but kysely kinda just don't care about that for most part. And in my experience prisma + kysely is better than drizzle.
Peter Pistorius's avatar picture
Today I'll be adding persistence to Machinen using RedwookSDK's Durable Object database integration: It uses kysely under the hood. Typesafety is directly provided by migrations.
Harminder Virk's avatar picture
If not Lucid, Kysely is what I would recommend everyone use. It presents itself as a type-safe SQL query builder and delivers 100% on that promise.
Catalin Pit's avatar picture
Kysely is fantastic! We use it at @documenso with Prisma.
"pilcrow"'s avatar picture
Ok, so I'm not a big fan of Drizzle. I don't like how I have to import everything when declaring schemas and queries, and I just prefer the simplicity and the overall API of Kysely.
Theo "t3dotgg" Browne's avatar picture
kysely is dope too. Drizzle and kysely are the frontrunners for "new db tools that really understand JS needs" atm
Nicholas Griffin's avatar picture
I don't actually like prisma that much, I prefer Kysely, not an ORM though.
Shoubhit "nexxel" Dash's avatar picture
kysely is great btw
Guga Guichard's avatar picture
I've been seeing a lot of discussions about ORMs vs raw SQL. What about strongly typed SQL query builders? Kysely is in the sweet spot! Best DX with total freedom I've seen in decades.
Johan Eliasson's avatar picture
Instead of Prisma, I'm testing Kysely, Kysely Codegen, and Atlas. Works great.
Samuel Bodin's avatar picture
Im currently in love with Kysely, it has found the perfect balance/API imo
Endel Dreyer's avatar picture
i just use postgres + kysely and old school migrations as needed
Alberto "gimenete" Gimeno's avatar picture
I'm a happy Kysely user. It's great to see that the code I'm writing now can work with serverless PostgreSQL now!
R. Alex Anderson's avatar picture
Shout out to Kysely for adding extensive JSDoc comments above the methods. It makes it much easier to figure out how to use it the way I want without having to dig into the docs. (though the docs are vv good too)
Mehul Mohan's avatar picture
We went with query builder because we did not have more time to waste on ORMs. ORMs might be great but we have the technical capability to pull off just using a query builder. However, we type safety and sanitization for DX and security was a must - hence Kysely.
Sam Cook's avatar picture
Kysely is amazing.
Alisson "thelinuxlich" C.Agiani's avatar picture
Kysely is superior and with each release gets even more awesome
Marvin's avatar picture
I've been saying it many times already, but it's probably one of the best additions to my tech stack. I enjoy writing SQL since I know Kysely 😆
Jiří "Capaj" Špác's avatar picture
Kysely is awesome

Try it out for yourself!

Modify the query on the left and view the generated SQL on the right.

Looking for code examples?

From finding a single record to complex joins, our docs have examples to get you started quickly.

Jump right in