🗄️
Database300K+/wkMIT

kysely

Kysely is a type-safe TypeScript SQL query builder that provides autocompletion, type checking, and IntelliSense for SQL queries without code generation. Kysely

Installation

npm
npm install kysely
yarn
yarn add kysely
pnpm
pnpm add kysely

Import

ESM
import { Kysely, PostgresDialect } from 'kysely';

Quick Example

usage
import { Kysely, PostgresDialect } from 'kysely';

interface Database {
  users: { id: number; name: string; email: string };
}

const db = new Kysely<Database>({ dialect: new PostgresDialect({ pool }) });

const users = await db
  .selectFrom('users')
  .select(['id', 'name'])
  .where('name', 'like', '%Ali%')
  .execute();

About kysely

Kysely is a type-safe TypeScript SQL query builder that provides autocompletion, type checking, and IntelliSense for SQL queries without code generation. Kysely infers types from a database interface you define, providing compile-time validation that table names, column names, and operations are correct. The query builder API closely mirrors SQL syntax: db.selectFrom('users').select(['id', 'name']).where('age', '>', 18).orderBy('name').execute(). This approach gives you the full power of SQL with the safety of TypeScript. Kysely supports PostgreSQL, MySQL, SQLite, and MSSQL through dialect-specific drivers, and provides transactions, CTEs (WITH clauses), subqueries, joins, aggregations, and insert/update/delete operations all with complete type inference. The library generates efficient SQL without unnecessary subqueries or wrapping. Kysely's plugin system supports query logging, camelCase to snake_case conversion, and result transformation. The migration system provides type-safe migration files. Kysely is particularly well-suited for developers who want SQL-like control with TypeScript safety, sitting between raw SQL (no type safety) and full ORMs (too much abstraction) in the spectrum of database tools.

Quick Facts

Packagekysely
CategoryDatabase
Weekly Downloads300K+
LicenseMIT
Installnpm install kysely

Related Packages

Browse npm Packages by Category

Explore our reference of 200 popular npm packages with install commands, examples, and quick-start guides.