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

@effectstream/db

v0.103.3

Published

PostgreSQL and PgLite database layer for EffectStream

Readme

@effectstream/db

The PostgreSQL (and PgLite) layer for EffectStream. Wraps pg with a connection pool, ships every pgtyped-generated SQL query the runtime needs, owns the snapshot loop, and provides a mutex needed for safe single-threaded PgLite access.

  • Pooled Postgres client plus every pgtyped query the runtime needs.
  • Snapshot loop (runSnapshotLoop) and acquireDBMutex / releaseDBMutex for PgLite.
  • Subpath scripts for in-memory PgLite, migrations, and version checks.
  • getConnection() is the dominant entry point, ~31 call sites across the repo.

Install

bun add @effectstream/db
# or
npm install @effectstream/db

Standalone usage

You can drop @effectstream/db into any Node service that needs a pooled Postgres client plus EffectStream's pgtyped queries. The most common things you'd reach for:

import {
  getConnection,
  getBlockHeights,
  getLatestProcessedBlockHeight,
} from "@effectstream/db";

const pool = getConnection({
  host: process.env.PGHOST,
  user: process.env.PGUSER,
  password: process.env.PGPASSWORD,
  database: process.env.PGDATABASE,
});

const client = await pool.connect();
try {
  const heights = await getBlockHeights.run({ limit: 5 }, client);
  console.log(heights);
} finally {
  client.release();
}

For PgLite (in-memory) the package ships ./start-pglite, ./apply-migrations, ./db-wait, ./pgtyped-update, ./version as small executable subpaths - used directly by the orchestrator.

PgLite caveat: PgLite is single-writer. Wrap PgLite-bound code in acquireDBMutex(name) / releaseDBMutex(name) so concurrent generators don't trample each other.

Inside EffectStream

@effectstream/db is the canonical access path. The runtime gets a pooled client through getConnection(), every state-transition function yields against pgtyped queries exported here, and the snapshot loop (runSnapshotLoop) emits versioned pg_dump artifacts so a fresh node can rejoin without re-syncing from genesis.

Key exports

Connection management (heavily used):

  • getConnection(creds?): pooled Pool singleton. Dominant entry point (~31 call sites across the repo).
  • acquireDBMutex(name, priority?) and releaseDBMutex(name) coordinate PgLite access; ~7 call sites each.
  • waitUntilFree() - companion to the mutex.
  • getPersistentConnection(creds) returns a non-pooled Client for long-lived listeners.

Queries (pgtyped-generated, shipped under one umbrella):

  • Block bookkeeping: getBlockHeights, getBlockByHash, blockHeightDone, saveLastBlock, getLatestProcessedBlockHeight.
  • Achievements: getAchievementProgress, setAchievementProgress.
  • Re-exports of *.queries.ts for statistics, nonces, rollup inputs, accounts, events, sync protocol pages, primitives, system, tables.

Snapshots:

  • runSnapshotLoop - periodic pg_dump of synced state.
  • createSnapshot: single-shot snapshot helper.
  • SnapshotConfig, SnapshotRetentionConfig: config types.

Dynamic table / event helpers:

  • createDynamicTables registers tables a primitive wants to own.
  • createIndexesForEvents creates pgtyped indexes for app events; registerEventTypes records each event's topic/name in the database.

Subpath entry points (executable scripts):

  • @effectstream/db/start-pglite: boot a PgLite instance.
  • @effectstream/db/apply-migrations - apply SQL migrations against the active DB.
  • @effectstream/db/db-wait: block until the DB accepts a connection.
  • @effectstream/db/pgtyped-update: regenerate pgtyped types.
  • @effectstream/db/version - print schema version.

Examples

Links

  • Docs: https://effectstream.github.io/docs/packages/node/db
  • Source: https://github.com/effectstream/effectstream/tree/main/packages/node-sdk/db