Postgres and Node

I’ve just been getting started with database access with node, and I’ll save you some time.  There are three competing node Progres libraries at the moment, and the right one is the one you’ll probably try third.  I appreciate that “right” is something of a strong statement, but it’s completely justified in context.

First up, we have postgres-js.  This is by the incredibly talented Tim Caswell aka creationix.  It’s a pure js library, which is a good thing, but it’s missing a couple of things: an example of how to make it work, and a test suite.  The former isn’t as big a problem as the latter, because sadly it doesn’t work.  Relatively simple queries will break as it tries to parse the response stream.  To be honest, I seriously doubt this is much of a focus for him, its last update was in August.

So, how about one by Ryan Dahl himself?  Postgres_Node (note the underscore) tries a different approach and goes to the C-level Postgres API.  Thinking about it, you’d kind of expect this from the guy who wrote node in the first place.  However, it’s in my opinion needlessly complex to do it this way, and although it does have a (short) test suite, I rapidly found myself breaking it badly.  It’s got a great big sign on the front page saying it’s experimental.  He means it.

Finally, Brian Carlson has written Postgres-Node (note the dash).  This is inspired by Tim Caswell’s take, but has an extensive test suite.  It even has (occasionally confusing) documentation.  Even better, it’s the only one that actually allows you to stream results.  To date, I haven’t managed to break it at all.  I highly recommend using this one.

Technorati Tags: ,

Published by

Julian Birch

Full time dad, does a bit of coding on the side.

One thought on “Postgres and Node”

  1. Would love to discuss what parts of the documentation you find confusing. They definitely need some work. Catch me on github gmail or google talk at my email address. Cheers!


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s