Overview
Kysely is a TypeScript SQL query builder started in 2021 by Sami Koskimäki (also the author of Objection.js) and now led by him and Igal Klebanov, under the MIT licence. It was inspired by Knex but built around modern TypeScript: it only lets you reference tables and columns that are in scope for the query you are writing, and the result type contains exactly the selected columns and aliases, including those from subqueries and CTEs.
There are no entities, models or relation declarations. Nested data is loaded with helpers such as jsonArrayFrom that build correlated subqueries, so one round trip returns typed nested JSON. You supply a Database type yourself or generate it from a live database with the community kysely-codegen tool; the Prisma generator prisma-kysely is another route.
Kysely ships dialects for PostgreSQL, MySQL, SQL Server, SQLite and PGlite, and community dialects cover others such as D1, PlanetScale and libSQL. A built-in Migrator runs up and down migrations written in TypeScript, but it does not diff schemas or generate migrations for you.
Pricing and plans
| Plan | Price | What you get |
|---|---|---|
| Kysely | $0 | MIT licence |
What it does
- Scope-aware typing
- Only tables and columns visible at that point of the query autocomplete; misspelled columns are compile errors.
- Precise result types
- Result rows contain exactly the selected columns and aliases, inferred through joins, subqueries and CTEs.
- Composable expressions
- Query fragments can be extracted into plain typed functions and reused across queries.
- Migrator
- Runs up/down migration files in order, with an option to allow unordered migrations for teams.
- Plugins
- Transform queries before compilation and results after execution, for example camelCase to snake_case.
- Runs anywhere
- No runtime dependencies; works in Node, Deno, Bun, AWS Lambda, Cloudflare Workers and browsers.
Strengths and limitations
Strengths
- Predictable one-to-one SQL output, with little hidden behaviour
- Very precise TypeScript inference, including aliases and subqueries
- Zero runtime dependencies; suitable for edge runtimes
- Used as the SQL layer inside other tools, including MikroORM 7
Limitations
- Not an ORM: no entities, relation mapping, change tracking or lazy loading
- Migrations are written by hand; there is no schema diffing or migration generation
- Database types must be written by hand or generated with a separate community tool (kysely-codegen)
- Complex type inference can slow the TypeScript compiler on very large queries
Who it suits
Good for
- TypeScript developers who know SQL and want compile-time checks
- Serverless and edge apps that need a small dependency-free layer
- Replacing Knex in an existing codebase
Look elsewhere if
- Teams that want an ORM with models and generated migrations (Prisma, Drizzle, MikroORM)
- Developers who do not want to write SQL-style queries
Alternatives to Kysely
| Tool | From | Free option | Stages |
|---|---|---|---|
| Dapper .NET micro-ORM | — | ||
| SQLx Async Rust SQL toolkit | — | ||
| Bun (Go ORM) SQL-first Go ORM | — | ||
| Eloquent ORM Active Record ORM for Laravel | — | ||
| sqlc SQL-to-code compiler | — | ||
| Drizzle ORM SQL-like TypeScript ORM | — |
Questions
Is Kysely an ORM?
No. It is a type-safe SQL query builder with no models or relation mapping; nested data is loaded with JSON subquery helpers.
How do I get types for my database in Kysely?
Write a Database interface by hand or generate it from a live database with kysely-codegen.
Does Kysely support migrations?
Yes, it has a Migrator that runs up and down migration files you write; it does not generate them.
Kysely vs Drizzle: which should I use?
Both are SQL-shaped; Drizzle adds schema-in-code, a relational API and generated migrations, while Kysely stays a pure query builder with types from your database.
Sources read for this page