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

@etauker/connector-postgres

v4.1.0

Published

Node postgres connector for etauker projects. Simplifies postgres database connections and allows running of database migrations from node applications.

Readme

Connector: Postgres

Node postgres connector for etauker projects. Simplifies postgres database connections and allows running of database migrations from node applications.

Usage

A pool factory and a persistance configuration object are needed to instantiate a connector object.

import {
    IPersistenceConfig,
    PoolFactory,
    PersistenceConnector    
} from '@etauker/connector-postgres';

const config: IPersistenceConfig = {
    database: process.env.DATABASE_DATABASE,
    user: process.env.DATABASE_USER,
    password: process.env.DATABASE_PASSWORD,
    host: process.env.DATABASE_HOST,
    port: parseInt(process.env.DATABASE_PORT),
};

const connectionPool = new PoolFactory().makePool(config);
const connector = new PersistenceConnector(connectionPool);

Basic usage

const query = 'SELECT * FROM car WHERE make = ? AND model = ?';
const params = [ 'Ford', 'Fiesta' ];
const results = await connector.select<Car>(query, params);
console.log(results);

Example output

[
    {
        id: '95c873fd-9326-41a7-9663-45f0132177b0',
        make: 'Ford',
        model: 'Fiesta',
        colour: 'Green'
    }
]

Features

Transaction management

The connector allows bypassing the simple CRUD methods and making use of the underlying transaction object to make atomic transactions.

const carId = 'd752f15c-e22f-4697-8eb6-e449c198ecf5';
const buyerId = '976a5724-f21e-43d4-99c8-e886ee491dd2';
const sellerId = 'f53deeb1-f9bc-450c-91f2-cd1c6033900a';

const buyerQuery = 'UPDATE person SET car_id = ? WHERE person_id = ?';
const sellerQuery = 'UPDATE person SET car_id = NULL WHERE person_id = ?';

const transaction = await connector.transact();
const [ buyerRowsUpdated, sellerRowsUpdated ] = await Promise.all([
    transaction.continue(buyerQuery, [ carId, buyerId ]),
    transaction.continue(sellerQuery, [ carId, sellerId ]),
]);

await transaction.commit();

console.log(`${ buyerRowsUpdated + sellerRowsUpdated } rows updated`);
// output: 2 rows updated

Database migrations

The library also provides functionality for executing database migrations.

Note: to run database migrations the connector needs to create some tables containing information about the state of migration execution. These tables currently make use of a certain database function which must first be created manually. This function can be found in scripts/create_type_if_not_exists.sql.

A {migration-root} directory containing all required migrations must first be created with the following structure. The migration directories can be named anything but should be prefixed with a number to ensure deterministic order. The files inside the migration directory must be names change.sql and rollback.sql.

{migration-root}
    |- 01.{first-migration}
        |- change.sql
        |- rollback.sql
    |- 02.{second-migration}
        |- change.sql
        |- rollback.sql
    |- ...

Change and rollback files must contain sql statements to be executed. The change file is executed during normal circumstances. If one of the migrations fails, the rollback file is executed for all previous migrations in that set.

-- {migration-root}/01.create-car-table/change.sql
CREATE TABLE IF NOT EXISTS cars (
    id              uuid            PRIMARY KEY,
    make            varchar(255)    UNIQUE,
    model           varchar(255)    NOT NULL,
    colour          varchar(255)
);

-- {migration-root}/01.create-car-table/rollback.sql
DROP TABLE IF EXISTS cars CASCADE;

The triggering of the migrations from code can be done like this

const migrationRoot = 'absolute/path/to/migration-root';
const persistenceConfig = getPersistenceConfig();
const migrationConfig = { debug: false };

const pool = new PoolFactory().makePool(persistenceConfig);
const connector = new PersistenceConnector(pool);
const service = new MigrationService(migrationConfig, connector);
await service.setup();
await service.loadAndExecuteChanges(migrationRoot);

Changelog

Version 4.0.0

Added

  • setup migration script to create helper functions

Removed

  • dependence on pre-existing helper functions

Changed

  • migrations and code logic to use helper functions in the provided schema

Version 4.1.0

Added

  • PersistenceTransaction.isOpen() method
  • PersistenceTransaction.closeIfOpen() method

Removed

  • logging directly through global console methods

Changed

  • verifyStatementMethod to split words by any whitespace instead of only spaces