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

@heyhru/server-plugin-pg

v0.8.2

Published

PostgreSQL connection pool with unified execute interface

Readme

@heyhru/server-plugin-pg

PostgreSQL connection pool with a unified, parameter-style execute interface, plus a tiny migration runner that piggybacks on the same PgDb handle.

Install

pnpm add @heyhru/server-plugin-pg

Two ways to talk to Postgres

This package ships two abstractions for two distinct use cases:

  • createPgDb(url, opts) / getPgDb() — singleton app DB with ?-style placeholders, intended for the app's own data (users, sessions, etc.).
  • createPool(config) — multi-instance target DB pool used by data-source registries that connect to many user-owned databases.

App DB (singleton)

import { createPgDb, getPgDb } from "@heyhru/server-plugin-pg";

await createPgDb(process.env.DATABASE_URL!, {
  ssl: true,
  poolMin: 2,
  poolMax: 10,
  idleTimeoutMs: 10_000,
});

const db = getPgDb();
await db.run("INSERT INTO users (email) VALUES (?)", ["[email protected]"]);
const rows = await db.query<{ id: string }>("SELECT id FROM users WHERE email = ?", [
  "[email protected]",
]);

? placeholders are converted to $1, $2, ... internally so callers stay agnostic of pg-specific syntax.

Migrations

runMigrations(db, migrations) walks an ordered list of { name, sql } records, applies any that have not yet been recorded in the _migrations tracking table, and inserts a marker on success.

import { createPgDb, getPgDb, runMigrations, type Migration } from "@heyhru/server-plugin-pg";

const migrations: Migration[] = [
  { name: "001_users.sql", sql: () => `CREATE TABLE users (...)` },
  { name: "002_audit.sql", sql: () => `CREATE TABLE audit_log (...)` },
];

await createPgDb(process.env.DATABASE_URL!);
await runMigrations(getPgDb(), migrations, {
  onApplied: (name) => console.log(`migrated: ${name}`),
});

The runner is intentionally minimal: no down migrations, no checksums, no transactions across migrations. Each migration is run sequentially and recorded only after success.

Target DB pool

import { createPool } from "@heyhru/server-plugin-pg";

const pool = createPool({
  host: "db.example.com",
  port: 5432,
  database: "analytics",
  username: "ro",
  password: "secret",
  poolMin: 2,
  poolMax: 10,
  ssl: true,
});

const rows = await pool.execute("SELECT NOW()");
await pool.end();

Use this when you maintain a registry of user-supplied connection strings (DMS-style), not for the app's own DB.