[ANN] connect-postgres (not a connect session store, but middleware to help manage and automatically release Pg clients)

48 views
Skip to first unread message

Andrew Chilton

unread,
Apr 11, 2013, 6:51:12 AM4/11/13
to nod...@googlegroups.com
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/

alessioalex

unread,
Apr 12, 2013, 7:13:15 AM4/12/13
to nod...@googlegroups.com
I think you should have named it differently (ex. connect-postgres-client), because everybody's first thought will be that this is a session store for connect.

Andrew Chilton

unread,
Apr 12, 2013, 9:27:54 AM4/12/13
to nod...@googlegroups.com
On 12 April 2013 23:13, alessioalex <alessio...@gmail.com> wrote:
> I think you should have named it differently (ex. connect-postgres-client),
> because everybody's first thought will be that this is a session store for
> connect.

Good point. Renamed to connect-pgclient:

* npm install connect-pgclient
* https://npmjs.org/package/connect-pgclient
* https://github.com/chilts/connect-pgclient <- please star! :)

Cheers,
Reply all
Reply to author
Forward
0 new messages