Registry / database / rain-util-postgres

rain-util-postgres

JSON →
library0.4.0jsnpmunverified

Generator-based, co/koa compatible utility for accessing PostgreSQL. Version 0.4.0 is the current release (last updated circa 2016). Provides a simple DAO layer with schema introspection, upsert, and query execution using yieldable generators. Designed for use with Koa/co-style coroutines. Not suitable for modern async/await or ESM environments. Limited to Node >=4.2.0. Deprecated in favor of modern ORMs like Prisma, Sequelize, or TypeORM.

npm install rain-util-postgres
INSTALL
IMPORT
SIG · RAIN-UTIL-POSTGRES
R
rain-util-postgres
databasejavascriptv0.4.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

$Postgres
const $Postgres = require('rain-util-postgres');
import $Postgres from 'rain-util-postgres';
CJS-only; no ESM export. Using import will fail.
$Postgres.default
const $Postgres = require('rain-util-postgres'); const instance = new $Postgres(conn);
import { $Postgres } from 'rain-util-postgres';
Not exported as named export. Only default require works.
require('rain-util-postgres')
const $Postgres = require('rain-util-postgres');
const { $Postgres } = require('rain-util-postgres');
Destructuring from require will yield undefined because module.exports = $Postgres directly.

Connects to PostgreSQL, creates a table, inserts a record using upsert, then retrieves it via DAO findOne, all using generator co-routines.

const $Postgres = require('rain-util-postgres'); const co = require('co'); const conn = { host: 'localhost', db: 'postgres', user: 'postgres', password: process.env.PG_PASSWORD ?? '' }; const $postgres = new $Postgres(conn); co(function* () { const createTable = `CREATE TABLE IF NOT EXISTS users (id SERIAL PRIMARY KEY, name VARCHAR(100));`; yield $postgres.db.query(createTable); $postgres.table('users'); yield $postgres.tables.users.upsert({ name: 'Alice' }); const user = yield $postgres.tables.users.findOne('name = ?', 'Alice'); console.log(user); }).catch(err => console.error(err));
Debug
Known issues
deprecatedPackage is unmaintained since 2016; no updates for security or compatibility.
fix
Migrate to a modern PostgreSQL client like pg with async/await, or use an ORM like Sequelize, Prisma, or TypeORM.
affects: >=0
breakingRequires Node >=4.2.0 and generator support (co). Does not work with modern Node versions that dropped generator-based patterns.
fix
Use an async/await library instead, or run with a wrapper that provides generator support.
affects: >=0
deprecatedCJS-only; no ESM support. Using import will throw an error.
fix
Use require() or switch to an ESM-compatible package.
affects: >=0
gotchaThe $postgres.table() method must be called before accessing $postgres.tables. Otherwise tables object is empty.
fix
Always call $postgres.table(tablename) for each table you intend to use.
affects: >=0
gotchaThe upsert method may not work correctly with all column types or without a primary key.
fix
Ensure each table has a primary key and that all columns are supported by the upsert logic.
affects: >=0
deprecatedNo TypeScript definitions; lack of type safety.
fix
Write your own type declarations or use a TypeScript-first library.
affects: >=0
Errors
Common errors & fixes
TypeError: $Postgres is not a constructor
Using ES import (import $Postgres from ...) instead of require().
fix
Use const $Postgres = require('rain-util-postgres');
ReferenceError: co is not defined
Missing co dependency for generator execution.
fix
Install co: npm i co and wrap code in co(function*(){ ... }).
Cannot read property 'users' of undefined
Calling $postgres.tables.users without first calling $postgres.table('users').
fix
Add $postgres.table('users'); before accessing $postgres.tables.users.
ConnectionError: getaddrinfo ENOTFOUND localhost
PostgreSQL not running or incorrect connection config.
fix
Ensure PostgreSQL is running and host/port are correct.
Upgrade
Version history
0.4.0latest on npm
Audit
Dependencies
corequiredRequired for generator-based yield flow (used internally).
pgrequiredPostgreSQL client driver.
Agent activity
10 hits · last 30 days
node
8
Bingbot
1
Resources
rain-util-postgres — npm install rain-util-postgres · libregistry