node-pg-helper
v1.0.5
Published
postgres database helper
Downloads
3
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);
});