Registry / database / co-postgres

co-postgres

JSON →
library2.0.12jsnpmunverified

co-postgres is a thin wrapper around the `pg` PostgreSQL client that enables use with generators via the `co` library. Version 2.0.12 (last released in 2016) is stable but effectively unmaintained. It provides a simple API for querying Postgres using yield, making it suitable for legacy koa/co-based applications. Unlike modern async/await drivers, this package requires the co runtime and does not support promises natively. It has no dependencies beyond co and pg.

npm install co-postgres
INSTALL
IMPORT
SIG · CO-POSTGRES
C
co-postgres
databasejavascriptv2.0.12
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.

default
import postgres from 'co-postgres'
const postgres = require('co-postgres')
ESM import works in Node 12+, but CommonJS require is more common for this legacy package.
query
const { query } = require('co-postgres')
import { query } from 'co-postgres'
Named export 'query' is only available via CommonJS destructuring. ESM may not support it.
postgres
const postgres = require('co-postgres')
import postgres from 'co-postgres'
CommonJS require is the standard way to import this package. ESM default import may fail due to lack of default export.

Connects to a local Postgres database and runs a parameterized query using generators with co.

const co = require('co'); const postgres = require('co-postgres'); const db = postgres('postgres://localhost/test'); co(function* () { const result = yield db.query('SELECT $1::text as name', ['world']); console.log(result.rows); // [{ name: 'world' }] }).catch(err => console.error(err));
Debug
Known issues
deprecatedThis package is unmaintained and relies on the deprecated 'co' library. Use async/await with 'pg' directly.
fix
Replace co-postgres with 'pg' and convert generators to async/await.
affects: *
breakingRequires a generator runtime (co) and does not work with async/await out of the box.
fix
Wrap with co or switch to pg with async/await.
affects: *
gotchaThe query method returns a co-compatible thunk, not a Promise. Cannot use .then() directly.
fix
Use yield or wrap with co.
affects: *
Errors
Common errors & fixes
TypeError: postgres is not a function
Using ESM default import on a CommonJS module that does not export a default.
fix
Use const postgres = require('co-postgres') or use interop.
ReferenceError: yield is not defined
Calling yield outside of a generator function.
fix
Wrap code in co(function* () { ... }).
Upgrade
Version history
2.0.12latest on npm
Audit
Dependencies
corequiredRequired for generator-based control flow
pgrequiredUnderlying PostgreSQL client
Agent activity
7 hits · last 30 days
node
6
OpenAI (training)
1
Resources