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

@openaddresses/batch-generic

v25.0.0

Published

JSON Schema/ORM Hybrid Helper for Drizzle-ORM

Readme

Installation

npm add @openaddresses/batch-generic

Example Usage

The Generic Pool object is a wrapper around a Drizzle-ORM PgDatabase with the addition of several functions related to connection management and generation of internal JSON schemas.

import { Pool } from '@openaddresses/batch-generic';

async function start() {
    const pool = await Pool.connect('postgres://<conn-str>', schema);

    await pool.end();
}

Write/Read Load Balancing

If your database is deployed as a single writer with a cluster of read replicas, a { write, read } pair of connection strings can be provided in place of a single connection string. Read queries issued by the Modeler (from, list, count, iter, stream) are load balanced round-robin across the read connection(s), while write queries (generate, commit, delete, clear) are issued against the write connection.

import Modeler, { Pool } from '@openaddresses/batch-generic';

async function start() {
    const pool = await Pool.connect({
        write: 'postgres://writer.example.com:5432/db',
        read: [
            'postgres://reader-1.example.com:5432/db',
            'postgres://reader-2.example.com:5432/db'
        ]
    }, schema);

    const model = new Modeler(pool, schema.MyTable);

    await model.from(1);        // routed to a reader
    await model.commit(1, {});  // routed to the writer

    // pool.read returns the next reader pool for custom read queries
    await pool.read.select().from(schema.MyTable);

    await pool.end();
}

Note: read replicas are typically subject to replication lag - immediately reading back a row after a write may return stale data.

Tables

Each table within the database should also receive it's own Class definition that extends Generic. Upon Pool connection, a JSON Schema is generated dynamically for each table in the database. This schema is then used to ensure that objects always dynamically mirror their in database representations. State of the class is thus managed almost entirely though the database definition and automatically mirrored to the class.

CREATE TABLE dog (
    id      BIGSERIAL PRIMARY KEY,
    breed   TEXT,
    size    TEXT NOT NULL,
    tags    JSONB
);
import Generic from '@openaddresses/batch-generic';

class MyClass extends Generic {
    static _table = '<postgres table name>';
}
import { Pool } from '@openaddresses/batch-generic';
import Dog from './lib/types/dog.js';

async function start() {
    const pool = await Pool.connect('<postgres://<conn-str>');

    const dog = await Dog.from(pool, 1);
    await dog.commit({
        breed: 'newfie',
        size: 'large',
        tags: ['tag']
    });
    await dog.delete();

    await pool.end();
}

Views

Views are also supported by extending the Generic class. Views are given access to read-only functions such as list() or from() but access to write functions such as commit() or generate() will produce an error.

CREATE TABLE view_dog
    AS
        SELECT
            *
        FROM
            dog
import Generic from '@openaddresses/batch-generic';

class MyClass extends Generic {
    static _view = '<postgres view name>';
}
import { Pool } from '@openaddresses/batch-generic';
import Dog from './lib/views/dog.js';

async function start() {
    const pool = await Pool.connect('<postgres://<conn-str>');

    const dog = await Dog.from(pool, 1);

    await pool.end();
}

Docs

API Docs can be found here