pg-plus
This library wraps the node-postgres library to provide some nice things:
- promise support
- mongoDB-like interface
- case changing (i.e., can be set to automatically convert column names like
my_column
to JavaScript names likemyColumn
) - automatic resource clear up (uses Bluebird's
disposer
method behind the scenes)
Install
$ npm install pg-plus
Examples
This is a rough and ready demonstration until I have time to write more full documentation. Please also check out the test.js for examples.
// require the lib// (I use ES6, hence the extra .default part)var PostgresPlus = default; // set it up with some connection string (e.g. postgres://postgres@localhost/test)var pg = myConnectionString; // get a table (default primary key is 'id')var table1 = pg; // get a table using '_id' as the primary keyvar table2 = pg; // get a table using '_id' as the primary key, and converting column names// from snake casevar table3 = pg; // get some rows// refer to MongoDB docs for query syntax, most basic stuff should worktest; // get a single rowtest; // since we were using the primary key, there is a shorthand for the abovetest;