with-conn-pg
Calls a function injecting a pg connection, and release it afterwards
Last updated 2 years ago by matteo.collina .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install with-conn-pg 
SYNC missed versions from official npm registry.

with-conn-pg  Build Status

Calls a function injecting a pg connection, and release it afterwards

Install

npm install with-conn-pg --save

API


withConnPg(config)

Returns a new instance of withConn. Config can be both an object or a string. In case of an object, check pg. The connection string is parsed with: pg-connection-string.


withConn(func(conn, args.., done))

Wraps the passed function so that the first argument is what is returned by pool.connect() and release it afterwards.

this is preserved, and any arguments will be passed through.

If multiple functions are passed, they will be wrapped in a fastfall.

Example:

var connString = 'postgres://localhost/with_conn'
var withConn = require('with-conn-pg')(connString)
var func = withConn(function (client, arg, done) {
  console.log('input is', arg)
  client.query('SELECT $1::int AS number', [arg], function (err, result) {
    done(err, result.rows[0])
  })
})

func(42, function (err, result) {
  console.log('output is', result.number)
})

withConn.end()

Wraps pool.end() to release the connection pool (useful during testing).

License

MIT

Current Tags

  • 2.1.0                                ...           latest (2 years ago)

5 Versions

  • 2.1.0                                ...           2 years ago
  • 2.0.0                                ...           3 years ago
  • 1.1.0                                ...           4 years ago
  • 1.0.1                                ...           4 years ago
  • 1.0.0                                ...           5 years ago
Maintainers (1)
Downloads
Today 0
This Week 5
This Month 5
Last Day 0
Last Week 0
Last Month 0
Dependencies (3)
Dev Dependencies (4)

Copyright 2014 - 2016 © taobao.org |