Registry / database / kysely-pglite

kysely-pglite

JSON →
library0.6.1jsnpmunverified

Kysely dialect for PGlite (Postgres WASM) that enables type-safe SQL queries in Node.js and the browser. Current stable version is 0.6.1. It wraps PGlite's embedded PostgreSQL via WebAssembly, allowing zero-config, in-memory or persisted databases. Unlike raw PGlite, it provides Kysely's query builder interface, integrates with live queries via KyselyLive, and includes a CLI for TypeScript type generation by running migrations or scanning a PGlite data directory.

npm install kysely-pglite
INSTALL
IMPORT
SIG · KYSELY-PGLITE
K
kysely-pglite
databasejavascriptv0.6.1
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.

KyselyPGlite
import { KyselyPGlite } from 'kysely-pglite'
const KyselyPGlite = require('kysely-pglite')
ESM-only – no CommonJS support
KyselyLive
import { KyselyLive } from 'kysely-pglite'
import KyselyLive from 'kysely-pglite'
Named export, not default. Requires @electric-sql/pglite live extension
type DB
import type { DB } from './path/to/generated/schema'
import { DB } from 'kysely-pglite'
Type is generated by the CLI, not from the package itself

Shows how to create an in-memory PGlite instance, define a table, insert data, and query using Kysely.

import { Kysely } from 'kysely' import { KyselyPGlite } from 'kysely-pglite' async function main() { const { dialect } = await KyselyPGlite.create() const db = new Kysely<{}>({ dialect }) await db.schema .createTable('user') .addColumn('id', 'serial', (cb) => cb.primaryKey()) .addColumn('name', 'text', (cb) => cb.notNull()) .execute() const { rows } = await db .insertInto('user') .values({ name: 'Alice' }) .returning(['id', 'name']) .execute() console.log(rows) } main()
Debug
Known issues
breakingKyselyPGlite.create() is async – do not use new KyselyPGlite() directly as it may not be fully initialized.
fix
Always await KyselyPGlite.create() or ensure the constructor is only used after explicit setup.
affects: >=0.3.0
deprecatedDirect use of new KyselyPGlite() without arguments is deprecated; prefer KyselyPGlite.create().
fix
Replace new KyselyPGlite() with await KyselyPGlite.create().
affects: >=0.5.0
gotchaThe generated types file (via CLI) must be imported manually – it is not re-exported from the package.
fix
Generate types with npx kysely-pglite <path> --outFile ./types.ts, then import { DB } from './types'.
affects: >=0.1.0
gotchaPGlite live queries require the `@electric-sql/pglite/live` extension to be enabled; KyselyLive depends on it.
fix
Pass { extensions: { live: true } } to KyselyPGlite.create() options.
affects: >=0.6.0
Errors
Common errors & fixes
TypeError: KyselyPGlite is not a constructor
Using require() in an ESM-only package
fix
Change to import { KyselyPGlite } from 'kysely-pglite'
Error: Cannot find module '@electric-sql/pglite'
Missing peer dependency @electric-sql/pglite
fix
Install @electric-sql/pglite alongside kysely-pglite
error: relation "user" does not exist
Querying a table before creating it via migrations or schema builder
fix
Run schema.createTable('user', ...).execute() before inserting
Upgrade
Version history
0.6.1latest on npm
Audit
Dependencies
@electric-sql/pgliterequiredPeer dependency – the underlying in-browser Postgres engine
kyselyrequiredPeer dependency – the query builder library for which this provides a dialect
Agent activity
9 hits · last 30 days
node
8
Resources
kysely-pglite — npm install kysely-pglite · libregistry