prisma-pglite-bridge
v1.1.0
Published
In-process PGlite bridge for Prisma — zero-TCP, zero-Docker PostgreSQL
Maintainers
Readme
prisma-pglite-bridge
In-process PGlite bridge for Prisma. Replaces the TCP socket in
pg.Client with a Duplex stream that speaks PostgreSQL wire protocol
directly to PGlite's WASM engine.
Install
Requires Prisma 7+ and Node.js 20+.
pnpm add -D prisma-pglite-bridge @electric-sql/pglite @prisma/adapter-pg pgThe last three are peer dependencies you may already have.
TypeScript users also need @types/pg.
Quickstart
import { PGliteBridge, pushMigrations } from 'prisma-pglite-bridge';
import { PrismaClient } from '@prisma/client';
import seed from './seed.ts'; // user-provided: (prisma: PrismaClient) => Promise<void>
const bridge = new PGliteBridge();
// Have prisma/migrations/? Use pushMigrations (shown).
// Only schema.prisma? Use pushSchema instead — see docs/api.md.
await pushMigrations(bridge.pglite, { migrationsPath: './prisma/migrations' });
const prisma = new PrismaClient({ adapter: bridge.adapter });
await seed(prisma);
await bridge.snapshotDb();
beforeEach(() => bridge.resetDb());snapshotDb() captures the seeded state once. resetDb() in
beforeEach then restores each test to that snapshot — fast,
deterministic, no re-seeding per test. Skip the snapshot/reset
pair if your tests are read-only or you want state to carry
over.
That's it. Run prisma migrate dev first to generate migration
files. No Docker, no database server — works in GitHub Actions,
GitLab CI, and any environment where Node.js runs.
For projects without a prisma/migrations directory (test
fixtures, prototypes), see Populating the
database for the
pushSchema alternative.
Running the Prisma CLI against this bridge (shadow DB for
migrate dev, psql, SQL GUIs)? See
PGliteServer for the TCP/Unix-socket front.
Documentation
- API reference — exports, options, return values, fs-sync policy.
- Cookbook — Vitest / Jest setup, per-test isolation, seed sharing, extensions, persistent dev database, clean shutdown.
PGliteServer— TCP / Unix-socket front for PGlite. Use for the Prisma CLI shadow database,psql, and SQL GUIs.- Stats and diagnostics —
stats()snapshots andnode:diagnostics_channelevent streams. - Troubleshooting & limitations —
known issues (PGlite version mismatch, WASM
ExperimentalWarning) and runtime constraints.
License
MIT
