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 install kysely
yarn add kysely
pnpm add kysely
Import
import { Kysely, PostgresDialect } from 'kysely';Quick Example
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
| Package | kysely |
| Category | Database |
| Weekly Downloads | 300K+ |
| License | MIT |
| Install | npm install kysely |
Related Packages
Drizzle ORM is a TypeScript ORM that provides a SQL-like query builder with full type safety, zero o…
Knex.js is a batteries-included SQL query builder for Node.js that supports PostgreSQL, MySQL, Maria…
Prisma is a next-generation Node.js and TypeScript ORM that provides a declarative data modeling lan…
pg (node-postgres) is the standard PostgreSQL client for Node.js, providing low-level access to Post…
Slonik is a Node.js PostgreSQL client with strict types, detailed logging, and assertions that encou…
Browse npm Packages by Category
Explore our reference of 200 popular npm packages with install commands, examples, and quick-start guides.