node-pg-query-builder
This is a fork of (node-db-query)[https://github.com/markselby/node-db-query]. But my focus is on the postgres query build only.
Create SQL queries programatically in Node.js. Loosely based on Rails' ActiveRelation.
Getting Started
Install the module with: npm install pg-query-builder
This example uses any-db, so you'll need to npm install any-db
to run it.
Examples
var Query = ;var anyDB = ;var database = 'postgres://user@host:5432/database_name'; var dbPool = anyDB; var options = id: 1234 ;// or options = { id: '1,2,3,4' }; var q = dbPool ; // Add some sample optional processing to the queryvar food = 'cheese'; if food // Get people by food q q; q; // This becomes : foods.name = $1 else // Get people by id(s) // q.ids is another form of q.param, but will join arrays and wraps the result in '{ }' braces. qids1234; // q.ids('1,2,3,4'); as an alternative // This is using Postgres' ANY format rather than id IN blah because it's much more efficient q; // This becomes : id = ANY($1::int[]) // Prepare some event handlers and execute the queryq ;
Contributing
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Grunt.
Release History
v0.1.0
License
Copyright (c) 2013 Daisuke Yamashita Licensed under the MIT license.