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

@railrepay/postgres-client

v1.0.0

Published

Reusable PostgreSQL connection pool for RailRepay microservices

Readme

@railrepay/postgres-client

Reusable PostgreSQL connection pool for RailRepay microservices with schema isolation support (ADR-001).

Features

  • Connection pooling with configurable pool size
  • Schema isolation per ADR-001 (schema-per-service pattern)
  • Automatic query logging with duration tracking
  • Health check support for container orchestration
  • Graceful shutdown
  • Optional logger injection

Installation

npm install @railrepay/postgres-client

Usage

Basic Usage

import { PostgresClient } from '@railrepay/postgres-client';

const client = new PostgresClient({
  serviceName: 'my-service',   // REQUIRED
  schemaName: 'my_schema',     // REQUIRED
});

await client.connect();

// Query all rows
const users = await client.query<User>('SELECT * FROM users');

// Query single row
const user = await client.queryOne<User>('SELECT * FROM users WHERE id = $1', [userId]);

// Health check
const isHealthy = await client.healthCheck();

// Graceful shutdown
await client.disconnect();

With Full Configuration

import { PostgresClient } from '@railrepay/postgres-client';
import { createLogger } from '@railrepay/winston-logger';

const logger = createLogger({ serviceName: 'my-service' });

const client = new PostgresClient({
  serviceName: 'timetable-loader',    // REQUIRED
  schemaName: 'timetable_loader',     // REQUIRED
  host: 'db.example.com',             // default: process.env.PGHOST
  port: 5432,                         // default: process.env.PGPORT
  database: 'railrepay',              // default: process.env.PGDATABASE
  user: 'postgres',                   // default: process.env.PGUSER
  password: 'secret',                 // default: process.env.PGPASSWORD
  ssl: true,                          // default: process.env.PGSSLMODE === 'require'
  poolSize: 20,                       // default: 20
  idleTimeout: 30000,                 // default: 30000ms
  connectionTimeout: 5000,            // default: 5000ms
  logger: logger,                     // optional winston logger
});

Transaction Support

const poolClient = await client.getClient();

try {
  await poolClient.query('BEGIN');
  await poolClient.query('INSERT INTO users (name) VALUES ($1)', ['Alice']);
  await poolClient.query('INSERT INTO accounts (user_id) VALUES ($1)', [1]);
  await poolClient.query('COMMIT');
} catch (error) {
  await poolClient.query('ROLLBACK');
  throw error;
} finally {
  poolClient.release();
}

Pool Statistics

const stats = client.getStats();
console.log('Pool stats:', stats);
// { totalCount: 20, idleCount: 18, waitingCount: 0 }

Configuration

PostgresConfig Interface

| Property | Type | Required | Default | Description | |----------|------|----------|---------|-------------| | serviceName | string | Yes | - | Service name for logging | | schemaName | string | Yes | - | PostgreSQL schema (ADR-001) | | host | string | No | process.env.PGHOST \|\| 'localhost' | Database host | | port | number | No | process.env.PGPORT \|\| 5432 | Database port | | database | string | No | process.env.PGDATABASE \|\| 'railrepay' | Database name | | user | string | No | process.env.PGUSER \|\| 'postgres' | Database user | | password | string | No | process.env.PGPASSWORD | Database password | | ssl | boolean | No | process.env.PGSSLMODE === 'require' | Enable SSL | | poolSize | number | No | 20 | Max pool connections | | idleTimeout | number | No | 30000 | Idle timeout (ms) | | connectionTimeout | number | No | 5000 | Connection timeout (ms) | | logger | Logger | No | console | Logger instance |

Environment Variables

  • PGHOST - Database host
  • PGPORT - Database port
  • PGDATABASE - Database name
  • PGUSER - Database user
  • PGPASSWORD - Database password
  • PGSSLMODE - Set to 'require' for SSL

Schema Isolation (ADR-001)

This package enforces schema-per-service pattern from ADR-001. The schemaName config sets the PostgreSQL search_path, ensuring each service accesses only its own tables.

-- Automatically set by PostgresClient
SET search_path = timetable_loader, public;

License

Private - RailRepay