Kysely: Type-Safe SQL Query Builder
Kysely (pronounced “Key-Seh-Lee”) is a type-safe and autocompletion-friendly TypeScript SQL query builder. Inspired by Knex.js, Kysely brings the power of SQL with the safety of TypeScript to your database operations.Type-Safe Queries
Kysely ensures you only reference tables and columns that exist in your database schema at compile time.
Full Autocompletion
Get intelligent autocompletion for table names, column names, and even inferred aliases.
Universal Runtime
Works seamlessly with Node.js, Deno, Bun, Cloudflare Workers, and web browsers.
Why Kysely?
Kysely makes sure you only refer to tables and columns that are visible to the part of the query you’re writing. The result type only has the selected columns with correct types and aliases. As an added bonus, you get autocompletion for all that stuff.Intelligent Type Inference
Through the pure magic of modern TypeScript, Kysely is able to parse aliases and add them to the result row type. Kysely can infer column names, aliases, and types from:- Selected subqueries
- Joined subqueries
WITHstatements- Complex expressions
- And much more
Supported Databases
Kysely supports all major SQL databases with first-class TypeScript support:PostgreSQL
Full support with the
PostgresDialect using the pg driverMySQL
Full support with the
MysqlDialect using the mysql2 driverSQLite
Full support with the
SqliteDialect using the better-sqlite3 driverMS SQL Server
Full support with the
MssqlDialect using the tedious driverGet Started
Installation
Install Kysely with npm, yarn, pnpm, or bun
Quick Start
Get up and running with your first query in minutes
API Reference
Comprehensive API documentation with examples
Key Features
Schema Migrations
Kysely includes a powerful migration system for managing database schema changes:Escape Hatches
When you need raw SQL for complex queries, Kysely provides thesql template tag:
All API documentation is written in the TypeScript definition files. Simply hover over any method in your IDE to see comprehensive documentation.
Community and Support
- Discord: Join our Discord server for help and discussions
- GitHub: Report issues or contribute on GitHub
- Documentation: Visit kysely.dev for comprehensive guides