Skip to content
This repository has been archived by the owner on Aug 30, 2023. It is now read-only.

connrs/node-pg-sugar

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PG Sugar Build Status

A couple of methods to automate pooling with pg.

Create sugar

var sugar = require('pg-sugar');
var s = sugar(pg, connectionString);

Create a client to perform a query

s.client(function (err, query) {
  query('SELECT 1', [], function (err, results) {
    // Do stuff
    // Client is automatically returned to the pool
  });
});

Create a transaction client to run transactions

s.transaction(function (err, client) {
  client.query('SELECT 2', [], function (err, results, client) {
    if (err) {
      client.rollback(function () { console.log('LOSE!'); });
    }
    else {
      client.commit(function () { console.log('WIN!'); });
    }
  });
});

About

Some sugar methods on top of pg

Resources

License

Stars

Watchers

Forks

Packages

No packages published