This repository has been archived by the owner. It is now read-only.
This is a pure javascript query builder for NodeJS supporting mysql and mongo out of the box.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
lib
tests
yuidoc
.gitignore
.travis.yml
LICENSE
README.md
index.js
package.json

README.md

Universal Query

Build Status Code Climate Coverage Status Author

An pure javascript query builder for various databases.

Currently supported:

  • MySQL
  • MongoDB

The API

The API is for all the query builders the same.
This is done so you can easily change the database type, and the queries work like normal.

Although keep the database limitations in mind.

Documentation

All example can be used in MySQL and MongoDB only by changing the getType value. Supported values are:

  • mysql
  • mongo

Building a simple mysql select query.

var universal_query = require('universal-query');

var mysql = universal_query('mysql');
var sql = mysql.select().table('foo').toQuery();
// SELECT * FROM `foo`;

A more advanced select query

var universal_query = require('universal-query');

var mysql = universal_query('mysql');
var sql = mysql.select().table('foo', 'bar').where('bar.foo_bar', '=', 1).toQuery();
// SELECT * FROM `foo` AS `bar` WHERE `bar`.`foo_bar` = 1;

An insert query

var universal_query = require('universal-query');

var mysql = universal_query('mysql');
var sql = mysql.insert().table('foo').set('foo', 'bar').toQuery();
// INSERT INTO `foo` (`foo`) VALUES ('bar');

An update query

var universal_query = require('universal-query');

var mysql = universal_query('mysql');
var sql = mysql.update().table('foo').set('foo', 'bar').where('foo.foo_bar', '=', 1).toQuery();
// UPDATE `foo` SET `foo`='bar' WHERE `foo`.`foo_bar` = 1;