Registry / database / postgres-wrapper

postgres-wrapper

JSON →
library1.0.4jsnpmunverified

A lightweight, zero-dependency wrapper around the `pg` (node-postgres) library for Node.js, providing simplified CRUD methods (`one`, `oneOrNone`, `any`, `many`, `none`) and automatic connection management via a single `POSTGRES_URL` environment variable. Version 1.0.4 is the latest stable release. It is designed for quick prototyping and small projects, with minimal API surface and no ORM features. Key differentiator: instant setup with environment variables, no configuration files required.

npm install postgres-wrapper
INSTALL
IMPORT
SIG · POSTGRES-WRAPPER
P
postgres-wrapper
databasejavascriptv1.0.4
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 export
const pg = require('postgres-wrapper')
import pg from 'postgres-wrapper'
The package only provides a CommonJS export. Named exports are not available.
one
const object = await pg.one({ query, params })
const object = await pg.one(query, params)
All methods expect a single object argument with `query` and optional `params` keys.
any
const rows = await pg.any({ query, params })
const rows = await pg.query({ text: query, values: params })
Do not use raw pg client methods; the wrapper handles connection and cleanup.

Demonstrates basic usage: importing the module, querying a single row, and closing the connection.

const pg = require('postgres-wrapper'); async function run() { try { const user = await pg.one({ query: 'SELECT * FROM users WHERE id = $1', params: [1] }); console.log(user); await pg.end(); } catch (err) { console.error(err); } } run();
Debug
Known issues
breakingEnvironment variable POSTGRES_URL must be set at runtime; failure to set it causes immediate connection error.
fix
Ensure POSTGRES_URL is defined in .env or process environment before calling any query method.
affects: >=0.0.0
gotchaEach query method creates a new connection pool internally if not already connected; calling pg.end() is required to avoid resource leaks.
fix
Always call await pg.end() after finishing all queries, or use a single instance.
affects: >=0.0.0
deprecatedThe package has no TypeScript typings; users must write their own declarations or use @types/pg.
fix
Install @types/pg and create a custom type declaration for postgres-wrapper.
affects: >=0.0.0
Errors
Common errors & fixes
Error: Cannot find module 'pg'
pg is a peer dependency not installed automatically.
fix
Run: npm install pg
Error: getaddrinfo ENOTFOUND <host>
POSTGRES_URL environment variable is missing or malformed.
fix
Set POSTGRES_URL to a valid PostgreSQL connection string (e.g., postgres://user:pass@localhost:5432/mydb)
TypeError: pg.one is not a function
Incorrect import: using ES module import instead of require.
fix
Use const pg = require('postgres-wrapper')
Upgrade
Version history
1.0.4latest on npm
Audit
Dependencies
pgrequiredpeer dependency: postgres-wrapper is a thin wrapper around node-postgres (pg)
Agent activity
10 hits · last 30 days
node
8
Resources
postgres-wrapper — npm install postgres-wrapper · libregistry