Kysely is a type-safe and autocompletion-friendly TypeScript SQL query builder for Node.js, version 0.29.x (released Nov 2024). It provides a fluent API to build and execute SQL queries against PostgreSQL, MySQL, SQLite, and MSSQL databases with full TypeScript support. Unlike ORMs like TypeORM or Prisma, Kysely gives you direct control over SQL while preventing syntax errors and SQL injection at compile time. It is actively maintained with monthly releases.
npm install kyselyNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Initialize Kysely with PostgreSQL dialect, define a simple database schema, and execute a type-safe select query.
Upgrade to v0.22+ or use 'kysely/dist/cjs' for CommonJS.
Define a proper database type interface for your tables.
Replace .execute() with .executeTakeFirst() or .executeTakeFirstOrThrow() for single-row results.
Use synchronous SqliteDialect: new SqliteDialect({ database: new Database('my.db') }) or async callback for SQLite.Ensure your table type includes all columns you select. Use 'Selectable' wrapper from 'kysely' if needed.
Use .innerJoin() or .leftJoin() to join tables before selecting columns from them.
Use a separate migration tool (e.g., 'kysely-codegen' or raw SQL files). Kysely is query-builder only.
Install kysely: npm install kysely && import { Kysely } from 'kysely'Upgrade to v0.21+ and import from 'kysely' directly.
Upgrade to v0.24+ or use .execute() and handle arrays manually.
Install pg: npm install pg && import { Pool } from 'pg'Add dialect: new PostgresDialect({...}) (or other dialect) to the constructor.No dependency data recorded yet.