with-conn-pg
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 = connStringvar func =
withConn.end()
Wraps pool.end()
to release the
connection pool (useful during testing).
License
MIT