Waddler <> PGlite
This guide assumes familiarity with:
- Database connection basics with Waddler
- ElectricSQL - website
- PgLite driver - docs & GitHub
According to the official repo, PGlite is a WASM Postgres build packaged into a TypeScript client library that enables 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.
It can be used as an ephemeral in-memory database, or with persistence either to the file system (Node/Bun) or indexedDB (Browser).
Unlike previous “Postgres in the browser” projects, PGlite does not use a Linux virtual machine - it is simply Postgres in WASM.
Step 1 - Install packages
npm
yarn
pnpm
bun
npm i waddler @electric-sql/pglite
Step 2 - Initialize the driver and make a query
In-Memory
In directory
With extra config options
import { waddler } from 'waddler/pglite';
const sql = waddler();
const result = await sql`select 1;`;
If you need to provide your existing driver:
import { PGlite } from '@electric-sql/pglite';
import { waddler } from 'waddler/pglite';
// In-memory Postgres
const client = new PGlite();
const sql = waddler({ client });
const result = await sql`select 1;`;