querybuilder

1.1.0 • Public • Published

node-querybuilder

Querybuilder have a simple, mongo like, API to create SQL and NoSQL queries.

Install

$ npm install querybuilder

Supported storages / client libs

API

Create NoSQL query (MongoDB)

var Querybuilder = require('querybuilder');
var qb = new Querybuilder('mongodb');
 
// Synchronous
var query = qb.select('*')
              .where({name: 'horst'})
              .offset(5)
              .call();
/* <- returns: 
{ type: 'select',
  what: undefined,
  where: { name: 'horst' },
  limit: 50,
  skip: 5,
  sort: {},
  set: {} }
*/
 
// Asynchronous
// Define a handler. We simply forward the query to the callback
qb.handler(function(query, callback) {
  
    // Your SQL connection can be placed here
    callback(null, query);
});
 
qb.select('*')
  .from('users') // just for campability to mysql
  .where({name: 'horst'})
  .offset(5)
  .call(function(err, query) {
    if (err) throw new Error(err);
    
    console.dir(query);
    // <- equal to synchronous
});

Create SQL query (MySQL)

 
var Querybuilder = require('querybuilder');
var qb = new Querybuilder('mysql');
 
// Synchronous
var query = qb.select('*')
              .from('users')
              .where({name: 'horst'})
              .offset(5)
              .call();
// <- returns: 'SELECT * FROM `users` WHERE (`name` = \'horst\') LIMIT 50,5'
 
 
// Asynchronous
// Define a handler. We simply forward the query to the callback
qb.handler(function(query, callback) {
  
    // Your SQL connection can be placed here
    callback(null, query);
});
 
qb.select('*')
  .from('users')
  .where({name: 'horst'})
  .offset(5)
  .call(function(err, query) {
    if (err) throw new Error(err);
    
    console.dir(query);
    // <- equal to synchronous
});

Module under MIT Licence

Readme

Keywords

none

Package Sidebar

Install

npm i querybuilder

Weekly Downloads

38

Version

1.1.0

License

MIT

Last publish

Collaborators

  • mrcrgl