Skip to main content

Kysely

The type-safe SQL
query builder for TypeScript

Getting startedView on GitHub

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
Tim GriesserKnex.js creator, Cypress Staff Eng
👋 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
Orta TheroxEx-TypeScript team
👋 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
Niels Sandholt BuschMaersk SWE
We are using Kysely in production at Maersk inventory control!
Guðmundur Bjarni Olafsson's avatar picture
Guðmundur Bjarni OlafssonVercel Principal SWE
I made a strong recommendation internally for using Kysely for a greenfield service that's in the works. Looks very solid. 👌🏻
Catalin Pit's avatar picture
Catalin PitDocumenso SWE
Kysely is fantastic! We use it at @documenso with Prisma.
Dax "thdxr" Raad's avatar picture
Dax "thdxr" RaadSST core team, Terminal co-founder
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
Julius Marminge's avatar picture
Julius MarmingetRPC & create-t3-app core team
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.
Gal Schlezinger's avatar picture
Gal Schlezingerfnm creator, Vercel SWE
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.
Yusuke "yusukebe" Wada's avatar picture
Yusuke "yusukebe" WadaHono creator, Cloudflare DevRel
Kysely is great. D1 will be great. This is great.
Harminder Virk's avatar picture
Harminder VirkAdonisJS creator, Medusa SWE
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.
"pilcrow"'s avatar picture
"pilcrow"Lucia creator
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.
Ben Holmes's avatar picture
Ben HolmesAstro SWE
I really like Prisma for schemas and Kysely for querying. Drizzle feels... younger for schemas, but also quite nice
Theo "t3dotgg" Browne's avatar picture
Theo "t3dotgg" BrowneUploadthing creator, Ping.gg CEO
kysely is dope too. Drizzle and kysely are the frontrunners for "new db tools that really understand JS needs" atm
Shoubhit "nexxel" Dash's avatar picture
Shoubhit "nexxel" Dashcreate-t3-app author, Leapflow CTO
kysely is great btw
Lee "leerob" Robinson's avatar picture
Lee "leerob" RobinsonVercel VP Product
Type-safe SQL queries with PlanetScale and Kysely 😍
Nicholas Griffin's avatar picture
Nicholas Griffinsqs-consumer maintainer, BBC SWE
I don't actually like prisma that much, I prefer Kysely, not an ORM though.
Alberto "gimenete" Gimeno's avatar picture
Alberto "gimenete" GimenoRailway SWE
I'm a happy Kysely user. It's great to see that the code I'm writing now can work with serverless PostgreSQL now!
Guga Guichard's avatar picture
Guga Guichardstring-ts creator, Seasoned Partner
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.
Bereket "Bek Cru" Engida's avatar picture
Bereket "Bek Cru" Engidabetter-auth creator
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 + kysley is better than drizzle.
Ross Coundon's avatar picture
Ross Coundonleadent digital CTO
I particularly like Kysely here, it's a type-safe query builder and as such doesn't enforce the specifics of an ORM on you, therefore I feel, in the medium-to-long term, it'll save you the time and effort of working around ORM-specific and enforced structures/approaches
Johan Eliasson's avatar picture
Johan EliassonOneLab CTO
Instead of Prisma, I'm testing Kysely, Kysely Codegen, and Atlas. Works great.
R. Alex Anderson's avatar picture
R. Alex AndersonThorium Nova creator
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
Mehul MohanCodedamn Founder
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
Sam CookGamma.io SWE
Kysely is amazing.
Gannon Hall's avatar picture
Gannon HallAstro Labs Founder
Vercel just announced native Postgres support and published Prisma and Kysely templates. I like the DX of Prisma and the type safety of Kysely so I use both via prisma-kysely.
Alisson "thelinuxlich" C.Agiani's avatar picture
Alisson "thelinuxlich" C.AgianiOpensourcerer
Kysely is superior and with each release gets even more awesome
Marvin's avatar picture
MarvinIndie Hacker
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
Jiří "Capaj" ŠpácLangtail SWE
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