electric-sql /pglite

Embeddable Postgres with real-time, reactive bindings.

★ 16,277⑂ 475👁 64⑃ 725● 443▤ 577
TypeScriptApache-2.0Created 2024-02-19pglite.dev
Download: @electric-sql/[email protected]@electric-sql/[email protected] ↓0.0.92026-11-10
+2
Daily
16,277
stars
475
forks
64
watchers
725
prs
443
issues
577
releases

README

PGlite - the WASM build of Postgres from Electric.
  Build reactive, realtime, local-first apps directly on Postgres.



  
   --
  
  
  
  
  


 PGlite - Postgres in WASM

!PGlite

PGlite is a WASM Postgres build packaged into a TypeScript client library that enables you to run Postgres in the browser, Node.js, Bun and Deno, with no need to install any other dependencies. It is only 3mb gzipped and has support for many Postgres extensions, including pgvector and PostGIS.

javascript
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/Deno) or indexedDB (Browser).

Unlike previous "Postgres in the browser" projects, PGlite does not use a Linux virtual machine - it is simply Postgres in WASM.

For full documentation and user guides see pglite.dev.

 Browser

It can be installed and imported using your usual package manager:

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

or using a CDN such as JSDeliver:

js
import { PGlite } from "https://cdn.jsdelivr.net/npm/@electric-sql/pglite/dist/index.js";


Then for an in-memory Postgres:

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


or to persist the database to indexedDB:

js
const db = new PGlite("idb://my-pgdata");


 Node/Bun/Deno

Install into your project:

NodeJS

bash
npm install @electric-sql/pglite


Bun

bash
bun install @electric-sql/pglite


Deno

bash
deno add npm:@electric-sql/pglite


To use the in-memory Postgres:

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

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


or to persist to the filesystem:

javascript
const db = new PGlite("./path/to/pgdata");


 pg (node-postgres)

Since v0.5.13, PGlite exposes a connection object that you can directly pass to pg (node-postgres) modules (clients):

javascript
import { createPgConfig } from '@electric-sql/pglite/node-postgres'
import { Client, Pool } from 'pg'
import Cursor from 'pg-cursor'

// use with pg Client
const pgConfig1 = createPgConfig()
const client = new Client(pgConfig1)
await client.connect()
await client.query(
  CREATE TABLE IF NOT EXISTS test (
    id SERIAL PRIMARY KEY,
    name TEXT
  );
)

// or with Pool
const pgConfig2 = createPgConfig()
const pool = new Pool(pgConfig2)
const conn = await pool.connect()

await conn.query(
  CREATE TABLE IF NOT EXISTS test (
    id SERIAL PRIMARY KEY,
    name TEXT
  );
)

// or even with Cursor from pg-cursor
const cursor = client.query(new Cursor('SELECT  FROM items;'))



 How it works

PostgreSQL typically operates using a process forking model; whenever a client initiates a connection, a new process is forked to manage that connection. However, prog

Top issues

Discussions

Latest release

@electric-sql/[email protected] @electric-sql/[email protected] 2026-11-10
Patch Changes

- 51aa2a0: Bump version of newest extensions

Snapshot: 2026-11-16T09:23:14Z · Data license Apache-2.0 · JSON