Features
- End-to-end type-safe SQL query builder
- No code generation — pure TypeScript inference
- Supports PostgreSQL, MySQL, SQLite
- Plugin system for custom dialects
Pros
- True SQL with full TypeScript type safety
- No build step or code generation needed
- Lightweight and composable
Cons
- Not a full ORM — no migrations, models, or relations
- Requires defining database types manually
- Smaller ecosystem than Prisma or Drizzle
Overview
Kysely is a type-safe TypeScript SQL query builder that provides autocompletion and type checking for your SQL queries without code generation. You define your database schema as TypeScript types, and Kysely uses them to provide compile-time safety for every query.
Unlike full ORMs, Kysely focuses solely on query building. It doesn’t include migrations, model definitions, or relationship management. This makes it ideal for developers who want SQL’s full power with TypeScript’s type safety, without the abstractions of a traditional ORM.
When to Use
Kysely is the right choice when you want type-safe SQL without ORM abstractions, when you prefer writing SQL-like queries with TypeScript safety, or when combining with other tools for migrations and schema management. It’s popular as a Knex.js replacement for TypeScript projects.
Getting Started
npm install kysely pg
import { Kysely, PostgresDialect } from "kysely";
import { Pool } from "pg";
type Database = {
users: { id: number; name: string; email: string };
};
const db = new Kysely<Database>({
dialect: new PostgresDialect({ pool: new Pool() }),
});
const users = await db.selectFrom("users").selectAll().execute();