npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@vibeorm/adapter-pglite

v5.2.2

Published

PGlite (in-process Postgres) adapter for VibeORM v2

Readme

@vibeorm/adapter-pglite

Part of VibeORM — a type-safe TypeScript ORM for Bun and Node. Prisma-schema or TypeScript-DSL input, a canonical schema IR, a generated client, and a dialect-aware SQL layer over PostgreSQL, PGlite, SQLite and MySQL.

This adapter runs VibeORM on PGlite, real PostgreSQL compiled to WASM and running in-process. There is no server and no Docker, which makes it the zero-setup default for tests and demos; @electric-sql/pglite is a regular dependency, so nothing extra to install.

bun add @vibeorm/adapter-pglite

Stable. 2.0.0, published under the latest dist-tag. The v1 line stays installable as vibeorm@1.

Usage

import { VibeClient } from "./generated/vibeorm/index.js";
import { pgliteAdapter } from "@vibeorm/adapter-pglite";

// no dataDir → a fresh in-memory database
const db = VibeClient({ adapter: pgliteAdapter() });

const users = await db.user.findMany({ where: { email: { contains: "@example.com" } }, take: 10 });

await db.$disconnect();
const persistent = pgliteAdapter({ dataDir: "./.pglite" });     // persisted on disk
const shared = pgliteAdapter({ pglite: existingInstance });      // reuse a warm instance

disconnect() ends the adapter for good: work that already started finishes, an instance the adapter created is closed, and every later call refuses with VIBE_ADAPTER_CLOSED. Create a new adapter to connect again; with no dataDir its instance is a new, empty database.

Options

pgliteAdapter(options?: PgliteAdapterOptions):

| Option | Type | Default | Meaning | |---|---|---|---| | dataDir | string | — (in-memory) | Directory to persist the database in. PGlite's own prefixes (idb://, memory://) work here too | | pglite | PGliteInterface | — | An already-created PGlite instance to run on. The adapter never closes an instance it did not create; disconnect() then only ends the adapter |

There is no pool size and no connection URL: PGlite is a single embedded connection.

Runtime support

| Runtime | Supported | |---|---| | Bun ≥ 1.2 | yes | | Node | yes |

PGlite is WASM, so it needs no native build and no database server on either runtime.

Capabilities

PGlite speaks the postgres dialect, so the full capability set is available: RETURNING, scalar array columns, native enums, ILIKE, DISTINCT ON, partial indexes, transactional DDL, createManyAndReturn, a real JSON column type, native NULLS FIRST/NULLS LAST, and the "join" relation strategy (LEFT JOIN LATERAL plus JSON aggregation). The generated capability table lives in docs/dialects.md.

Two behaviours are specific to running in-process, and both are enforced rather than silent:

  • Transaction timeout is refused. PGlite accepts SET LOCAL statement_timeout and even reports it back through SHOW, but the single-threaded WASM build has no timer interrupt and never cancels a running statement. Passing timeout to $transaction therefore throws VIBE_UNSUPPORTED_CAPABILITY instead of becoming a no-op. isolationLevel is applied for real. Use a PostgreSQL server adapter where the option is genuinely enforced.
  • One connection, one queue. Every operation is serialized through a single operation queue, and a whole transaction holds that queue until it commits or rolls back. Calling the root client from inside a transaction callback would queue behind the transaction it is running in, so it is refused with VIBE_TRANSACTION; use the tx client the callback receives.

Nested transactions become savepoints on the open transaction, named from a counter shared across the whole top-level transaction.

On PGlite's in-process class the adapter sends a transaction's control statements itself (BEGIN, COMMIT, ROLLBACK, SET TRANSACTION, the savepoint statements): each is the same Query + Sync pair PGlite's transaction() and exec() send, in one engine call, inside PGlite's transaction lock, with PGlite's error objects. A transaction costs about 60 µs less, a savepoint pair about 60 µs less. Code that observes execProtocolStream sees these calls; other instances (PGliteWorker, another copy of the module) keep PGlite's transaction().

Caller cancellation of reads

This adapter declares readCancellation: "before-dispatch" on root, transaction and savepoint handles. Execution options are separate from query arguments and apply only to known reads. An abort observed before dispatch, including after waiting for the operation queue, prevents SQL. If a statement has already started, it settles before successful rows are discarded with VIBE_CANCELLED and databaseCancelled: false. Unrelated driver failures keep their mapped codes.

cancellation: "running" refuses with VIBE_UNSUPPORTED_CAPABILITY before instance creation or SQL. The installed PGlite interface has no cancellation method, and its current in-process execution calls the synchronous WASM main loop on the same thread. This adapter does not use a worker interrupt transport or reimplement the PostgreSQL protocol. Writes and raw SQL are outside this contract. An injected PGlite instance is never closed just to service a read signal.

Error mapping

PGlite runs the real PostgreSQL error protocol in-process, so its errors carry the same SQLSTATE plus constraint / table / column, which end up in meta; the driver error is attached as cause. Table (PGLITE_SQLSTATE_ERROR_CODES, frozen and mirrored by tests):

| SQLSTATE | Condition | VibeError code | meta.reason | |---|---|---|---| | 23505 | unique_violation | VIBE_UNIQUE_VIOLATION | | | 23503 | foreign_key_violation | VIBE_FK_VIOLATION | | | 23502 | not_null_violation | VIBE_VALIDATION | | | 23514 | check_violation | VIBE_VALIDATION | | | 22P02 | invalid_text_representation | VIBE_VALIDATION | | | 40001 | serialization_failure | VIBE_TRANSACTION | | | 40P01 | deadlock_detected | VIBE_TRANSACTION | | | 57014 | query_canceled | VIBE_TRANSACTION | "timeout" | | anything else, including PGlite's own failures (closed database, WASM init) | | VIBE_ADAPTER | |

A transaction callback's own error propagates untouched; PGlite has already rolled the transaction back by then.

Links