Registry / database / kysely-postgres-js

kysely-postgres-js

JSON →
library3.0.0jsnpmunverified

Kysely dialect for PostgreSQL using the Postgres.js client library (version >= 3.4) or Bun's native SQL binding (Bun >= 1.2). This library is the official dialect maintained by the Kysely core team, offering a type-safe SQL query builder for PostgreSQL. Unlike Kysely's core pg dialect, this targets the modern Postgres.js and Bun runtimes. Current stable version is 3.0.0, released with frequent updates. Key differentiators: full TypeScript support, seamless integration with Kysely's type safety, and support for both Node.js and Bun.

npm install kysely-postgres-js
INSTALL
IMPORT
SIG · KYSELY-POSTGRES-JS
K
kysely-postgres-js
databasejavascriptv3.0.0
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.

PostgresJSDialect
import { PostgresJSDialect } from 'kysely-postgres-js'
const PostgresJSDialect = require('kysely-postgres-js')
ESM-only package; CJS require() will fail. TypeScript types included.
Kysely
import { Kysely } from 'kysely'
import { Kysely } from 'kysely-postgres-js'
Kysely is imported from the 'kysely' package, not from this dialect.
postgres
import postgres from 'postgres'
const postgres = require('postgres')
Postgres.js is ESM-only for Node.js; for Bun, use new SQL() from 'bun' instead.

Creates a Kysely instance with PostgresJSDialect, defines a simple schema, and selects all rows from the person table.

import { type GeneratedAlways, Kysely } from 'kysely' import { PostgresJSDialect } from 'kysely-postgres-js' import postgres from 'postgres' interface Database { person: { id: GeneratedAlways<number> first_name: string | null last_name: string | null age: number } } const db = new Kysely<Database>({ dialect: new PostgresJSDialect({ postgres: postgres({ database: 'test', host: process.env.DB_HOST ?? 'localhost', max: 10, port: 5432, user: process.env.DB_USER ?? 'admin', password: process.env.DB_PASSWORD ?? '', }), }), }) const people = await db.selectFrom('person').selectAll().execute() console.log(people)
Debug
Known issues
breakingVersion 3.0.0 drops support for Node < 20 and Bun < 1.2.
fix
Update your runtime to Node >=20 or Bun >=1.2.
affects: >=3.0.0
gotchaThe 'postgres' peer dependency is required for Node.js but not for Bun. Using both might cause conflicts.
fix
For Bun, import SQL from 'bun' instead of installing the 'postgres' npm package.
affects: >=1.0.0
gotchaThe dialect expects the 'postgres' client instance directly, not a pool or URL string.
fix
Pass the return value of postgres({...}) (a Postgres.js connection instance) as the 'postgres' option.
affects: >=1.0.0
deprecatedUsing require() to import this package will fail because it is ESM-only.
fix
Use ES module imports with 'import' or set 'type': 'module' in package.json.
affects: >=2.0.0
Errors
Common errors & fixes
Error [ERR_REQUIRE_ESM]: require() of ES Module .../node_modules/kysely-postgres-js/src/index.js not supported.
The package is ESM-only; CommonJS require() is not supported.
fix
Use import syntax: import { PostgresJSDialect } from 'kysely-postgres-js'
error: Could not resolve: kysely
Missing required peer dependency 'kysely'.
fix
Install kysely: npm install kysely
TypeError: Class extends value undefined is not a constructor or null
The peer dependency 'postgres' is missing or incorrect version (needs >=3.4).
fix
Install postgres: npm install postgres (version >=3.4)
Error: Cannot find module 'kysely-postgres-js'
Package not installed or not in node_modules.
fix
Install kysely-postgres-js: npm install kysely-postgres-js
Upgrade
Version history
3.0.0latest on npm
Audit
Dependencies
kyselyrequiredpeer dependency: Kysely query builder framework
postgresoptionalpeer dependency: Postgres.js client library (optional for Bun runtime)
Agent activity
6 hits · last 30 days
node
6
Resources
kysely-postgres-js — npm install kysely-postgres-js · libregistry