
Security News
The Changelog Podcast: Practical Steps to Stay Safe on npm
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.
pg-database
Advanced tools
Handy wrapper for pg (formerly node-postgres) database connection instances featuring:
You can import and instantiate database connection manually:
import Database from 'pg-database';
const database = new Database('<connection-uri>', console.log);
You can import an "automatically instantiated" database providing DB_URI=<connection-uri> and DB_LOG=<1|> environment variables:
import { database } from 'pg-database';
You can use this module as a simple drop-in replacement for pg.
Original pool, query and close methods are bound as they are.
import { database } from 'pg-database';
const client = await database.pool.connect();
client.query('LISTEN events');
client.on('notification', console.log);
client.on('error', console.error);
await client.release();
Check out src/index.ts to get a picture of available methods: minimal and simple.
You can use object for replacements (named placeholders) instead of array replacements (positional placeholders).
Placeholders must begin with : or $ and can contain only letters, numbers, underscores, dashes.
Before:
client.query('SELECT name FROM people WHERE name = $1', ['john'])
After:
client.query('SELECT name FROM people WHERE name = :name', { name: 'john' })
You can log executed queries.
Either create your db instance with a customer logger:
const database = new Database('<connection-uri>', console.log);
Or use the automatic instance setting DB_URI=<connection-uri> and DB_LOG=1 env variables:
import { database } from 'pg-database';
To run tests locally:
# start db
docker run --rm --name pg-database-test -p 5432:5432 --detach --env POSTGRES_USER=root --env POSTGRES_PASSWORD=root --env POSTGRES_DB=test postgres:14-alpine postgres -c log_statement=all
# run tests
yarn test
# remove db
docker rm -f pg-database-test
FAQs
Handy wrapper for pg (node-postgres) database connections.
We found that pg-database demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.

Security News
Experts push back on new claims about AI-driven ransomware, warning that hype and sponsored research are distorting how the threat is understood.

Security News
Ruby's creator Matz assumes control of RubyGems and Bundler repositories while former maintainers agree to step back and transfer all rights to end the dispute.