Skip to content

mrcrgl/node-querybuilder

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published