PACKAGE · ORM & DATABASE

kysely

Type safe SQL query builder

WEEKLY DOWNLOADS 3.5M
STARS 13.9K
FORKS 414
OPEN ISSUES 163
GZIP SIZE 39.8 kB
UNPACKED SIZE 1.7 MB
DEPENDENCIES 1
LAST UPDATED 4mo ago
DOWNLOAD TRENDS

kysely downloads — last 12 months

Download trends for kysely1 download series from Jun 2025 to May 2026. Use left and right arrow keys to inspect monthly values.06.1M12.2M18.3M24.4MJun 2025SepDecMarMay 2026
kysely
ABOUT KYSELY

Kysely is a type-safe SQL query builder designed to bring compile-time safety to your database interactions within TypeScript projects. It tackles the common problem of runtime SQL errors and type mismatches that often plague ORMs or raw SQL string constructions, by leveraging TypeScript's type system to ensure queries are valid before they are executed.

The core philosophy of Kysely revolves around providing a developer experience as close to raw SQL as possible while embedding robust type safety. It is primarily built for developers who prefer writing SQL-like queries but want the assurance that their queries align with their database schema and TypeScript types, avoiding common pitfalls like incorrect column names or data types during runtime.

Kysely achieves its type safety through a fluent API that mirrors SQL syntax. Key patterns include defining a `Database` interface that maps to your tables and columns, and then using methods like `select`, `from`, `where`, and `join` which are statically checked against this interface. It also features type inference for query results, meaning the output of a query will have a precise TypeScript type corresponding to the selected columns.

Integration points for Kysely are broad, supporting various JavaScript and TypeScript environments including Node.js, Deno, and Bun. It works seamlessly with popular database drivers for PostgreSQL, MySQL, SQLite, and Microsoft SQL Server. While not a full ORM like Prisma or TypeORM, Kysely can be integrated into existing frameworks and applications that require direct SQL control with enhanced safety.

With 5.5 million weekly downloads and 13.8K GitHub stars, Kysely demonstrates significant community adoption and stability. Its unpacked size is 1.7 MB, with a gzipped bundle size of only 39.8 kB, making it a relatively lightweight addition to projects concerned with bundle size. The project is actively maintained, with the last update being May 16, 2026, though this date implies it's a future projection.

One potential limitation to consider is that Kysely focuses on query building and does not handle migrations or schema management out-of-the-box. Developers will need to use separate tools for schema evolution. Additionally, while it supports many SQL databases, complex or highly vendor-specific SQL features might require dropping down to raw SQL execution, which bypasses some of Kysely's compile-time guarantees.

WHEN TO USE
  • When you need to write SQL queries in TypeScript but want compile-time validation of table/column names and types, using Kysely's `select` and `where` clauses.
  • For projects using Node.js, Deno, or Bun that interact with PostgreSQL, MySQL, SQLite, or Microsoft SQL Server and require type safety.
  • When building complex query logic involving multiple joins and aggregations, leveraging Kysely's fluent API for better readability and safety.
  • To reduce runtime errors caused by incorrect SQL syntax or type mismatches, by relying on Kysely's static analysis of your queries against a defined `Database` schema interface.
  • When you want a query builder that feels close to writing raw SQL, but with the added benefit of TypeScript type checking throughout the query construction process.
  • For developers who prefer explicit SQL structure over a full ORM's abstractions, but still desire compile-time safety for database operations.
WHEN NOT TO USE
  • If you only need simple CRUD operations and a full ORM with built-in migration management provides a more integrated solution.
  • When working in environments where TypeScript is not used, as Kysely's primary benefit is compile-time type safety which would be absent.
  • If your database interactions are extremely simple, like fetching configuration values, where the overhead of defining a `Database` interface might outweigh the benefits.
  • For projects that rely heavily on highly advanced, database-specific SQL features not easily expressible through Kysely's fluent API, potentially requiring raw SQL escapes.
  • If you require automated schema migrations and schema management directly integrated into your database client; consider a solution that offers these features alongside query building.

CORRECTIONS

Spot wrong data here?

A short note helps us fix it.

Anonymous · No account · No email back

COMPARISONS 6
kysely vs sequelize ★ 30.4K · 1.4M/wk kysely vs mongoose ★ 27.5K · 2.8M/wk kysely vs knex ★ 20.3K · 2.0M/wk kysely vs drizzle-orm ★ 34.7K · 5.5M/wk kysely vs prisma ★ 46.2K · 6.5M/wk kysely vs typeorm ★ 36.5K · 2.1M/wk