Kysely

Type-safe TypeScript SQL query builder for Postgres, MySQL and SQLite, with types inferred from your database schema.

Works with AI agents:llms.txt
Ask your AI about this, with this page as the source:ChatGPT ↗Claude ↗Perplexity ↗

Kysely is a TypeScript library for building SQL queries with full type checking. It is not an ORM: you think in tables and joins, but the compiler knows which tables and columns are in scope at each point of a query and what shape the result rows will have.

The model is small. You give the Kysely constructor a TypeScript interface describing your database's tables, plus a dialect, the adapter for one database engine. Built-in dialects cover PostgreSQL, MySQL, SQL Server, SQLite and PGlite, and community dialects add Postgres.js, serverless drivers for PlanetScale and TiDB, Cloudflare Durable Objects and others. Queries are chained method calls that compile to SQL. Kysely infers columns and aliases even through subqueries and CTEs; a sql template tag covers the rest.

What you get: transactions, including controlled ones with savepoints; helpers such as jsonArrayFrom that fetch nested objects and arrays in a single query; a plugin system that hooks into query compilation and results; and a built-in migrator that runs ordered up and down functions. It is mainly developed for Node.js but also runs on Deno, Bun and in browsers, where it can compile SQL without a connection.

Limits: Kysely has no relations or models, so no automatic eager loading or change tracking. It does not create your schema types for you either; you write them by hand or generate them with third-party tools such as kysely-codegen or prisma-kysely. Migrations are code you write, not diffs generated from a schema.

Where it fits

How Kysely itself is built

1 tools, from its own code, website and Product Hunt page.

Who uses it

No maker's live product on record yet, and 39 open-source projects that declare it in their code.

We haven't found a maker's live product that uses Kysely yet — only the open-source projects below, which declare it in their code.

Open source: a project that declares Kysely as a dependency in its public code — verifiable, but not necessarily a live product.

Loved and watch-outs

Themes that recur in makers' words and Hacker News comments, each linked to what it summarises.

Most loved
  • It is a thin, SQL-shaped query builder with unusually strong TypeScript typing, so you keep writing SQL without hiding it behind an ORM. HNHN 2HN 3HN 4
  • Queries compose well, which handles dynamic filters and even serves as the engine for other ORMs. HNHN 2HN 3
  • It sits alongside Prisma or plain SQL schemas for performance-critical queries and SQL features an ORM does not support. HNHN 2HN 3HN 4
  • Teams moving off heavier ORMs like TypeORM saw big gains in query speed and memory use. HNHN 2
Watch-outs
  • Not being an ORM, it does not generate migrations or offer declarative schemas, and rows still need mapping into objects. HNHN 2HN 3
  • Complex queries are harder to translate into builder calls than to write in SQL directly. HNHN 2
  • Support varies by dialect; the ClickHouse extension is immature and features like savepoints depend on the dialect. HNHN 2

Reliability and open issues

Most wanted on GitHubOpen on 2026-10-04 in kysely-org/kysely, with activity in the last year — issues and feature requests by 👍.

Who switches

Public pull requests on GitHub since Oct 2024 whose title says "X to Y" — real code changes moving a project from one tool to another, by developers in general. Open a row to see the pull requests.

Prisma → Kysely10 PRs
Drizzle ORM → Kysely5 PRs
Kysely → Drizzle ORM6 PRs

Alternatives to Kysely

All alternatives by situation →

Questions makers ask about Kysely

Which databases does Kysely support?

Built-in dialects cover PostgreSQL, MySQL, Microsoft SQL Server, SQLite and PGlite. Community dialects add Postgres.js, SingleStore, the PlanetScale and TiDB serverless drivers, Cloudflare Durable Objects, AWS RDS Data API, ClickHouse and more. source ↗

Do I have to write the database types by hand?

You can, but Kysely recommends generating them for production apps with third-party tools; kysely-codegen introspects a live database, prisma-kysely reads an existing Prisma schema, and kanel-kysely covers PostgreSQL. source ↗

Can I load related rows like an ORM?

Kysely has no relations, but helpers such as jsonArrayFrom and jsonObjectFrom fetch nested arrays and objects in one query. They may not work with third-party dialects that return JSON as strings. source ↗

How do migrations work?

Each migration exports up and down functions that receive a Kysely instance and run in alphanumeric order of their names; Kysely errors if a new migration sorts before already-run ones unless you enable allowUnorderedMigrations. Migrations should not import your app code, so they stay fixed in time. source ↗

Does it run outside Node.js?

Yes. Kysely is mainly developed for Node.js but also runs on Deno, Bun and other JavaScript environments, and in browsers it can compile queries without a database connection. source ↗

What if the query builder cannot express my query?

Use the sql template tag to write raw SQL fragments, which can be mixed into builder queries, as an escape hatch for cases that cannot be typed at compile time. source ↗

Is Kysely free?

Yes — it is free, open-source software.

Is Kysely open source or self-hostable?

Open source, and you can self-host it. source ↗

Can AI coding agents work with Kysely?

It serves an llms.txt docs index.

Who uses Kysely?

No maker's live product we track yet; 39 open-source projects declare it in their code. source ↗