Pdo wrapper for https://github.com/porsager/postgres
$ npm i -S postgres-pdoconst postgres = require('postgres');
const Pdo = require('postgres-pdo');
const options = {
// Connection parameters
}
const sql = postgres(options);
const pdo = new Pdo(sql);const result = await pdo
.select()
.from('table_name')
.whereIn('id', [1, 2])
.orWhere('id', '=', 3)
.execute();
console.log(result);await pdo
.insert(['name', 'age'])
.into('table_name')
.values(['John', 30])
.execute();await pdo
.update({
name: 'John',
age: 30
})
.table('table_name')
.where('id', '=', 1)
.execute();await pdo
.delete('table_name')
.where('id', '>', 1)
.execute();await pdo.transaction(async (trxPdo) => {
const user = await trxPdo
.select()
.from('users')
.where('uid', '=', 1)
.forUpdate()
.first()
.execute();
await trxPdo
.update({
name: 'Updated'
})
.table('users')
.where('uid', '=', user.uid)
.execute();
});const row = await pdo
.select()
.from('jobs')
.where('status', '=', 'pending')
.forUpdate()
.skipLocked()
.first()
.execute();Available helpers:
forUpdate()forShare()skipLocked()noWait()first()returningOne()
const trxPdo = pdo.withClient(trx);
const isolatedBuilder = pdo.fork();