Package Exports
- node-pg-helper
- node-pg-helper/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (node-pg-helper) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
node-pg-helper
common helper functions for node-postgres
Examples
Setup postgres connection
const { Pool } = require('pg');
const db = require('node-pg-helper');
const pool = new Pool({
connectionString: process.env.DATABASE_URL,
ssl: { rejectUnauthorized: false }
});Set the client as Pool
db.setClient(pool);example insert
await db.insert('users', {
'id': 100,
'firstname': 'john',
'lastname': 'smith'
})example upsert
await db.upsert('users', {
'id': 100,
'firstname': 'john',
'lastname': 'snow'
}, 'id');example update
await db.update('users',{
'lastname': 'snow'
},
{
'id': 100
});select all the rows in a table
let rows = await db.selectAllRows("users");
rows.forEach(row => {
console.log(row);
});