JSON-SQL
Node.js library for mapping mongo-style query objects to SQL queries.
This library is not a driver, it is only translator, you should use specific driver for your db (for example https://github.com/brianc/node-postgres for PostgreSQL) to execute result query.
Quick Start
Install it with NPM or add it to your package.json:
$ npm install json-sql
Then:
var jsonSql = ;var sql = jsonSql;sqlquery// sql string:// select name, age from users where name = $p1 && id = 6;sqlvalues// hash of values:// { p1: 'Max' }
Documentation
Documentation is available at the ./docs directory.
Examples
Select with join:
var sql = jsonSql;sqlquery// select * from users join documents on user.id = documents.userId;sqlvalues// {}
Insert:
var sql = jsonSql;sqlquery// insert into users (name, lastname, age, gender) values ($p1, $p2, 24, $p3);sqlvalues// { p1: 'John', p2: 'Snow', p3: 'male' }
Update:
var sql = jsonSql;sqlquery// update users set role = $p1, age = 33 where id = 5;sqlvalues// { p1: 'admin' }
Remove:
var sql = jsonSql;sqlquery// delete from users where id = 5;sqlvalues// {}
For more examples, take a look at the ./docs directory or ./tests directory.
Tests
Clone repository from github, cd
into cloned dir and install dev dependencies:
$ npm install
Then run tests with command:
$ gulp test
Or run tests coverage with command:
$ gulp coverage