Hi everyone,
I've just released connect-postgres[1] to help you with managing
Postgres connections. It uses brianc's node-pg.
The reason for making this is because having middleware early in your
route to get a client and then later to release the client ended up
being unwieldy, and especially sad if you did a res.redirect() and
forgot to manually release the client yourself. Also, if the request
ended in failure and you didn't have any error middleware to release
it for you, you'd again lose a client.
This middleware wraps res.end() much like connect's session middleware
does so that it is called at the end of every request whether it ends
in a res.send(), res.json(), res.redirect(), res.render() or even in
error. You may also specify if you want to wrap the request with a
transaction (BEGIN and COMMIT) automatically.
Hope you like it and if anyone can help with helping me figure out if
the request ended in error (Note: it's not error middleware, just
regular middleware that makes sure it is called after res.end() has
been called) then I'd be more than grateful[3]. :)
[1] NPM :
https://npmjs.org/package/connect-postgres
[2] GitHub :
https://github.com/chilts/connect-postgres
[3] Caveat :
https://github.com/chilts/connect-postgres#caveat
Many thanks,
Andy
--
contact: Andrew Chilton
website:
http://www.chilts.org/blog/