{"id":43739,"library":"rain-util-postgres","title":"rain-util-postgres","description":"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.","status":"deprecated","version":"0.4.0","language":"javascript","source_language":"en","source_url":null,"tags":["javascript","koa","postgres","utils","pg","sql","dao","data access","generators"],"install":[{"cmd":"npm install rain-util-postgres","lang":"bash","label":"npm"},{"cmd":"yarn add rain-util-postgres","lang":"bash","label":"yarn"},{"cmd":"pnpm add rain-util-postgres","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Required for generator-based yield flow (used internally).","package":"co","optional":false},{"reason":"PostgreSQL client driver.","package":"pg","optional":false}],"imports":[{"note":"CJS-only; no ESM export. Using import will fail.","wrong":"import $Postgres from 'rain-util-postgres';","symbol":"$Postgres","correct":"const $Postgres = require('rain-util-postgres');"},{"note":"Not exported as named export. Only default require works.","wrong":"import { $Postgres } from 'rain-util-postgres';","symbol":"$Postgres.default","correct":"const $Postgres = require('rain-util-postgres'); const instance = new $Postgres(conn);"},{"note":"Destructuring from require will yield undefined because module.exports = $Postgres directly.","wrong":"const { $Postgres } = require('rain-util-postgres');","symbol":"require('rain-util-postgres')","correct":"const $Postgres = require('rain-util-postgres');"}],"quickstart":{"code":"const $Postgres = require('rain-util-postgres');\nconst co = require('co');\n\nconst conn = { host: 'localhost', db: 'postgres', user: 'postgres', password: process.env.PG_PASSWORD ?? '' };\nconst $postgres = new $Postgres(conn);\n\nco(function* () {\n    const createTable = `CREATE TABLE IF NOT EXISTS users (id SERIAL PRIMARY KEY, name VARCHAR(100));`;\n    yield $postgres.db.query(createTable);\n\n    $postgres.table('users');\n    yield $postgres.tables.users.upsert({ name: 'Alice' });\n\n    const user = yield $postgres.tables.users.findOne('name = ?', 'Alice');\n    console.log(user);\n}).catch(err => console.error(err));","lang":"javascript","description":"Connects to PostgreSQL, creates a table, inserts a record using upsert, then retrieves it via DAO findOne, all using generator co-routines."},"warnings":[{"fix":"Migrate to a modern PostgreSQL client like pg with async/await, or use an ORM like Sequelize, Prisma, or TypeORM.","message":"Package is unmaintained since 2016; no updates for security or compatibility.","severity":"deprecated","affected_versions":">=0"},{"fix":"Use an async/await library instead, or run with a wrapper that provides generator support.","message":"Requires Node >=4.2.0 and generator support (co). Does not work with modern Node versions that dropped generator-based patterns.","severity":"breaking","affected_versions":">=0"},{"fix":"Use require() or switch to an ESM-compatible package.","message":"CJS-only; no ESM support. Using import will throw an error.","severity":"deprecated","affected_versions":">=0"},{"fix":"Always call $postgres.table(tablename) for each table you intend to use.","message":"The $postgres.table() method must be called before accessing $postgres.tables. Otherwise tables object is empty.","severity":"gotcha","affected_versions":">=0"},{"fix":"Ensure each table has a primary key and that all columns are supported by the upsert logic.","message":"The upsert method may not work correctly with all column types or without a primary key.","severity":"gotcha","affected_versions":">=0"},{"fix":"Write your own type declarations or use a TypeScript-first library.","message":"No TypeScript definitions; lack of type safety.","severity":"deprecated","affected_versions":">=0"}],"env_vars":null,"search_vec":"'0.4.0':15 '2016':23 '4.2.0':56 'access':12,76 'async/await':49 'base':7 'circa':22 'co/koa':8 'compat':9 'coroutin':44 'current':18 'dao':27,74 'data':75 'deprec':57 'design':39 'environ':52 'esm':51 'execut':35 'favor':59 'generat':6,38,77 'generator-bas':5 'introspect':31 'javascript':68 'koa':69 'koa/co-style':43 'last':20 'layer':28 'like':63 'limit':53 'modern':48,61 'node':55 'orm':62 'pg':72 'postgr':4,70 'postgresql':13 'prisma':64 'provid':24 'queri':34 'rain':2 'rain-util-postgr':1 'releas':19 'schema':30 'sequel':65 'simpl':26 'sql':73 'suitabl':46 'typeorm':67 'updat':21 'upsert':32 'use':36,41 'util':3,10,71 'version':14 'yieldabl':37","created_at":"2026-06-05T17:01:15.121984+00:00","updated_at":"2026-06-05T17:01:15.121984+00:00","problems":[{"fix":"Use const $Postgres = require('rain-util-postgres');","cause":"Using ES import (import $Postgres from ...) instead of require().","error":"TypeError: $Postgres is not a constructor"},{"fix":"Install co: npm i co and wrap code in co(function*(){ ... }).","cause":"Missing co dependency for generator execution.","error":"ReferenceError: co is not defined"},{"fix":"Add $postgres.table('users'); before accessing $postgres.tables.users.","cause":"Calling $postgres.tables.users without first calling $postgres.table('users').","error":"Cannot read property 'users' of undefined"},{"fix":"Ensure PostgreSQL is running and host/port are correct.","cause":"PostgreSQL not running or incorrect connection config.","error":"ConnectionError: getaddrinfo ENOTFOUND localhost"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":null,"github":null,"docs":null,"changelog":null,"pypi":null,"npm":"rain-util-postgres","openapi_spec":null,"status_page":null,"smithery":null,"categories":["database"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-05","next_check":"2026-09-03","install_tag":null}}