VibORM

PGlite

Embedded PostgreSQL using WebAssembly

Installation

pnpm add @electric-sql/pglite

Configuration

import { createClient } from "viborm/drivers/pglite";

const client = createClient({
  schema,
});

Options

OptionTypeDescription
clientPGliteExisting PGlite instance
dataDirstringData directory for persistence
optionsPGliteOptionsPGlite configuration
pgvectorbooleanEnable pgvector support
postgisbooleanEnable PostGIS support

In-Memory Database

import { createClient } from "viborm/drivers/pglite";

// Default is in-memory
const client = createClient({
  schema,
});

Persistent Database

import { createClient } from "viborm/drivers/pglite";

const client = createClient({
  dataDir: "./pglite-data",
  schema,
});

Using Existing Instance

import { PGlite } from "@electric-sql/pglite";
import { createClient } from "viborm/drivers/pglite";

const pg = new PGlite();

const client = createClient({
  client: pg,
  schema,
});

Use Cases

  • Local development: Full PostgreSQL without Docker
  • Testing: Fast, isolated database per test
  • Browser: PostgreSQL in the browser via WASM
  • Edge: Serverless functions with embedded database

Transactions

PGlite supports transactions but nested transactions have limitations.

await client.$transaction(async (tx) => {
  await tx.user.create({ data: { name: "Alice" } });
  await tx.post.create({ data: { title: "Hello", authorId: "..." } });
});

Limitations

  • WASM-based: may have performance overhead for heavy workloads
  • Limited nested transaction support
  • Some PostgreSQL extensions not available

On this page