Registry / database / kysely

kysely

JSON →
library0.29.2jsnpmunverified

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 kysely
INSTALL
IMPORT
SIG · KYSELY
K
kysely
databasejavascriptv0.29.2
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Kysely
import { Kysely } from 'kysely'
import Kysely from 'kysely'
Kysely uses named exports. Default export is not available.
PostgresDialect
import { PostgresDialect } from 'kysely'
import { PostgresDialect } from 'kysely/dialects'
Dialects are exported from the main package since v0.21.
sql
import { sql } from 'kysely'
It's a helper for raw SQL expressions.

Initialize Kysely with PostgreSQL dialect, define a simple database schema, and execute a type-safe select query.

import { Kysely, PostgresDialect } from 'kysely' import { Pool } from 'pg' interface Person { id: number name: string age: number } interface Database { person: Person } const db = new Kysely<Database>({ dialect: new PostgresDialect({ pool: new Pool({ connectionString: process.env.DATABASE_URL }) }) }) async function main() { const person = await db .selectFrom('person') .select(['id', 'name']) .where('age', '>', 18) .executeTakeFirst() console.log(person) } main()
Debug
Known issues
breakingError: Cannot find module 'kysely' or its corresponding type declarations.
fix
Upgrade to v0.22+ or use 'kysely/dist/cjs' for CommonJS.
affects: <=0.21
gotchaType 'any' is not assignable to type 'never'.
fix
Define a proper database type interface for your tables.
affects: >=0.20
deprecatedMethod 'execute' is deprecated. Use 'executeTakeFirst' or 'executeTakeFirstOrThrow'.
fix
Replace .execute() with .executeTakeFirst() or .executeTakeFirstOrThrow() for single-row results.
affects: >=0.24
breakingconst db = new Kysely({ dialect: new SqliteDialect({ database: new Database('my.db') }) }) // TypeError: new Database is not a constructor
fix
Use synchronous SqliteDialect: new SqliteDialect({ database: new Database('my.db') }) or async callback for SQLite.
affects: >=0.24
gotchaProperty 'id' does not exist on type 'SelectExpression<DB, "person">'.
fix
Ensure your table type includes all columns you select. Use 'Selectable' wrapper from 'kysely' if needed.
affects: >=0.21
gotchaCannot query across tables without a join.
fix
Use .innerJoin() or .leftJoin() to join tables before selecting columns from them.
affects: >=0.20
gotchaKysely does not support automatic migrations like Prisma.
fix
Use a separate migration tool (e.g., 'kysely-codegen' or raw SQL files). Kysely is query-builder only.
affects: >=0.0
Errors
Common errors & fixes
Cannot find name 'Kysely'
Missing import or incorrect package install
fix
Install kysely: npm install kysely && import { Kysely } from 'kysely'
Type 'PostgresDialect' is not generic.
Using old import path or wrong version
fix
Upgrade to v0.21+ and import from 'kysely' directly.
Method 'executeTakeFirst' does not exist on type 'SelectQueryBuilder<...>'.
Using version <0.24 where executeTakeFirst was not introduced
fix
Upgrade to v0.24+ or use .execute() and handle arrays manually.
const pool = new Pool({ connectionString: process.env.DATABASE_URL }) // Pool is not defined
Missing pg package or import
fix
Install pg: npm install pg && import { Pool } from 'pg'
Error: The 'dialect' option is required.
Forgot to provide a dialect when creating Kysely instance
fix
Add dialect: new PostgresDialect({...}) (or other dialect) to the constructor.
Upgrade
Version history
0.29.2latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
8 hits · last 30 days
node
6
Amazon
1
Resources
packagekysely
kysely — npm install kysely · libregistry