pg-wrapper-ontech
v0.0.3
Published
[![Build Status](https://travis-ci.org/claudiohilario/pg-wrapper.svg?branch=master)](https://travis-ci.org/claudiohilario/pg-wrapper) [![Coverage Status](https://coveralls.io/repos/github/claudiohilario/pg-wrapper/badge.svg?branch=master)](https://coveral
Downloads
4
Readme
PG Wrapper
Usage Example
const config = {
user: 'postgres',
password: 'postgres',
database: 'postgres',
host: 'localhost',
port: 5432,
}
const pgClient = require('./src/index');
global.poolDb = pgClient(config);
Execute simple queries
const query = 'SELECT * FROM users WHERE uuid = $1';
const queryParams = ['00000000-0000-0000-0000-000000000000'];
poolDb.query(query, queryParams)
Execute transaction
const transactionClient = await poolDb.startTransaction();
try {
await poolDb.query(query, queryParams, transactionClient);
await poolDb.query(query1, queryParams1, transactionClient);
await poolDb.query(query2, queryParams2, transactionClient);
poolDb.endTransaction(undefined, transactionClient);
} catch(err) {
poolDb.endTransaction(err, transactionClient);
}