Kysely dialect for PostgreSQL using the Postgres.js client
npm install kysely-postgres-js!A Kysely-branded yellow duck canoeing with a Postgres.js-branded grey elephant in the river





!GitHub contributors

###### Join the discussion ⠀⠀⠀⠀⠀⠀⠀


kysely-postgres-js offers a Kysely dialect for PostgreSQL that supports the Postgres.js client library (version >= 3.4) and Bun's (version >= 1.2) SQL native binding.
This dialect should not be confused with Kysely's core PostgreSQL dialect, which supports the significantly more adopted pg client library and Neon's WebSockets Pool instead. Both of these dialects are maintained by members of the Kysely core team and are production ready.
``bash`
npm install kysely-postgres-js postgres kysely
`bash`
pnpm add kysely-postgres-js postgres kysely
`bash`
yarn add kysely-postgres-js postgres kysely
`bash`
deno add npm:kysely-postgres-js npm:postgres npm:kysely
`bash`
bun add kysely-postgres-js kysely
`ts
import { type GeneratedAlways, Kysely } from 'kysely'
import { PostgresJSDialect } from 'kysely-postgres-js'
import postgres from 'postgres'
interface Database {
person: {
id: GeneratedAlways
first_name: string | null
last_name: string | null
age: number
}
}
const db = new Kysely
dialect: new PostgresJSDialect({
postgres: postgres({
database: 'test',
host: 'localhost',
max: 10,
port: 5434,
user: 'admin',
}),
}),
})
const people = await db.selectFrom("person").selectAll().execute();
`
`ts
import { SQL } from 'bun'
import { type GeneratedAlways, Kysely } from 'kysely'
import { PostgresJSDialect } from 'kysely-postgres-js'
interface Database {
person: {
id: GeneratedAlways
first_name: string | null
last_name: string | null
age: number
}
}
const db = new Kysely
dialect: new PostgresJSDialect({
postgres: new SQL({
database: 'test',
host: 'localhost',
max: 10,
port: 5434,
user: 'admin',
}),
}),
})
const people = await db.selectFrom("person").selectAll().execute();
``