Skip to content

PGlite

Embed a lightweight WASM Postgres with real-time, reactive bindings.

PGlite website ↗   GitHub repo ↗

Use cases

PGlite is a lightweight WASM Postgres build, packaged into a TypeScript library for the browser, Node.js, Bun and Deno.

PGlite repl screenshot

PGlite allows you to run Postgres in the browser, Node.js and Bun, with no need to install any other dependencies. It is only 2.6mb gzipped.

js
import { PGlite } from "@electric-sql/pglite";

const db = new PGlite();
await db.query("select 'Hello world' as message;");
// -> { rows: [ { message: "Hello world" } ] }

It can be used as an ephemeral in-memory database, or with persistence either to the file system (Node/Bun) or indexedDB (Browser).

How does it work?

Unlike previous "Postgres in the browser" projects, PGlite does not use a Linux virtual machine - it is simply Postgres in WASM, compiled using Emscripten. It provides a mechanism for dynamic extension loading, debug tooling and an in-browser repl.

How do I use it?

See the website and repo for more details:

PGlite website ↗   GitHub repo ↗