Kysely Type-Safe SQL Builder

Kysely Type-Safe SQL Builder

kysely.dev

2

About this website

Kysely is a type-safe SQL query builder for TypeScript that provides compile-time verification of database queries while maintaining a thin abstraction layer over raw SQL. Created by Igal Klebanov and endorsed by Knex.js author Tim Griesser, the library generates SQL that closely mirrors what a developer would write manually, with a one-to-one mapping between builder method chains and the resulting query text. The type system flows database schema definitions through every method in the fluent API, enabling intelligent auto-completion for table names, column names, and function signatures directly in the editor. Type safety extends to result types, ensuring that SELECT queries return correctly typed rows, JOIN operations produce combined row types, and INSERT and UPDATE operations validate column values against their schema definitions. The builder supports the full range of SQL operations including SELECT with subqueries and CTEs, INSERT with conflict handling, UPDATE with returning clauses, DELETE, and MERGE statements. When the builder cannot express a particular query, raw SQL fragments can be embedded within structured queries while preserving type inference for parameters and results. Kysely ships with built-in dialect drivers for PostgreSQL, MySQL, Microsoft SQL Server, and SQLite including the PGlite in-browser variant. A community-driven dialect system allows third-party packages to add support for additional databases. The migration system provides up and down functions with transaction support, while a plugin architecture enables custom query transformations such as camelCase conversion. The library has zero runtime dependencies, works in Node.js, Deno, Bun, and browsers, and is tree-shakeable for minimal bundle impact.

Tags & Categories

Statistics

2
Views
0
Clicks
0
Like
0
Dislike

Comments

Log In to post a comment

No comments yet. Be the first!