Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

node-querybuilder

Package Overview
Dependencies
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-querybuilder - npm Package Compare versions

Comparing version 0.15.0 to 1.0.0

51

drivers/mysql/adapters.js

@@ -1,4 +0,4 @@

var Adapters = function(nqb) {
const Adapters = function(nqb) {
// Load MySQL Driver
var mysql = require('mysql');
const mysql = require('mysql');

@@ -24,3 +24,3 @@ // Verify setting property exists

this.connection_settings = {};
var that = this;
const that = this;

@@ -33,4 +33,4 @@ // ****************************************************************************

// ****************************************************************************
var map_connection_settings = function() {
that.connection_settings = {
const map_connection_settings = () => {
this.connection_settings = {
host: nqb.settings.host,

@@ -41,7 +41,7 @@ user: nqb.settings.user,

if (nqb.settings.hasOwnProperty('database')) {
that.connection_settings.database = nqb.settings.database;
this.connection_settings.database = nqb.settings.database;
delete nqb.settings.database
}
if (nqb.settings.hasOwnProperty('port')) {
that.connection_settings.port = nqb.settings.port;
this.connection_settings.port = nqb.settings.port;
delete nqb.settings.port

@@ -56,3 +56,3 @@ }

// Merge any driver-specific settings into connection settings
that.connection_settings = Object.assign(that.connection_settings, nqb.settings);
this.connection_settings = Object.assign(this.connection_settings, nqb.settings);
}

@@ -69,3 +69,3 @@

// ****************************************************************************
var get_query_builder = function() {
const get_query_builder = () => {
try {

@@ -86,3 +86,3 @@ return require('./query_builder.js').QueryBuilder();

// ****************************************************************************
var get_query_exec = function(qb, conn) {
const get_query_exec = (qb, conn) => {
try {

@@ -100,4 +100,4 @@ return require('./query_exec.js').QueryExec(qb, conn);

// ****************************************************************************
var Adapter = function(settings) {
var pool, connection;
const Adapter = function(settings) {
let pool, connection;

@@ -114,6 +114,6 @@ // If the Pool object is instatiating this Adapter, use it's connection

var qb = get_query_builder();
var qe = get_query_exec(qb, connection);
const qb = get_query_builder();
const qe = get_query_exec(qb, connection);
var adapter = Object.assign({
const adapter = Object.assign({
connection_settings: function() {

@@ -157,5 +157,5 @@ return that.connection_settings;

// ****************************************************************************
var Pool = function() {
const Pool = function() {
// Return Pool Object
var return_pool = function() {
const return_pool = () => {
return {

@@ -167,3 +167,3 @@ pool: function() {

if (null === nqb.pool) {
var error_msg = "Connection pool not available!";
const error_msg = "Connection pool not available!";
if (console && console.hasOwnProperty('error')) console.error(error_msg);

@@ -173,5 +173,5 @@ throw new Error(error_msg);

nqb.pool.getConnection(function (err, connection) {
nqb.pool.getConnection((err, connection) => {
if (err) throw err;
var adapter = new Adapter({
const adapter = new Adapter({
pool: {

@@ -199,4 +199,4 @@ pool: nqb.pool,

if (that.debugging === true) {
nqb.pool.getConnection(function(err, connection) {
connection.query('SELECT 1 + 1 AS solution', function(err) {
nqb.pool.getConnection((err, connection) => {
connection.query('SELECT 1 + 1 AS solution', (err) => {
connection.release();

@@ -220,3 +220,3 @@ if (err) {

// ****************************************************************************
var Cluster = function() {
const Cluster = () => {

@@ -231,14 +231,11 @@ };

// ****************************************************************************
var determine_adapter = function() {
const determine_adapter = () => {
switch(nqb.connection_type) {
case 'cluster':
return new Cluster();
break;
case 'pool':
return new Pool();
break;
case 'single':
default:
return new Adapter({});
break;
}

@@ -245,0 +242,0 @@ }

@@ -7,7 +7,7 @@ // ****************************************************************************

// ****************************************************************************
var QueryExec = function(qb, conn) {
const QueryExec = function (qb, conn) {
var exec = function(sql, callback) {
const exec = (sql, callback) => {
if (Object.prototype.toString.call(conn) == Object.prototype.toString.call({})) {
conn.query(sql, function(err, results) {
conn.query(sql, (err, results) => {
// Standardize some important properties

@@ -50,5 +50,5 @@ if (!err && results.length > 0) {

var sql = qb.count(table);
const sql = qb.count(table);
qb.reset_query(sql);
exec(sql, function(err, row) {
exec(sql, (err, row) => {
if (!err) {

@@ -73,3 +73,3 @@ //console.dir(row[0].numrows);

var sql = qb.get(table);
const sql = qb.get(table);
qb.reset_query(sql);

@@ -80,3 +80,3 @@ exec(sql,callback);

get_where: function(table,where,callback) {
if (typeof table !== 'string' && Object.prototype.toString.call(table) !== Object.prototype.toString.call([])) {
if (typeof table !== 'string' && !Array.isArray(table)) {
throw new Error("First parameter of get_where() must be a string or an array of strings.");

@@ -87,3 +87,3 @@ }

}
var sql = qb.get_where(table,where);
const sql = qb.get_where(table,where);
qb.reset_query(sql);

@@ -94,3 +94,3 @@ exec(sql,callback);

insert: function(table,set,callback,ignore,suffix) {
var sql = qb.insert(table,set,ignore,suffix);
const sql = qb.insert(table,set,ignore,suffix);
qb.reset_query(sql);

@@ -105,3 +105,3 @@ exec(sql,callback);

}
var sql = qb.insert_ignore(table,set,on_dupe);
const sql = qb.insert_ignore(table,set,on_dupe);
qb.reset_query(sql);

@@ -112,3 +112,3 @@ exec(sql,callback);

insert_batch: function(table,set,callback) {
var sql = qb.insert_batch(table,set);
const sql = qb.insert_batch(table,set);
qb.reset_query(sql);

@@ -131,3 +131,3 @@ exec(sql,callback);

var sql = qb.update(table,set,where);
const sql = qb.update(table,set,where);
qb.reset_query(sql);

@@ -151,12 +151,12 @@ exec(sql,callback);

var sqls = qb.update_batch(table,set,index,where);
var results = null;
var errors = [];
const sqls = qb.update_batch(table,set,index,where);
const results = null;
const errors = [];
// Execute each batch of (at least) 100
(function next_batch() {
var sql = sqls.shift();
const sql = sqls.shift();
qb.reset_query(sql);
exec(sql, function(err, res) {
exec(sql, (err, res) => {
if (!err) {

@@ -198,3 +198,3 @@ if (null === results) {

var sql = qb.delete(table, where);
const sql = qb.delete(table, where);

@@ -206,3 +206,3 @@ qb.reset_query(sql);

empty_table: function(table, callback) {
var sql = qb.empty_table(table,callback);
const sql = qb.empty_table(table,callback);
qb.reset_query(sql);

@@ -213,3 +213,3 @@ exec(sql,callback);

truncate: function(table, callback) {
var sql = qb.truncate(table,callback);
const sql = qb.truncate(table,callback);
qb.reset_query(sql);

@@ -216,0 +216,0 @@ exec(sql,callback);

@@ -16,3 +16,3 @@ /**

var connect, Standard, Pool, PoolCluster;
let connect, Standard, Pool, PoolCluster;

@@ -26,4 +26,4 @@ // ****************************************************************************

// ****************************************************************************
Standard = function(settings) {
Standard = settings => {
};

@@ -37,4 +37,4 @@

// ****************************************************************************
Pool = function(settings) {
Pool = settings => {
};

@@ -49,4 +49,4 @@

// ****************************************************************************
PoolCluster = function(settings) {
PoolCluster = settings => {
};

@@ -60,7 +60,7 @@

// ****************************************************************************
connect = function(settings,type) {
connect = (settings,type) => {
type = type || 'single';
var connection = null;
let connection = null;
switch(type) {

@@ -80,3 +80,3 @@ case 'single':

}
if (connection === null) {

@@ -83,0 +83,0 @@ throw new Error("A connection could not be established!");

@@ -1,2 +0,2 @@

var settings = {
const settings = {
host: 'localhost',

@@ -7,9 +7,9 @@ database: 'mydatabase',

};
var nqb = require('node-querybuilder');
var pool = new QueryBuilder(settings, 'mysql', 'pool');
const nqb = require('node-querybuilder');
const pool = new QueryBuilder(settings, 'mysql', 'pool');
pool.get_connection(function(qb) {
pool.get_connection(qb => {
qb.select('name', 'position')
.where({type: 'rocky', 'diameter <': 12000})
.get('planets', function(err,response) {
.get('planets', (err,response) => {
if (err) return console.error("Uh oh! Couldn't get results: " + err.msg);

@@ -16,0 +16,0 @@

@@ -1,2 +0,2 @@

var settings = {
const settings = {
host: 'localhost',

@@ -7,8 +7,8 @@ database: 'mydatabase',

};
var nqb = require('node-querybuilder');
var qb = new QueryBuilder(settings, 'mysql', 'single');
const nqb = require('node-querybuilder');
const qb = new QueryBuilder(settings, 'mysql', 'single');
qb.select('name', 'position')
.where({type: 'rocky', 'diameter <': 12000})
.get('planets', function(err,response) {
.get('planets', (err,response) => {
if (err) return console.error("Uh oh! Couldn't get results: " + err.msg);

@@ -15,0 +15,0 @@

@@ -17,5 +17,5 @@ # Changes

* Added the ability to do `[OR] WHERE [NOT] IN(...)` statements directly (new methods: `where_in()`, `or_where_in()`, `where_not_in()`, `or_where_not_in()`)
* Added the ability to do `FROM` statements directly for `SELECT` and `DELETE` queries (new method: `from()`) (ex. db.from('foo').get(function() { ... }))
* Added the ability to do `FROM` statements directly for `SELECT` and `DELETE` queries (new method: `from()`) (ex. db.from('foo').get(() => ...))
* Identifiers will now be properly escaped in `JOIN` statements.
* Added the ability to call `get_where()` as a shorthand to `get()` and `where()` (ex. `db.get_where('table',{foo: 'bar'},function() { ... });`)
* Added the ability to call `get_where()` as a shorthand to `get()` and `where()` (ex. `db.get_where('table',{foo: 'bar'},() => ...);`)
* Added the ability to call `select_min()`, `select_max()`, `select_avg()`, and `select_sum()`.

@@ -22,0 +22,0 @@ * Significanly improved security, helping to prevent SQL injection attacks.

@@ -5,5 +5,5 @@ /**

* kyle@chomponllc.com
*
* A generic Query Builder for any SQL or NOSQL database adapter.
*
*
* A generic Query Builder for any SQL or NOSQL database adapter.
*
* Current adapters:

@@ -19,5 +19,5 @@ * - MySQL

* - mongo
*
*
* Dual licensed under the MIT and GPL licenses.
*
*
* Permission is hereby granted, free of charge, to any person obtaining a

@@ -30,6 +30,6 @@ * copy of this software and associated documentation files (the

* the following conditions:
*
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS

@@ -42,7 +42,7 @@ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF

* OTHER DEALINGS IN THE SOFTWARE.
*
*
**/
var lo_assign = require('lodash.assign');
var QueryBuilder = function(settings,driver,type) {
const lo_assign = require('lodash.assign');
const QueryBuilder = (settings,driver,type) => {
this.settings = (settings ? lo_assign({}, settings) : {});

@@ -55,3 +55,3 @@ this.driver = driver || 'mysql';

this.pool = [];
// ****************************************************************************

@@ -63,3 +63,3 @@ // Get information about the driver the user wants to use and modify QB object

// ****************************************************************************
var get_driver_info = function(qb) {
const get_driver_info = qb => {
// A driver must be specified

@@ -69,5 +69,5 @@ if (typeof driver !== 'string') {

}
qb.driver = driver.toLowerCase();
// Verify that the driver is one we fundamentally support

@@ -77,9 +77,9 @@ if (Object.keys(qb.drivers).indexOf(qb.driver) === -1) {

}
// Determine version of driver to use
if (qb.settings.hasOwnProperty('version') && (typeof qb.settings.version).match(/^(string|number)$/i)) {
if (qb.settings.hasOwnProperty('version') && /^(string|number)$/i.test(typeof qb.settings.version)) {
qb.driver_version = qb.settings.version;
delete qb.settings.version;
}
// Retrieve info about driver if available, error if not

@@ -95,6 +95,6 @@ if (qb.drivers[qb.driver].versions.hasOwnProperty(qb.driver_version)) {

}
// Fail if specified driver is inactive
if (qb.driver_info.active === false) {
var err = (qb.driver_version == 'default' ? 'The default version' : "Version " + qb.driver_version)
const err = (qb.driver_version == 'default' ? 'The default version' : "Version " + qb.driver_version)
+ " of the " + qb.driver + " driver you are attempting to load is not currently available!";

@@ -105,3 +105,3 @@ throw new Error(err);

get_driver_info(this);
// ****************************************************************************

@@ -113,3 +113,3 @@ // Determine the type of connection (single, pool, cluster, etc...)

// ****************************************************************************
var get_connection_type = function(qb) {
const get_connection_type = qb => {
if (Object.keys(qb.drivers[qb.driver].connection_types).indexOf(qb.connection_type) === -1) {

@@ -124,3 +124,3 @@ throw new Error("You have specified a invalid database connection method: " + qb.connection_type);

get_connection_type(this);
// ****************************************************************************

@@ -131,5 +131,5 @@ // Returns the single, pool, or cluster adapter

// ****************************************************************************
var get_adapter = function(qb) {
const get_adapter = qb => {
try {
var adapter = require(qb.driver_info.path + 'adapters.js').Adapters(qb);
const adapter = require(qb.driver_info.path + 'adapters.js').Adapters(qb);
return adapter;

@@ -140,3 +140,3 @@ } catch(e) {

};
return get_adapter(this);

@@ -143,0 +143,0 @@ };

{
"name": "node-querybuilder",
"version": "0.15.0",
"version": "1.0.0",
"author": "Kyle Farris <kyle@chomponllc.com>",

@@ -5,0 +5,0 @@ "description": "Modeled after Codeigniter's QueryBuilder. Build and execute queries in a safe and database-agnostic way.",

@@ -1,6 +0,6 @@

var should = require('chai').should();
var expect = require('chai').expect;
var nqb = require('../../index.js');
const should = require('chai').should();
const expect = require('chai').expect;
const nqb = require('../../index.js');
var check = function(done, f) {
const check = (done, f) => {
try {

@@ -14,4 +14,4 @@ f();

var connection_released = function(qb) {
var connection = qb.connection();
const connection_released = qb => {
const connection = qb.connection();
expect(connection._pool._freeConnections).to.have.length(0);

@@ -22,10 +22,10 @@ qb.release();

describe('QueryBuilder() - MySQL Adapter', function() {
var on_connect = function(err) {
describe('QueryBuilder() - MySQL Adapter', () => {
const on_connect = err => {
if (err) { console.error("Not connected!"); return; }
console.log("connected!");
};
var driver = 'mysql';
var settings = {
host: '127.0.0.1',
const driver = 'mysql';
const settings = {
host: '127.0.0.1',
database: 'mock_db',

@@ -36,35 +36,35 @@ user: 'travis',

};
var bad_user = Object.assign({},settings); bad_user.user = 'foobar';
var bad_host = Object.assign({},settings); bad_host.host = 'nonlocalhost';
var bad_password = Object.assign({},settings); bad_password.password = 'password';
var bad_database = Object.assign({},settings); bad_database.database = 'bad_mock_db';
var bad_port = Object.assign({},settings); bad_port.port = 1;
var bad_version = Object.assign({},settings); bad_version.version = 12;
const bad_user = Object.assign({},settings); bad_user.user = 'foobar';
const bad_host = Object.assign({},settings); bad_host.host = 'nonlocalhost';
const bad_password = Object.assign({},settings); bad_password.password = 'password';
const bad_database = Object.assign({},settings); bad_database.database = 'bad_mock_db';
const bad_port = Object.assign({},settings); bad_port.port = 1;
const bad_version = Object.assign({},settings); bad_version.version = 12;
it('should exist', function() {
it('should exist', () => {
should.exist(nqb.QueryBuilder);
});
it('should be a function', function() {
it('should be a function', () => {
nqb.QueryBuilder.should.be.a('function');
});
it('should have all the QueryBuilder methods', function() {
var qb = nqb.QueryBuilder(Object.assign({}, settings), driver);
var children = ['where_array','where_in_array','from_array','join_array','select_array','set_array','order_by_array','group_by_array','having_array','limit_to','offset_val','join_clause','last_query_string','distinct_clause','aliased_tables','reset_query','where','or_where','_where','where_in','or_where_in','where_not_in','or_where_not_in','_where_in','like','not_like','or_like','or_not_like','_like','from','join','select','select_min','select_max','select_avg','select_sum','_min_max_avg_sum','distinct','group_by','having','or_having','_having','order_by','limit','offset','set'];
it('should have all the QueryBuilder methods', () => {
const qb = nqb.QueryBuilder(Object.assign({}, settings), driver);
const children = ['where_array','where_in_array','from_array','join_array','select_array','set_array','order_by_array','group_by_array','having_array','limit_to','offset_val','join_clause','last_query_string','distinct_clause','aliased_tables','reset_query','where','or_where','_where','where_in','or_where_in','where_not_in','or_where_not_in','_where_in','like','not_like','or_like','or_not_like','_like','from','join','select','select_min','select_max','select_avg','select_sum','_min_max_avg_sum','distinct','group_by','having','or_having','_having','order_by','limit','offset','set'];
expect(qb).to.include.keys(children);
});
it('should have all the QueryExec methods', function() {
var qb = nqb.QueryBuilder(Object.assign({}, settings), driver);
var children = ['insert','insert_ignore','insert_batch','get','get_where','count','update','update_batch','delete','get_compiled_select','get_compiled_delete','get_compiled_update','get_compiled_insert','compile_select','compile_delete','compile_update','compile_insert'];
it('should have all the QueryExec methods', () => {
const qb = nqb.QueryBuilder(Object.assign({}, settings), driver);
const children = ['insert','insert_ignore','insert_batch','get','get_where','count','update','update_batch','delete','get_compiled_select','get_compiled_delete','get_compiled_update','get_compiled_insert','compile_select','compile_delete','compile_update','compile_insert'];
expect(qb).to.include.keys(children);
});
it('should have all the miscellaneous methods', function() {
var qb = nqb.QueryBuilder(Object.assign({}, settings), driver);
var children = ['last_query','escape','empty_table','truncate'];
it('should have all the miscellaneous methods', () => {
const qb = nqb.QueryBuilder(Object.assign({}, settings), driver);
const children = ['last_query','escape','empty_table','truncate'];
expect(qb).to.include.keys(children);
});
it('should establish a single connection given valid connection credentials', function(done) {
var qb = nqb.QueryBuilder(Object.assign({}, settings), driver);
it('should establish a single connection given valid connection credentials', done => {
const qb = nqb.QueryBuilder(Object.assign({}, settings), driver);
expect(qb, 'should have connect property').to.have.property('connect');
qb.connect(function(err) {
check(done, function() {
qb.connect(err => {
check(done, () => {
expect(err, 'should be connected').to.not.be.instanceof(Error);

@@ -74,12 +74,12 @@ });

});
it('should allow us to disconnect from MySQL', function(done) {
var qb = nqb.QueryBuilder(Object.assign({}, settings), driver);
qb.connect(function(err) {
it('should allow us to disconnect from MySQL', done => {
const qb = nqb.QueryBuilder(Object.assign({}, settings), driver);
qb.connect(err => {
should.exist(qb.disconnect);
qb.disconnect.should.be.a('function');
qb.disconnect(function(err) {
var connection = qb.connection();
qb.disconnect(err => {
const connection = qb.connection();
check(done, function() {
check(done, () => {
expect(err, 'should be diconnected').to.not.be.instanceof(Error);

@@ -93,11 +93,14 @@ expect(connection._protocol._ended).to.be.true;

it('should fail to establish a single connection given no parameters', function() {
expect(function() { nqb.QueryBuilder(); }).to.throw(Error);
it('should fail to establish a single connection given no parameters', () => {
expect(() => nqb.QueryBuilder()).to.throw(Error);
});
it('should fail to establish a single connection given no connection credentials', function() {
expect(function() { nqb.QueryBuilder({},driver); }).to.throw(Error);
it('should fail to establish a single connection given no connection credentials', () => {
expect(() => nqb.QueryBuilder({},driver)).to.throw(Error);
});
it('should fail to establish a single connection given connection credentials with bad user', function(done) {
it('should fail to establish a single connection given connection credentials with bad user', done => {
let qb;
try {
var qb = nqb.QueryBuilder(bad_user, driver);
qb = nqb.QueryBuilder(bad_user, driver);
} catch(e) {

@@ -108,4 +111,4 @@ expect(e, 'should not get a connection').to.be.instanceof(Error);

expect(qb, 'should have connect property').to.have.property('connect');
qb.connect(function(err) {
check(done, function() {
qb.connect(err => {
check(done, () => {
expect(err, 'should not be connected').to.be.instanceof(Error);

@@ -115,5 +118,8 @@ });

});
it('should fail to establish a single connection given connection credentials with bad host', function(done) {
it('should fail to establish a single connection given connection credentials with bad host', done => {
let qb;
try {
var qb = nqb.QueryBuilder(bad_host, driver);
qb = nqb.QueryBuilder(bad_host, driver);
} catch(e) {

@@ -124,4 +130,4 @@ expect(e, 'should not get a connection').to.be.instanceof(Error);

expect(qb, 'should have connect property').to.have.property('connect');
qb.connect(function(err) {
check(done, function() {
qb.connect(err => {
check(done, () => {
expect(err, 'should not be connected').to.be.instanceof(Error);

@@ -131,5 +137,8 @@ });

});
it('should fail to establish a single connection given connection credentials with bad database', function(done) {
it('should fail to establish a single connection given connection credentials with bad database', done => {
let qb;
try {
var qb = nqb.QueryBuilder(bad_database, driver);
qb = nqb.QueryBuilder(bad_database, driver);
} catch(e) {

@@ -140,4 +149,4 @@ expect(e, 'should not get a connection').to.be.instanceof(Error);

expect(qb, 'should have connect property').to.have.property('connect');
qb.connect(function(err) {
check(done, function() {
qb.connect(err => {
check(done, () => {
expect(err, 'should not be connected').to.be.instanceof(Error);

@@ -147,5 +156,8 @@ });

});
it('should fail to establish a single connection given connection credentials with bad password', function(done) {
it('should fail to establish a single connection given connection credentials with bad password', done => {
let qb;
try {
var qb = nqb.QueryBuilder(bad_password, driver);
qb = nqb.QueryBuilder(bad_password, driver);
} catch(e) {

@@ -156,4 +168,4 @@ expect(e, 'should not get a connection').to.be.instanceof(Error);

expect(qb, 'should have connect property').to.have.property('connect');
qb.connect(function(err) {
check(done, function() {
qb.connect(err => {
check(done, () => {
expect(err, 'should not be connected').to.be.instanceof(Error);

@@ -163,5 +175,6 @@ });

});
it('should fail to establish a single connection given connection credentials with bad port', function(done) {
it('should fail to establish a single connection given connection credentials with bad port', done => {
let qb;
try {
var qb = nqb.QueryBuilder(bad_port, driver);
qb = nqb.QueryBuilder(bad_port, driver);
} catch(e) {

@@ -172,4 +185,4 @@ expect(e, 'should not get a connection').to.be.instanceof(Error);

expect(qb, 'should have connect property').to.have.property('connect');
qb.connect(function(err) {
check(done, function() {
qb.connect(err => {
check(done, () => {
expect(err, 'should not be connected').to.be.instanceof(Error);

@@ -179,23 +192,23 @@ });

});
it('should fail to establish connection if an invalid driver is specified', function() {
var qb;
expect(function() { nqb.QueryBuilder(settings); }, 'no driver specified').to.throw(Error);
expect(function() { nqb.QueryBuilder(settings,'foobar'); }, 'invalid driver specified').to.throw(Error);
it('should fail to establish connection if an invalid driver is specified', () => {
let qb;
expect(() => nqb.QueryBuilder(settings), 'no driver specified').to.throw(Error);
expect(() => nqb.QueryBuilder(settings,'foobar'), 'invalid driver specified').to.throw(Error);
});
it('should fail to establish connection if an invalid driver version is specified', function() {
var qb;
expect(function() { nqb.QueryBuilder( Object.assign({}, settings), driver); }, 'valid driver version').to.not.throw(Error);
expect(function() { nqb.QueryBuilder(bad_version, driver); }, 'invalid driver version').to.throw(Error);
it('should fail to establish connection if an invalid driver version is specified', () => {
let qb;
expect(() => nqb.QueryBuilder( Object.assign({}, settings), driver), 'valid driver version').to.not.throw(Error);
expect(() => nqb.QueryBuilder(bad_version, driver), 'invalid driver version').to.throw(Error);
});
it('should allow us to retrieve our connection settings for reference', function(done) {
var conn_settings = Object.assign({}, settings, {password: undefined});
it('should allow us to retrieve our connection settings for reference', done => {
const conn_settings = Object.assign({}, settings, {password: undefined});
delete conn_settings.version;
var qb = nqb.QueryBuilder(Object.assign({}, settings), driver);
qb.connect(function(err) {
check(done, function() {
const qb = nqb.QueryBuilder(Object.assign({}, settings), driver);
qb.connect(err => {
check(done, () => {
should.exist(qb.connection_settings);
qb.connection_settings.should.be.a('function');
var settings = qb.connection_settings();
const settings = qb.connection_settings();
expect(settings).to.be.instanceof(Object);

@@ -207,6 +220,6 @@ expect(settings).to.be.eql(conn_settings);

});
it('should allow us to escape certain values', function(done) {
var qb = nqb.QueryBuilder(Object.assign({}, settings), driver);
qb.connect(function(err) {
check(done, function() {
it('should allow us to escape certain values', done => {
const qb = nqb.QueryBuilder(Object.assign({}, settings), driver);
qb.connect(err => {
check(done, () => {
should.exist(qb.escape);

@@ -223,6 +236,6 @@ qb.escape.should.be.a('function');

});
it('should allow us to escape identifiers the MySQL way', function(done) {
var qb = nqb.QueryBuilder(Object.assign({}, settings), driver);
qb.connect(function(err) {
check(done, function() {
it('should allow us to escape identifiers the MySQL way', done => {
const qb = nqb.QueryBuilder(Object.assign({}, settings), driver);
qb.connect(err => {
check(done, () => {
should.exist(qb.escape_id);

@@ -237,7 +250,7 @@ qb.escape_id.should.be.a('function');

});
it('should allow us to execute a query', function(done) {
var qb = nqb.QueryBuilder(Object.assign({}, settings), driver);
qb.connect(function(err) {
qb.query("select * from `cities` where `city` like 'Z%' and `state_code` = 'FL'", function(err, res) {
check(done, function() {
it('should allow us to execute a query', done => {
const qb = nqb.QueryBuilder(Object.assign({}, settings), driver);
qb.connect(err => {
qb.query("select * from `cities` where `city` like 'Z%' and `state_code` = 'FL'", (err, res) => {
check(done, () => {
expect(err).to.not.be.instanceof(Error);

@@ -250,12 +263,12 @@ expect(res).to.not.be.empty;

});
it('should not be able to release a non-pooled connection', function(done) {
var qb = nqb.QueryBuilder(Object.assign({}, settings), driver);
qb.connect(function(err) {
check(done, function() {
expect(function() { qb.release(); }).to.throw(Error);
it('should not be able to release a non-pooled connection', done => {
const qb = nqb.QueryBuilder(Object.assign({}, settings), driver);
qb.connect(err => {
check(done, () => {
expect(() => qb.release()).to.throw(Error);
});
});
});
it('should create a connection pool object if asked', function() {
var pool = nqb.QueryBuilder(Object.assign({}, settings), driver, 'pool');
it('should create a connection pool object if asked', () => {
const pool = nqb.QueryBuilder(Object.assign({}, settings), driver, 'pool');
expect(pool).to.be.instanceof.object;

@@ -267,7 +280,7 @@ expect(pool).to.include.keys(['pool','get_connection','disconnect']);

});
it('should create a QueryBuilder adapter when getting a connection from the pool', function(done) {
var qb2 = nqb.QueryBuilder(Object.assign({}, settings), driver);
var pool = nqb.QueryBuilder(Object.assign({}, settings), driver, 'pool');
pool.get_connection(function(qb) {
check(done, function() {
it('should create a QueryBuilder adapter when getting a connection from the pool', done => {
const qb2 = nqb.QueryBuilder(Object.assign({}, settings), driver);
const pool = nqb.QueryBuilder(Object.assign({}, settings), driver, 'pool');
pool.get_connection(qb => {
check(done, () => {
expect(qb).to.include.keys(Object.keys(qb2));

@@ -277,20 +290,20 @@ });

});
it('should allow one to release a connection from the pool', function(done) {
var qb2 = nqb.QueryBuilder(Object.assign({}, settings), driver);
var pool = nqb.QueryBuilder(Object.assign({}, settings), driver, 'pool');
pool.get_connection(function(qb) {
check(done, function() { connection_released(qb); });
it('should allow one to release a connection from the pool', done => {
const qb2 = nqb.QueryBuilder(Object.assign({}, settings), driver);
const pool = nqb.QueryBuilder(Object.assign({}, settings), driver, 'pool');
pool.get_connection(qb => {
check(done, () => connection_released(qb));
});
});
it('should allow one use the same connection pool connection for multiple queries', function(done) {
var pool = nqb.QueryBuilder(Object.assign({}, settings), driver, 'pool');
it('should allow one use the same connection pool connection for multiple queries', done => {
const pool = nqb.QueryBuilder(Object.assign({}, settings), driver, 'pool');
pool.get_connection(function(qb) {
qb.query('select * from `cities` where `city` = "Gainesville"', function(err, res) {
pool.get_connection(qb => {
qb.query('select * from `cities` where `city` = "Gainesville"', (err, res) => {
if (res.length > 0) {
qb.query('select * from `cities` where `state_code` = "' + res[0].state_code + '"', function(err, res) {
check(done, function() { connection_released(qb); });
qb.query('select * from `cities` where `state_code` = "' + res[0].state_code + '"', (err, res) => {
check(done, () => connection_released(qb));
});
} else {
check(done, function() { connection_released(qb); });
check(done, () => connection_released(qb));
}

@@ -297,0 +310,0 @@ });

@@ -1,13 +0,13 @@

var should = require('chai').should();
var expect = require('chai').expect;
var qb = require('../../drivers/mysql/query_builder.js').QueryBuilder();
const should = require('chai').should();
const expect = require('chai').expect;
const qb = require('../../drivers/mysql/query_builder.js').QueryBuilder();
describe('get_compiled_select()', function() {
it('should exist', function() {
describe('get_compiled_select()', () => {
it('should exist', () => {
should.exist(qb.get_compiled_select);
});
it('should be a function', function() {
it('should be a function', () => {
qb.get_compiled_select.should.be.a('function');
});
it('should add a table to from_array when a table is supplied', function() {
it('should add a table to from_array when a table is supplied', () => {
qb.reset_query();

@@ -17,3 +17,3 @@ qb.get_compiled_select('galaxies');

});
it('should add a set of tables to from_array when an array of tables is supplied', function() {
it('should add a set of tables to from_array when an array of tables is supplied', () => {
qb.reset_query();

@@ -23,5 +23,5 @@ qb.get_compiled_select(['galaxies','star_systems','planets']);

});
it('should return a SQL string', function() {
it('should return a SQL string', () => {
qb.reset_query();
var sql = qb.get_compiled_select('galaxies');
const sql = qb.get_compiled_select('galaxies');
sql.should.eql('SELECT * FROM `galaxies`');

@@ -31,12 +31,12 @@ });

describe('get_compiled_insert()', function() {
it('should exist', function() {
describe('get_compiled_insert()', () => {
it('should exist', () => {
should.exist(qb.get_compiled_insert);
});
it('should be a function', function() {
it('should be a function', () => {
qb.get_compiled_insert.should.be.a('function');
});
it('should return a SQL string', function() {
it('should return a SQL string', () => {
qb.reset_query();
var sql = qb.set({foo:'bar'}).get_compiled_insert('galaxies');
const sql = qb.set({foo:'bar'}).get_compiled_insert('galaxies');
sql.should.eql("INSERT INTO `galaxies` (`foo`) VALUES ('bar')");

@@ -46,12 +46,12 @@ });

describe('get_compiled_update()', function() {
it('should exist', function() {
describe('get_compiled_update()', () => {
it('should exist', () => {
should.exist(qb.get_compiled_update);
});
it('should be a function', function() {
it('should be a function', () => {
qb.get_compiled_update.should.be.a('function');
});
it('should return a SQL string', function() {
it('should return a SQL string', () => {
qb.reset_query();
var sql = qb.set({foo:'bar'}).where('id',45).get_compiled_update('galaxies');
const sql = qb.set({foo:'bar'}).where('id',45).get_compiled_update('galaxies');
sql.should.eql("UPDATE (`galaxies`) SET `foo` = 'bar' WHERE `id` = 45");

@@ -61,14 +61,14 @@ });

describe('get_compiled_delete()', function() {
it('should exist', function() {
describe('get_compiled_delete()', () => {
it('should exist', () => {
should.exist(qb.get_compiled_delete);
});
it('should be a function', function() {
it('should be a function', () => {
qb.get_compiled_delete.should.be.a('function');
});
it('should return a SQL string', function() {
it('should return a SQL string', () => {
qb.reset_query();
var sql = qb.where('id',45).get_compiled_delete('galaxies');
const sql = qb.where('id',45).get_compiled_delete('galaxies');
sql.should.eql("DELETE FROM `galaxies` WHERE `id` = 45");
});
});

@@ -1,26 +0,26 @@

var should = require('chai').should();
var expect = require('chai').expect;
var qb = require('../../drivers/mysql/query_builder.js').QueryBuilder();
const should = require('chai').should();
const expect = require('chai').expect;
const qb = require('../../drivers/mysql/query_builder.js').QueryBuilder();
describe('count()', function() {
it('should exist', function() {
describe('count()', () => {
it('should exist', () => {
should.exist(qb.count);
});
it('should be a function', function() {
it('should be a function', () => {
qb.count.should.be.a('function');
});
it('should require that an item already exists in the from_array if one is not provided as the first parameter', function() {
it('should require that an item already exists in the from_array if one is not provided as the first parameter', () => {
qb.reset_query();
expect(function() { qb.count(); }, 'no tables supplied in chain').to.throw(Error);
expect(function() { qb.from('galaxies').count(); }, 'table supplied by from()').to.not.throw(Error);
expect(function() { qb.count('galaxies'); }, 'table supplied as first parameter').to.not.throw(Error);
expect(() => qb.count(), 'no tables supplied in chain').to.throw(Error);
expect(() => qb.from('galaxies').count(), 'table supplied by from()').to.not.throw(Error);
expect(() => qb.count('galaxies'), 'table supplied as first parameter').to.not.throw(Error);
});
it('should add a table to from_array when a table is supplied', function() {
it('should add a table to from_array when a table is supplied', () => {
qb.reset_query();
var sql = qb.count('galaxies');
const sql = qb.count('galaxies');
qb.from_array.should.eql(['`galaxies`']);
});
it('should return a string', function() {
it('should return a string', () => {
qb.reset_query();
var sql = qb.count('galaxies');
const sql = qb.count('galaxies');
expect(sql).to.be.a('string');

@@ -30,27 +30,27 @@ expect(sql).to.exist;

});
it('should create a properly-escaped SELECT query', function() {
it('should create a properly-escaped SELECT query', () => {
qb.reset_query();
var sql = qb.count('galaxies');
const sql = qb.count('galaxies');
sql.should.eql("SELECT COUNT(*) AS `numrows` FROM `galaxies`");
});
it('should include WHERE statements', function() {
it('should include WHERE statements', () => {
qb.reset_query();
var sql = qb.where({type:'spiral'}).count('galaxies');
const sql = qb.where({type:'spiral'}).count('galaxies');
sql.should.eql("SELECT COUNT(*) AS `numrows` FROM `galaxies` WHERE `type` = 'spiral'");
});
it('should work when table/view/procedure is provided earlier in chain but not in count() method', function() {
it('should work when table/view/procedure is provided earlier in chain but not in count() method', () => {
qb.reset_query();
var sql = qb.from('galaxies').count();
const sql = qb.from('galaxies').count();
sql.should.eql("SELECT COUNT(*) AS `numrows` FROM `galaxies`");
});
it('should work with multiple tables/views/stored procedures', function() {
it('should work with multiple tables/views/stored procedures', () => {
qb.reset_query();
var sql = qb.from(['planets','galaxies']).count();
const sql = qb.from(['planets','galaxies']).count();
sql.should.eql("SELECT COUNT(*) AS `numrows` FROM `planets`, `galaxies`");
});
it('should include any joins that were added in the chain', function() {
it('should include any joins that were added in the chain', () => {
qb.reset_query();
var sql = qb.join('galaxies g','g.id=s.galaxy_id','left').count('star_systems s');
const sql = qb.join('galaxies g','g.id=s.galaxy_id','left').count('star_systems s');
sql.should.eql("SELECT COUNT(*) AS `numrows` FROM `star_systems` `s` LEFT JOIN `galaxies` `g` ON `g`.`id`=`s`.`galaxy_id`");
});
});

@@ -1,13 +0,13 @@

var should = require('chai').should();
var expect = require('chai').expect;
var qb = require('../../drivers/mysql/query_builder.js').QueryBuilder();
const should = require('chai').should();
const expect = require('chai').expect;
const qb = require('../../drivers/mysql/query_builder.js').QueryBuilder();
describe('delete()', function() {
it('should exist', function() {
describe('delete()', () => {
it('should exist', () => {
should.exist(qb.delete);
});
it('should be a function', function() {
it('should be a function', () => {
qb.delete.should.be.a('function');
});
it('should add a table to from_array when a table is supplied', function() {
it('should add a table to from_array when a table is supplied', () => {
qb.reset_query();

@@ -17,29 +17,29 @@ qb.delete('galaxies');

});
it('should only accept nothing or a non-empty-string for the table (first) parameter', function() {
qb.reset_query();
expect(function() { qb.delete([]); }, 'empty array provided').to.throw(Error);
expect(function() { qb.delete({}); }, 'empty object provided').to.throw(Error);
expect(function() { qb.delete(3); }, 'integer provided').to.throw(Error);
expect(function() { qb.delete(3.5); }, 'float provided').to.throw(Error);
expect(function() { qb.delete(true); }, 'true provided').to.throw(Error);
expect(function() { qb.delete(Infinity);}, 'Infinity provided').to.throw(Error);
expect(function() { qb.delete([1,2]); }, 'array of numbers provided').to.throw(Error);
expect(function() { qb.delete(/foobar/);}, 'regex provided').to.throw(Error);
expect(function() { qb.delete(NaN); }, 'NaN provided').to.throw(Error);
expect(function() { qb.delete(false); }, 'false provided').to.throw(Error);
expect(function() { qb.delete(''); }, 'empty string provided').to.throw(Error);
expect(function() { qb.delete(' '); }, 'string full of spaces provided').to.throw(Error);
expect(function() { qb.delete(null); }, 'null provided').to.throw(Error);
it('should only accept nothing or a non-empty-string for the table (first) parameter', () => {
qb.reset_query();
expect(() => qb.delete([]), 'empty array provided').to.throw(Error);
expect(() => qb.delete({}), 'empty object provided').to.throw(Error);
expect(() => qb.delete(3), 'integer provided').to.throw(Error);
expect(() => qb.delete(3.5), 'float provided').to.throw(Error);
expect(() => qb.delete(true), 'true provided').to.throw(Error);
expect(() => qb.delete(Infinity), 'Infinity provided').to.throw(Error);
expect(() => qb.delete([1,2]), 'array of numbers provided').to.throw(Error);
expect(() => qb.delete(/foobar/), 'regex provided').to.throw(Error);
expect(() => qb.delete(NaN), 'NaN provided').to.throw(Error);
expect(() => qb.delete(false), 'false provided').to.throw(Error);
expect(() => qb.delete(''), 'empty string provided').to.throw(Error);
expect(() => qb.delete(' '), 'string full of spaces provided').to.throw(Error);
expect(() => qb.delete(null), 'null provided').to.throw(Error);
// An undefined/nothing option will only work if a table has already been provided
qb.from('galaxies'); expect(function() { qb.delete(undefined); },'undefined provided').to.not.throw(Error);
qb.from('galaxies'); expect(function() { qb.delete(); },'nothing provided').to.not.throw(Error);
qb.from('galaxies'); expect(() => qb.delete(undefined),'undefined provided').to.not.throw(Error);
qb.from('galaxies'); expect(() => qb.delete(),'nothing provided').to.not.throw(Error);
});
it('should only use the first table supplied in a list if an array of table is supplied with the from() method.', function() {
it('should only use the first table supplied in a list if an array of table is supplied with the from() method.', () => {
qb.reset_query();
var sql = qb.from(['galaxies','star_systems','planets']).delete();
const sql = qb.from(['galaxies','star_systems','planets']).delete();
sql.should.eql("DELETE FROM `galaxies`");
});
it('should add where conditions to where_array when conditions are supplied', function() {
it('should add where conditions to where_array when conditions are supplied', () => {
qb.reset_query();

@@ -49,5 +49,5 @@ qb.delete('planets', {continents: 7, star_system: 'Solar'});

});
it('should return a string', function() {
it('should return a string', () => {
qb.reset_query();
var sql = qb.delete('galaxies', {continents: 7, star_system: 'Solar'});
const sql = qb.delete('galaxies', {continents: 7, star_system: 'Solar'});
expect(sql).to.be.a('string');

@@ -57,37 +57,37 @@ expect(sql).to.exist;

});
it('should build a properly-escaped delete statement that deletes all records in a table if only a table is given', function() {
it('should build a properly-escaped delete statement that deletes all records in a table if only a table is given', () => {
qb.reset_query();
var sql = qb.delete('galaxies');
const sql = qb.delete('galaxies');
sql.should.eql('DELETE FROM `galaxies`');
});
it('should build a properly-escaped delete statement that deletes all records in a table that matched passed conditions', function() {
it('should build a properly-escaped delete statement that deletes all records in a table that matched passed conditions', () => {
qb.reset_query();
var sql = qb.delete('galaxies', {class: 'M'});
const sql = qb.delete('galaxies', {class: 'M'});
sql.should.eql("DELETE FROM `galaxies` WHERE `class` = 'M'");
});
it('should use ONLY the FIRST table added previously via the from() method', function() {
it('should use ONLY the FIRST table added previously via the from() method', () => {
qb.reset_query();
qb.from('galaxies');
var sql = qb.delete();
let sql = qb.delete();
sql.should.eql('DELETE FROM `galaxies`');
qb.reset_query();
var sql = qb.from(['galaxies','star_systems','planets']).delete();
sql = qb.from(['galaxies','star_systems','planets']).delete();
sql.should.eql('DELETE FROM `galaxies`');
});
it('should accept where conditions added previously via the where() method', function() {
it('should accept where conditions added previously via the where() method', () => {
qb.reset_query();
var sql = qb.where('created >=',4.6E9).where({class: 'M'}).delete('galaxies');
const sql = qb.where('created >=',4.6E9).where({class: 'M'}).delete('galaxies');
sql.should.eql("DELETE FROM `galaxies` WHERE `created` >= 4600000000 AND `class` = 'M'");
});
it('should accept a limit on the number of rows deleted', function() {
it('should accept a limit on the number of rows deleted', () => {
qb.reset_query();
var sql = qb.limit(20).delete('galaxies');
const sql = qb.limit(20).delete('galaxies');
sql.should.eql("DELETE FROM `galaxies` LIMIT 20");
});
it('should accept a LIMIT on the number of rows to delete and an OFFSET at which to start deleting the rows', function() {
it('should accept a LIMIT on the number of rows to delete and an OFFSET at which to start deleting the rows', () => {
qb.reset_query();
var sql = qb.limit(20,10).delete('galaxies');
const sql = qb.limit(20,10).delete('galaxies');
sql.should.eql("DELETE FROM `galaxies` LIMIT 10, 20");
});
});

@@ -1,13 +0,13 @@

var should = require('chai').should();
var expect = require('chai').expect;
var qb = require('../../drivers/mysql/query_builder.js').QueryBuilder();
const should = require('chai').should();
const expect = require('chai').expect;
const qb = require('../../drivers/mysql/query_builder.js').QueryBuilder();
describe('distinct()', function() {
it('should exist', function() {
describe('distinct()', () => {
it('should exist', () => {
should.exist(qb.distinct);
});
it('should be a function', function() {
it('should be a function', () => {
qb.distinct.should.be.a('function');
});
it('should override the default distinct_clause with the "DISTINCT " keyword', function() {
it('should override the default distinct_clause with the "DISTINCT " keyword', () => {
qb.reset_query();

@@ -14,0 +14,0 @@ qb.distinct();

@@ -1,15 +0,15 @@

var should = require('chai').should();
var expect = require('chai').expect;
var qb = require('../../drivers/mysql/query_builder.js').QueryBuilder();
const should = require('chai').should();
const expect = require('chai').expect;
const qb = require('../../drivers/mysql/query_builder.js').QueryBuilder();
describe('emtpy_table()', function() {
it('should exist', function() {
describe('emtpy_table()', () => {
it('should exist', () => {
should.exist(qb.empty_table);
});
it('should be a function', function() {
it('should be a function', () => {
qb.empty_table.should.be.a('function');
});
it('should return a string', function() {
it('should return a string', () => {
qb.reset_query();
var sql = qb.empty_table('galaxies');
const sql = qb.empty_table('galaxies');
expect(sql).to.be.a('string');

@@ -19,33 +19,33 @@ expect(sql).to.exist;

});
it('should build a proper DELETE statement', function() {
it('should build a proper DELETE statement', () => {
qb.reset_query();
var sql = qb.empty_table('galaxies');
const sql = qb.empty_table('galaxies');
sql.should.eql('DELETE FROM `galaxies`');
});
it('should only accept nothing or a non-empty-string for the table (first) parameter', function() {
qb.reset_query();
expect(function() { qb.empty_table([]); }, 'empty array provided').to.throw(Error);
expect(function() { qb.empty_table({}); }, 'empty object provided').to.throw(Error);
expect(function() { qb.empty_table(3); }, 'integer provided').to.throw(Error);
expect(function() { qb.empty_table(3.5); }, 'float provided').to.throw(Error);
expect(function() { qb.empty_table(true); }, 'true provided').to.throw(Error);
expect(function() { qb.empty_table(Infinity);}, 'Infinity provided').to.throw(Error);
expect(function() { qb.empty_table([1,2]); }, 'array of numbers provided').to.throw(Error);
expect(function() { qb.empty_table(/foobar/);}, 'regex provided').to.throw(Error);
expect(function() { qb.empty_table(NaN); }, 'NaN provided').to.throw(Error);
expect(function() { qb.empty_table(false); }, 'false provided').to.throw(Error);
expect(function() { qb.empty_table(''); }, 'empty string provided').to.throw(Error);
expect(function() { qb.empty_table(' '); }, 'string full of spaces provided').to.throw(Error);
expect(function() { qb.empty_table(null); }, 'null provided').to.throw(Error);
it('should only accept nothing or a non-empty-string for the table (first) parameter', () => {
qb.reset_query();
expect(() => qb.empty_table([]), 'empty array provided').to.throw(Error);
expect(() => qb.empty_table({}), 'empty object provided').to.throw(Error);
expect(() => qb.empty_table(3), 'integer provided').to.throw(Error);
expect(() => qb.empty_table(3.5), 'float provided').to.throw(Error);
expect(() => qb.empty_table(true), 'true provided').to.throw(Error);
expect(() => qb.empty_table(Infinity), 'Infinity provided').to.throw(Error);
expect(() => qb.empty_table([1,2]), 'array of numbers provided').to.throw(Error);
expect(() => qb.empty_table(/foobar/), 'regex provided').to.throw(Error);
expect(() => qb.empty_table(NaN), 'NaN provided').to.throw(Error);
expect(() => qb.empty_table(false), 'false provided').to.throw(Error);
expect(() => qb.empty_table(''), 'empty string provided').to.throw(Error);
expect(() => qb.empty_table(' '), 'string full of spaces provided').to.throw(Error);
expect(() => qb.empty_table(null), 'null provided').to.throw(Error);
// An undefined/nothing option will only work if a table has already been provided
qb.from('galaxies'); expect(function() { qb.empty_table(undefined); },'undefined provided').to.not.throw(Error);
qb.from('galaxies'); expect(function() { qb.empty_table(); },'nothing provided').to.not.throw(Error);
qb.from('galaxies'); expect(() => qb.empty_table(undefined),'undefined provided').to.not.throw(Error);
qb.from('galaxies'); expect(() => qb.empty_table(),'nothing provided').to.not.throw(Error);
});
it('should only use the first table supplied in a list if an array of table is supplied with the from() method.', function() {
it('should only use the first table supplied in a list if an array of table is supplied with the from() method.', () => {
qb.reset_query();
var sql = qb.from(['galaxies','star_systems','planets']).empty_table();
const sql = qb.from(['galaxies','star_systems','planets']).empty_table();
sql.should.eql("DELETE FROM `galaxies`");
});
});

@@ -1,22 +0,22 @@

var should = require('chai').should();
var qb = require('../../drivers/mysql/query_builder.js').QueryBuilder();
const should = require('chai').should();
const qb = require('../../drivers/mysql/query_builder.js').QueryBuilder();
describe('from()', function() {
it('should exist', function() {
describe('from()', () => {
it('should exist', () => {
should.exist(qb.from);
});
it('should be a function', function() {
it('should be a function', () => {
qb.from.should.be.a('function');
});
it('should have an array to put fields into', function() {
it('should have an array to put fields into', () => {
qb.should.have.property('from_array');
});
it('should have an empty array to put fields into at the beginning', function() {
it('should have an empty array to put fields into at the beginning', () => {
qb.from_array.should.be.empty;
});
it('should add an item to an array and escape it properly', function() {
it('should add an item to an array and escape it properly', () => {
qb.from('universe');
qb.from_array.should.eql(['`universe`']);
})
it('should accept a comma-delimited string of items and trim and escape each properly', function() {
it('should accept a comma-delimited string of items and trim and escape each properly', () => {
qb.reset_query();

@@ -26,7 +26,7 @@ qb.from('universe,galaxy , star_system, planet');

});
it('should have an empty array after resetting', function() {
it('should have an empty array after resetting', () => {
qb.reset_query();
qb.from_array.should.be.empty;
});
it('should be allowed to be called multiple times to add multiple items to the from array', function() {
it('should be allowed to be called multiple times to add multiple items to the from array', () => {
qb.reset_query();

@@ -36,3 +36,3 @@ qb.from('universe').from('galaxy').from('star_system').from('planet');

});
it('should accept an array of items and add them individually to the from array', function() {
it('should accept an array of items and add them individually to the from array', () => {
qb.reset_query();

@@ -42,3 +42,3 @@ qb.from(['universe','galaxy','star_system','planet']);

});
it('should not double-escape an item', function() {
it('should not double-escape an item', () => {
qb.reset_query();

@@ -48,3 +48,3 @@ qb.from('`do`');

});
it('should not double-escape items when provided with an array of pre-escaped items', function() {
it('should not double-escape items when provided with an array of pre-escaped items', () => {
qb.reset_query();

@@ -54,3 +54,3 @@ qb.from(['`universe`','`galaxy`','`star_system`']);

});
it('should not double-escape items when provided with an array of pre-escaped items but should escpae non-pre-escaped items', function() {
it('should not double-escape items when provided with an array of pre-escaped items but should escpae non-pre-escaped items', () => {
qb.reset_query();

@@ -60,3 +60,3 @@ qb.from(['`universe`','galaxy','`star_system`']);

});
it('should allow for aliases and it should escape them properly', function() {
it('should allow for aliases and it should escape them properly', () => {
qb.reset_query();

@@ -66,3 +66,3 @@ qb.from('universe u');

});
it('should allow for the word AS to be used to alias an item', function() {
it('should allow for the word AS to be used to alias an item', () => {
qb.reset_query();

@@ -72,3 +72,3 @@ qb.from('universe as u');

});
it('should allow for an array of item + aliases and it should escape them all properly', function() {
it('should allow for an array of item + aliases and it should escape them all properly', () => {
qb.reset_query();

@@ -78,3 +78,3 @@ qb.from(['universe u', 'galaxy g']);

});
it('should allow for an array of item + aliases that are pre-escaped and it should not double-escape them', function() {
it('should allow for an array of item + aliases that are pre-escaped and it should not double-escape them', () => {
qb.reset_query();

@@ -84,3 +84,3 @@ qb.from(['`universe` `u`', '`galaxy` `g`']);

});
it('should allow for an array of item + aliases where some are pre-escaped and it should not double-escape pre-escaped items', function() {
it('should allow for an array of item + aliases where some are pre-escaped and it should not double-escape pre-escaped items', () => {
qb.reset_query();

@@ -90,3 +90,3 @@ qb.from(['`universe` u', 'galaxy `g`']);

});
it('should add aliases to alias-tracking array', function() {
it('should add aliases to alias-tracking array', () => {
qb.reset_query();

@@ -96,3 +96,3 @@ qb.from(['`universe` `u`', '`galaxy` `g`']);

});
it('should allow for an comma-delimited list of item + aliases and it should escape them all properly', function() {
it('should allow for an comma-delimited list of item + aliases and it should escape them all properly', () => {
qb.reset_query();

@@ -102,7 +102,7 @@ qb.from(['universe u, galaxy g']);

});
it('should allow for namespacing in field name (host.db.table)', function() {
it('should allow for namespacing in field name (host.db.table)', () => {
qb.reset_query();
qb.from('star_system.planet');
qb.from_array.should.eql(['`star_system`.`planet`']);
qb.reset_query();

@@ -112,3 +112,3 @@ qb.from('galaxy.star_system.planet');

});
it('should allow for namespacing in field name (host.db.table.column) + alias', function() {
it('should allow for namespacing in field name (host.db.table.column) + alias', () => {
qb.reset_query();

@@ -118,3 +118,3 @@ qb.from('universe.galaxy.star_system planet');

});
it('should allow for namespacing in field name (host.db.table.column) + alias (declare with AS)', function() {
it('should allow for namespacing in field name (host.db.table.column) + alias (declare with AS)', () => {
qb.reset_query();

@@ -124,11 +124,11 @@ qb.from('universe.galaxy.star_system as planet');

});
it('should accept but ignore empty strings and empty strings within arrays', function() {
it('should accept but ignore empty strings and empty strings within arrays', () => {
qb.reset_query();
qb.from('');
qb.from_array.should.be.empty;
qb.reset_query();
qb.from(['','']);
qb.from_array.should.be.empty;
qb.reset_query();

@@ -135,0 +135,0 @@ qb.from(['','foobar']);

@@ -1,8 +0,8 @@

var should = require('chai').should();
const should = require('chai').should();
describe('QueryBuilder', function() {
it('actually exists and can be initialized', function() {
var qb = require('../../drivers/mysql/query_builder.js').QueryBuilder();
describe('QueryBuilder', () => {
it('actually exists and can be initialized', () => {
const qb = require('../../drivers/mysql/query_builder.js').QueryBuilder();
qb.should.be.instanceOf(Object);
});
});

@@ -1,13 +0,13 @@

var should = require('chai').should();
var expect = require('chai').expect;
var qb = require('../../drivers/mysql/query_builder.js').QueryBuilder();
const should = require('chai').should();
const expect = require('chai').expect;
const qb = require('../../drivers/mysql/query_builder.js').QueryBuilder();
describe('get()', function() {
it('should exist', function() {
describe('get()', () => {
it('should exist', () => {
should.exist(qb.get);
});
it('should be a function', function() {
it('should be a function', () => {
qb.get.should.be.a('function');
});
it('should add a table to from_array when a table is supplied', function() {
it('should add a table to from_array when a table is supplied', () => {
qb.reset_query();

@@ -17,3 +17,3 @@ qb.get('galaxies');

});
it('should add a set of tables to from_array when an array of tables is supplied', function() {
it('should add a set of tables to from_array when an array of tables is supplied', () => {
qb.reset_query();

@@ -23,5 +23,5 @@ qb.get(['galaxies','star_systems','planets']);

});
it('should return a string', function() {
it('should return a string', () => {
qb.reset_query();
var sql = qb.get('galaxies');
const sql = qb.get('galaxies');
expect(sql).to.be.a('string');

@@ -31,87 +31,87 @@ expect(sql).to.exist;

});
it('should build a properly-escaped SELECT statement that retrieves all records in a table if only a table is given', function() {
it('should build a properly-escaped SELECT statement that retrieves all records in a table if only a table is given', () => {
qb.reset_query();
var sql = qb.get('galaxies');
const sql = qb.get('galaxies');
sql.should.eql('SELECT * FROM `galaxies`');
});
it('should properly handle alias if provided in table string', function() {
it('should properly handle alias if provided in table string', () => {
qb.reset_query();
var sql = qb.get('galaxies g');
const sql = qb.get('galaxies g');
sql.should.eql('SELECT * FROM `galaxies` `g`');
});
it('should build a properly-escaped SELECT statement that retrieves all fields specified from a table', function() {
it('should build a properly-escaped SELECT statement that retrieves all fields specified from a table', () => {
qb.reset_query();
var sql = qb.select(['id','name']).get('galaxies');
const sql = qb.select(['id','name']).get('galaxies');
sql.should.eql("SELECT `id`, `name` FROM `galaxies`");
});
it('should build a properly-escaped SELECT statement that retrieves all records in a table that match passed WHERE conditions', function() {
it('should build a properly-escaped SELECT statement that retrieves all records in a table that match passed WHERE conditions', () => {
qb.reset_query();
var sql = qb.where('class','M').get('galaxies');
const sql = qb.where('class','M').get('galaxies');
sql.should.eql("SELECT * FROM `galaxies` WHERE `class` = 'M'");
});
it('should build a properly-escaped SELECT statement that retrieves all records from a set of joined tables if an array of tables is given', function() {
it('should build a properly-escaped SELECT statement that retrieves all records from a set of joined tables if an array of tables is given', () => {
qb.reset_query();
var sql = qb.get(['galaxies','star_systems','planets']);
const sql = qb.get(['galaxies','star_systems','planets']);
sql.should.eql('SELECT * FROM `galaxies`, `star_systems`, `planets`');
});
it('should build a properly-escaped SELECT statement that retrieves all records in a set of tables that match the passed conditions', function() {
it('should build a properly-escaped SELECT statement that retrieves all records in a set of tables that match the passed conditions', () => {
qb.reset_query();
var sql = qb.where('class', 'M').get(['galaxies','star_systems','planets']);
const sql = qb.where('class', 'M').get(['galaxies','star_systems','planets']);
sql.should.eql("SELECT * FROM `galaxies`, `star_systems`, `planets` WHERE `class` = 'M'");
});
it('should use tables added previously via the from() method', function() {
it('should use tables added previously via the from() method', () => {
qb.reset_query();
qb.from('galaxies');
var sql = qb.get();
let sql = qb.get();
sql.should.eql('SELECT * FROM `galaxies`');
qb.reset_query();
var sql = qb.from(['galaxies','star_systems','planets']).get();
sql = qb.from(['galaxies','star_systems','planets']).get();
sql.should.eql('SELECT * FROM `galaxies`, `star_systems`, `planets`');
});
it('should accept where conditions added previously via the where() method', function() {
it('should accept where conditions added previously via the where() method', () => {
qb.reset_query();
var sql = qb.where('created >=',4.6E9).where({classification: 'M'}).get('galaxies');
const sql = qb.where('created >=',4.6E9).where({classification: 'M'}).get('galaxies');
sql.should.eql("SELECT * FROM `galaxies` WHERE `created` >= 4600000000 AND `classification` = 'M'");
});
it('should accept a limit on the number of rows selected', function() {
it('should accept a limit on the number of rows selected', () => {
qb.reset_query();
var sql = qb.limit(20).get('galaxies');
const sql = qb.limit(20).get('galaxies');
sql.should.eql("SELECT * FROM `galaxies` LIMIT 20");
});
it('should accept a LIMIT on the number of rows to select and an OFFSET at which to start selecting the rows', function() {
it('should accept a LIMIT on the number of rows to select and an OFFSET at which to start selecting the rows', () => {
qb.reset_query();
var sql = qb.limit(20,10).get('galaxies');
const sql = qb.limit(20,10).get('galaxies');
sql.should.eql("SELECT * FROM `galaxies` LIMIT 10, 20");
});
it('should include the DISTINCT keyword if the distinct() method is called', function() {
it('should include the DISTINCT keyword if the distinct() method is called', () => {
qb.reset_query();
var sql = qb.distinct().select(['id','name']).get('galaxies');
const sql = qb.distinct().select(['id','name']).get('galaxies');
sql.should.eql("SELECT DISTINCT `id`, `name` FROM `galaxies`");
});
it('should include the MIN, MAX, AVG, or SUM aggregation methods in the select statement if provided', function() {
it('should include the MIN, MAX, AVG, or SUM aggregation methods in the select statement if provided', () => {
qb.reset_query();
// MIN
var sql = qb.select_min('size','min_size').get('galaxies');
let sql = qb.select_min('size','min_size').get('galaxies');
sql.should.eql("SELECT MIN(`size`) AS min_size FROM `galaxies`");
qb.reset_query();
// MAX
var sql = qb.select_max('size','max_size').get('galaxies');
sql = qb.select_max('size','max_size').get('galaxies');
sql.should.eql("SELECT MAX(`size`) AS max_size FROM `galaxies`");
qb.reset_query();
// AVG
var sql = qb.select_avg('size','avg_size').get('galaxies');
sql = qb.select_avg('size','avg_size').get('galaxies');
sql.should.eql("SELECT AVG(`size`) AS avg_size FROM `galaxies`");
qb.reset_query();
// SUM
var sql = qb.select_sum('size','total_size').get('galaxies');
sql = qb.select_sum('size','total_size').get('galaxies');
sql.should.eql("SELECT SUM(`size`) AS total_size FROM `galaxies`");
});
it('should include any joins that were added in the chain', function() {
it('should include any joins that were added in the chain', () => {
qb.reset_query();
var sql = qb.select(['s.name as star_system_name', 'g.name as galaxy_name'])
const sql = qb.select(['s.name as star_system_name', 'g.name as galaxy_name'])
.join('galaxies g','g.id=s.galaxy_id','left')

@@ -121,54 +121,54 @@ .get('star_systems s');

});
it('should include any GROUP BY statements added using the group_by() method.', function() {
it('should include any GROUP BY statements added using the group_by() method.', () => {
qb.reset_query();
var sql = qb.select('size').select('COUNT(id) as `num_of_size`',false).group_by('size').get('galaxies');
sql.should.eql("SELECT `size`, COUNT(id) AS `num_of_size` FROM `galaxies` GROUP BY `size`");
const sql = qb.select('size').select('COUNT(id) as `num_of_size`',false).group_by('size').get('galaxies');
sql.should.eql("SELECT `size`, COUNT(id) AS `num_of_size` FROM `galaxies` GROUP BY `size`");
});
it('should add the ORDER BY clause of the order_by() method was called in the chain', function() {
it('should add the ORDER BY clause of the order_by() method was called in the chain', () => {
qb.reset_query();
var sql = qb.order_by('size').get('galaxies');
const sql = qb.order_by('size').get('galaxies');
sql.should.eql("SELECT * FROM `galaxies` ORDER BY `size` ASC");
});
it('should include any HAVING clauses added using the having() method', function() {
it('should include any HAVING clauses added using the having() method', () => {
qb.reset_query();
var sql = qb.select('size').select('COUNT(id) as `num_of_size`',false).group_by('size').having('num_of_size >=',456034960).get('galaxies');
sql.should.eql("SELECT `size`, COUNT(id) AS `num_of_size` FROM `galaxies` GROUP BY `size` HAVING `num_of_size` >= 456034960");
const sql = qb.select('size').select('COUNT(id) as `num_of_size`',false).group_by('size').having('num_of_size >=',456034960).get('galaxies');
sql.should.eql("SELECT `size`, COUNT(id) AS `num_of_size` FROM `galaxies` GROUP BY `size` HAVING `num_of_size` >= 456034960");
});
});
describe('get_where()', function() {
it('should exist', function() {
describe('get_where()', () => {
it('should exist', () => {
should.exist(qb.get_where);
});
it('should be a function', function() {
it('should be a function', () => {
qb.get_where.should.be.a('function');
});
it('should require the first parameter to be a table in string format or tables array format', function() {
it('should require the first parameter to be a table in string format or tables array format', () => {
qb.reset_query();
expect(function() { qb.get_where(); }, 'nothing provided').to.throw(Error);
expect(function() { qb.get_where(''); }, 'empty string for table').to.throw(Error);
expect(function() { qb.get_where([]); }, 'empty array for tables').to.throw(Error);
expect(function() { qb.get_where(['']); }, 'array of empty strings for tables').to.throw(Error);
expect(function() { qb.get_where(1); }, 'integer for table').to.throw(Error);
expect(function() { qb.get_where(5.5); }, 'float for table').to.throw(Error);
expect(function() { qb.get_where(true); }, 'TRUE for table').to.throw(Error);
expect(function() { qb.get_where(false); }, 'FALSE for table').to.throw(Error);
expect(function() { qb.get_where(null); }, 'NULL for table').to.throw(Error);
expect(function() { qb.get_where({}); }, 'Standard object for table').to.throw(Error);
expect(function() { qb.get_where(Infinite); }, 'Infinite for table').to.throw(Error);
expect(function() { qb.get_where('galaxies'); }, 'valid table, no where').to.throw(Error);
expect(function() { qb.get_where('galaxies',{}); }, 'valid table, empty where').to.throw(Error);
expect(function() { qb.get_where('galaxies',[]); }, 'valid table, array for where').to.throw(Error);
expect(function() { qb.get_where('galaxies',3); }, 'valid table, integer for where').to.throw(Error);
expect(function() { qb.get_where('galaxies',33.3); }, 'valid table, float for where').to.throw(Error);
expect(function() { qb.get_where('galaxies','foo'); }, 'valid table, string for where').to.throw(Error);
expect(function() { qb.get_where('galaxies',true); }, 'valid table, TRUE for where').to.throw(Error);
expect(function() { qb.get_where('galaxies',false); }, 'valid table, FALSE for where').to.throw(Error);
expect(function() { qb.get_where('galaxies',Infinite); }, 'valid table, Infinite where').to.throw(Error);
expect(function() { qb.get_where('galaxies',null); }, 'valid table, NULL where').to.throw(Error);
expect(function() { qb.get_where('galaxies',{id: 3}); }, 'valid table, valid where').to.not.throw(Error);
expect(() => qb.get_where(), 'nothing provided').to.throw(Error);
expect(() => qb.get_where(''), 'empty string for table').to.throw(Error);
expect(() => qb.get_where([]), 'empty array for tables').to.throw(Error);
expect(() => qb.get_where(['']), 'array of empty strings for tables').to.throw(Error);
expect(() => qb.get_where(1), 'integer for table').to.throw(Error);
expect(() => qb.get_where(5.5), 'float for table').to.throw(Error);
expect(() => qb.get_where(true), 'TRUE for table').to.throw(Error);
expect(() => qb.get_where(false), 'FALSE for table').to.throw(Error);
expect(() => qb.get_where(null), 'NULL for table').to.throw(Error);
expect(() => qb.get_where({}), 'Standard object for table').to.throw(Error);
expect(() => qb.get_where(Infinite), 'Infinite for table').to.throw(Error);
expect(() => qb.get_where('galaxies'), 'valid table, no where').to.throw(Error);
expect(() => qb.get_where('galaxies',{}), 'valid table, empty where').to.throw(Error);
expect(() => qb.get_where('galaxies',[]), 'valid table, array for where').to.throw(Error);
expect(() => qb.get_where('galaxies',3), 'valid table, integer for where').to.throw(Error);
expect(() => qb.get_where('galaxies',33.3), 'valid table, float for where').to.throw(Error);
expect(() => qb.get_where('galaxies','foo'), 'valid table, string for where').to.throw(Error);
expect(() => qb.get_where('galaxies',true), 'valid table, TRUE for where').to.throw(Error);
expect(() => qb.get_where('galaxies',false), 'valid table, FALSE for where').to.throw(Error);
expect(() => qb.get_where('galaxies',Infinite), 'valid table, Infinite where').to.throw(Error);
expect(() => qb.get_where('galaxies',null), 'valid table, NULL where').to.throw(Error);
expect(() => qb.get_where('galaxies',{id: 3}), 'valid table, valid where').to.not.throw(Error);
});
it('should return a string', function() {
it('should return a string', () => {
qb.reset_query();
var sql = qb.get('galaxies', {type: 'spiral'});
const sql = qb.get('galaxies', {type: 'spiral'});
expect(sql).to.be.a('string');

@@ -178,9 +178,9 @@ expect(sql).to.exist;

});
it('should add table(s) to from_array and where items to where_array', function() {
it('should add table(s) to from_array and where items to where_array', () => {
qb.reset_query();
var sql = qb.get_where('galaxies', {type: 'spiral'});
const sql = qb.get_where('galaxies', {type: 'spiral'});
qb.from_array.should.eql(['`galaxies`']);
qb.where_array.should.eql(["`type` = 'spiral'"]);
sql.should.eql("SELECT * FROM `galaxies` WHERE `type` = 'spiral'");
sql.should.eql("SELECT * FROM `galaxies` WHERE `type` = 'spiral'");
});
});

@@ -1,19 +0,19 @@

var should = require('chai').should();
var expect = require('chai').expect;
var qb = require('../../drivers/mysql/query_builder.js').QueryBuilder();
const should = require('chai').should();
const expect = require('chai').expect;
const qb = require('../../drivers/mysql/query_builder.js').QueryBuilder();
describe('group_by()', function() {
it('should exist', function() {
describe('group_by()', () => {
it('should exist', () => {
should.exist(qb.group_by);
});
it('should be a function', function() {
it('should be a function', () => {
qb.group_by.should.be.a('function');
});
it('should have an array to put fields into', function() {
it('should have an array to put fields into', () => {
qb.should.have.property('group_by_array');
});
it('should have an empty array to put fields into at the beginning', function() {
it('should have an empty array to put fields into at the beginning', () => {
qb.group_by_array.should.be.empty;
});
it('should accept a single field in string form', function() {
it('should accept a single field in string form', () => {
qb.reset_query();

@@ -23,3 +23,3 @@ qb.group_by('planet_type');

});
it('should accept a multiple fields delimited by commas', function() {
it('should accept a multiple fields delimited by commas', () => {
qb.reset_query();

@@ -29,3 +29,3 @@ qb.group_by('planet_type, planet_position');

});
it('should accept an array of fields', function() {
it('should accept an array of fields', () => {
qb.reset_query();

@@ -35,20 +35,20 @@ qb.group_by(['planet_type', 'planet_position']);

});
it('should not accept anything but a string or an array of strings', function() {
it('should not accept anything but a string or an array of strings', () => {
qb.reset_query();
expect(function() { qb.group_by(); }, 'nothing provided').to.throw(Error);
expect(function() { qb.group_by(null); }, 'null provided').to.throw(Error);
expect(function() { qb.group_by(false); }, 'false provided').to.throw(Error);
expect(function() { qb.group_by(true); }, 'true provided').to.throw(Error);
expect(function() { qb.group_by({}); }, 'empty object provided').to.throw(Error);
expect(function() { qb.group_by(3); }, 'integer provided').to.throw(Error);
expect(function() { qb.group_by(3.5); }, 'float provided').to.throw(Error);
expect(function() { qb.group_by([]); }, 'empty array provided').to.throw(Error);
expect(function() { qb.group_by([1,2]); }, 'array of numbers provided').to.throw(Error);
expect(function() { qb.group_by(''); }, 'empty string provided').to.throw(Error);
expect(() => qb.group_by(), 'nothing provided').to.throw(Error);
expect(() => qb.group_by(null), 'null provided').to.throw(Error);
expect(() => qb.group_by(false), 'false provided').to.throw(Error);
expect(() => qb.group_by(true), 'true provided').to.throw(Error);
expect(() => qb.group_by({}), 'empty object provided').to.throw(Error);
expect(() => qb.group_by(3), 'integer provided').to.throw(Error);
expect(() => qb.group_by(3.5), 'float provided').to.throw(Error);
expect(() => qb.group_by([]), 'empty array provided').to.throw(Error);
expect(() => qb.group_by([1,2]), 'array of numbers provided').to.throw(Error);
expect(() => qb.group_by(''), 'empty string provided').to.throw(Error);
// valid string
expect(function() { qb.group_by('planet_type'); }, 'valid string provided').to.not.throw(Error);
expect(function() { qb.group_by(['planet_type']); }, 'array of string(s) provided').to.not.throw(Error);
expect(() => qb.group_by('planet_type'), 'valid string provided').to.not.throw(Error);
expect(() => qb.group_by(['planet_type']), 'array of string(s) provided').to.not.throw(Error);
});
});

@@ -1,40 +0,40 @@

var should = require('chai').should();
var expect = require('chai').expect;
var qb = require('../../drivers/mysql/query_builder.js').QueryBuilder();
const should = require('chai').should();
const expect = require('chai').expect;
const qb = require('../../drivers/mysql/query_builder.js').QueryBuilder();
describe('having()', function() {
it('should exist', function() {
describe('having()', () => {
it('should exist', () => {
should.exist(qb.having);
});
it('should be a function', function() {
it('should be a function', () => {
qb.having.should.be.a('function');
});
it('should have an array to put fields into', function() {
it('should have an array to put fields into', () => {
qb.should.have.property('having_array');
});
it('should accept a string only in this format: a [>|<|<>|>=|<=|=|!=] b for the first parameter', function() {
it('should accept a string only in this format: a [>|<|<>|>=|<=|=|!=] b for the first parameter', () => {
qb.reset_query();
qb.having('planet_class > "M"');
qb.having_array.should.eql(["`planet_class` > 'M'"]);
qb.reset_query();
qb.having('planet_class < "M"');
qb.having_array.should.eql(["`planet_class` < 'M'"]);
qb.reset_query();
qb.having('planet_class <> "M"');
qb.having_array.should.eql(["`planet_class` <> 'M'"]);
qb.reset_query();
qb.having('planet_class >= "M"');
qb.having_array.should.eql(["`planet_class` >= 'M'"]);
qb.reset_query();
qb.having('planet_class <= "M"');
qb.having_array.should.eql(["`planet_class` <= 'M'"]);
qb.reset_query();
qb.having('planet_class = "M"');
qb.having_array.should.eql(["`planet_class` = 'M'"]);
qb.reset_query();

@@ -44,7 +44,7 @@ qb.having('planet_class != "M"');

});
it('should not accept compound conditions in this format: a [>|<|<>|>=|<=|=|!=] b[, repeat[, etc...]]', function() {
it('should not accept compound conditions in this format: a [>|<|<>|>=|<=|=|!=] b[, repeat[, etc...]]', () => {
qb.reset_query();
expect(function() { qb.having('planet_class = "M", sentient_life = 1'); }, 'two conditions provided').to.throw(Error);
expect(() => qb.having('planet_class = "M", sentient_life = 1'), 'two conditions provided').to.throw(Error);
});
it('should accept an array of conditions and prepend AND to each condition following the first one', function() {
it('should accept an array of conditions and prepend AND to each condition following the first one', () => {
qb.reset_query();

@@ -54,5 +54,5 @@ qb.having(["planet_class = 'M'", 'sentient_life = 1']);

});
it('should accept an object of conditions and prepend AND to each condition following the first one', function() {
it('should accept an object of conditions and prepend AND to each condition following the first one', () => {
qb.reset_query();
var object = {planet_class: 'M', sentient_life: 1};
const object = {planet_class: 'M', sentient_life: 1};
object['planet_order <='] = 3;

@@ -62,20 +62,20 @@ qb.having(object);

});
it('should not accept anything but a non-empty array, object, or string', function() {
it('should not accept anything but a non-empty array, object, or string', () => {
qb.reset_query();
expect(function() { qb.group_by(); }, 'nothing provided').to.throw(Error);
expect(function() { qb.group_by(null); }, 'null provided').to.throw(Error);
expect(function() { qb.group_by(false); }, 'false provided').to.throw(Error);
expect(function() { qb.group_by(true); }, 'true provided').to.throw(Error);
expect(function() { qb.group_by({}); }, 'empty object provided').to.throw(Error);
expect(function() { qb.group_by(3); }, 'integer provided').to.throw(Error);
expect(function() { qb.group_by(3.5); }, 'float provided').to.throw(Error);
expect(function() { qb.group_by([]); }, 'empty array provided').to.throw(Error);
expect(function() { qb.group_by([1,2]); }, 'array of numbers provided').to.throw(Error);
expect(function() { qb.group_by(''); }, 'empty string provided').to.throw(Error);
expect(() => qb.group_by(), 'nothing provided').to.throw(Error);
expect(() => qb.group_by(null), 'null provided').to.throw(Error);
expect(() => qb.group_by(false), 'false provided').to.throw(Error);
expect(() => qb.group_by(true), 'true provided').to.throw(Error);
expect(() => qb.group_by({}), 'empty object provided').to.throw(Error);
expect(() => qb.group_by(3), 'integer provided').to.throw(Error);
expect(() => qb.group_by(3.5), 'float provided').to.throw(Error);
expect(() => qb.group_by([]), 'empty array provided').to.throw(Error);
expect(() => qb.group_by([1,2]), 'array of numbers provided').to.throw(Error);
expect(() => qb.group_by(''), 'empty string provided').to.throw(Error);
// valid string
expect(function() { qb.group_by('planet_type = "M"'); }, 'valid string provided').to.not.throw(Error);
expect(function() { qb.group_by(['planet_type = "M"']); }, 'array of string(s) provided').to.not.throw(Error);
expect(() => qb.group_by('planet_type = "M"'), 'valid string provided').to.not.throw(Error);
expect(() => qb.group_by(['planet_type = "M"']), 'array of string(s) provided').to.not.throw(Error);
});
it('should accept 2 parameters where the first one is the field with optional condition and the second one is the value', function() {
it('should accept 2 parameters where the first one is the field with optional condition and the second one is the value', () => {
qb.reset_query();

@@ -85,3 +85,3 @@ qb.having('planet_class','M');

});
it('should not escape conditions if asked not to', function() {
it('should not escape conditions if asked not to', () => {
qb.reset_query();

@@ -91,3 +91,3 @@ qb.having(["planet_class = 'M'", 'sentient_life = 1'], null, false);

});
it('should be chainable', function() {
it('should be chainable', () => {
qb.reset_query();

@@ -99,10 +99,10 @@ qb.having('planet_class','M').having('sentient_life',true).having('planet_order <=',3);

describe('or_having()', function() {
it('should exist', function() {
describe('or_having()', () => {
it('should exist', () => {
should.exist(qb.or_having);
});
it('should be a function', function() {
it('should be a function', () => {
qb.or_having.should.be.a('function');
});
it('should accept an array of conditions and prepend OR to each condition following the first one', function() {
it('should accept an array of conditions and prepend OR to each condition following the first one', () => {
qb.reset_query();

@@ -112,3 +112,3 @@ qb.or_having(["planet_class = 'M'", 'sentient_life = 1']);

});
it('should be chainable with normal having', function() {
it('should be chainable with normal having', () => {
qb.reset_query();

@@ -115,0 +115,0 @@ qb.having('planet_class','M').having('sentient_life',true).or_having('planet_order <=',3);

@@ -1,16 +0,16 @@

var should = require('chai').should();
var expect = require('chai').expect;
var qb = require('../../drivers/mysql/query_builder.js').QueryBuilder();
const should = require('chai').should();
const expect = require('chai').expect;
const qb = require('../../drivers/mysql/query_builder.js').QueryBuilder();
var test_where = {id:3};
var test_data = [{id:3, name:'Milky Way', type: 'spiral'}, {id:4, name: 'Andromeda', type: 'spiral'}];
const test_where = {id:3};
const test_data = [{id:3, name:'Milky Way', type: 'spiral'}, {id:4, name: 'Andromeda', type: 'spiral'}];
describe('insert_batch()', function() {
it('should exist', function() {
describe('insert_batch()', () => {
it('should exist', () => {
should.exist(qb.insert_batch);
});
it('should be a function', function() {
it('should be a function', () => {
qb.insert_batch.should.be.a('function');
});
it('should add a table to from_array when a table is supplied', function() {
it('should add a table to from_array when a table is supplied', () => {
qb.reset_query();

@@ -20,85 +20,85 @@ qb.insert_batch('galaxies', test_data);

});
it('should only accept nothing or a string for the table (first) parameter', function() {
it('should only accept nothing or a string for the table (first) parameter', () => {
qb.reset_query();
// Doing these to prevent other errors
qb.from('galaxies');
expect(function() { qb.insert_batch([], test_data); }, 'empty array provided').to.throw(Error);
expect(function() { qb.insert_batch({}, test_data); }, 'empty object provided').to.throw(Error);
expect(function() { qb.insert_batch(3, test_data); }, 'integer provided').to.throw(Error);
expect(function() { qb.insert_batch(3.5, test_data); }, 'float provided').to.throw(Error);
expect(function() { qb.insert_batch(true, test_data); }, 'true provided').to.throw(Error);
expect(function() { qb.insert_batch(Infinity, test_data); }, 'Infinity provided').to.throw(Error);
expect(function() { qb.insert_batch([1,2], test_data); }, 'array of numbers provided').to.throw(Error);
expect(function() { qb.insert_batch(/foobar/, test_data); }, 'regex provided').to.throw(Error);
expect(function() { qb.insert_batch(NaN, test_data); }, 'NaN provided').to.not.throw(Error);
expect(function() { qb.insert_batch(false, test_data); }, 'false provided').to.not.throw(Error);
expect(function() { qb.insert_batch('', test_data); }, 'empty string provided').to.not.throw(Error);
expect(function() { qb.insert_batch(' ', test_data); }, 'string full of spaces provided').to.not.throw(Error);
expect(function() { qb.insert_batch(null, test_data); }, 'null provided').to.not.throw(Error);
expect(function() { qb.insert_batch(undefined, test_data); }, 'undefined provided').to.not.throw(Error);
qb.from('galaxies');
expect(() => qb.insert_batch([], test_data), 'empty array provided').to.throw(Error);
expect(() => qb.insert_batch({}, test_data), 'empty object provided').to.throw(Error);
expect(() => qb.insert_batch(3, test_data), 'integer provided').to.throw(Error);
expect(() => qb.insert_batch(3.5, test_data), 'float provided').to.throw(Error);
expect(() => qb.insert_batch(true, test_data), 'true provided').to.throw(Error);
expect(() => qb.insert_batch(Infinity, test_data), 'Infinity provided').to.throw(Error);
expect(() => qb.insert_batch([1,2], test_data), 'array of numbers provided').to.throw(Error);
expect(() => qb.insert_batch(/foobar/, test_data), 'regex provided').to.throw(Error);
expect(() => qb.insert_batch(NaN, test_data), 'NaN provided').to.not.throw(Error);
expect(() => qb.insert_batch(false, test_data), 'false provided').to.not.throw(Error);
expect(() => qb.insert_batch('', test_data), 'empty string provided').to.not.throw(Error);
expect(() => qb.insert_batch(' ', test_data), 'string full of spaces provided').to.not.throw(Error);
expect(() => qb.insert_batch(null, test_data), 'null provided').to.not.throw(Error);
expect(() => qb.insert_batch(undefined, test_data), 'undefined provided').to.not.throw(Error);
});
it('should build a proper batch INSERT string', function() {
it('should build a proper batch INSERT string', () => {
qb.reset_query();
var sql = qb.insert_batch('galaxies', test_data);
const sql = qb.insert_batch('galaxies', test_data);
sql.should.eql("INSERT INTO `galaxies` (`id`, `name`, `type`) VALUES (3, 'Milky Way', 'spiral'), (4, 'Andromeda', 'spiral')");
});
it('should only accept an array as the second parameter', function() {
it('should only accept an array as the second parameter', () => {
qb.reset_query();
expect(function() { qb.insert_batch('galaxies',test_data); }, 'array of objects provided').to.not.throw(Error);
expect(function() { qb.insert_batch('galaxies',[]); }, 'empty array provided').to.not.throw(Error);
expect(function() { qb.insert_batch('galaxies',[{},{}]); }, 'array of empty objects provided').to.throw(Error);
expect(function() { qb.insert_batch('galaxies',[test_data,test_data]); }, 'array of arrays provided').to.throw(Error);
expect(function() { qb.insert_batch('galaxies',{}); }, 'empty object provided').to.throw(Error);
expect(function() { qb.insert_batch('galaxies',''); }, 'empty string provided').to.throw(Error);
expect(function() { qb.insert_batch('galaxies',null); }, 'null provided').to.throw(Error);
expect(function() { qb.insert_batch('galaxies',undefined); }, 'undefined provided').to.throw(Error);
expect(function() { qb.insert_batch('galaxies'); }, 'nothing provided').to.throw(Error);
expect(function() { qb.insert_batch('galaxies',3); }, 'integer provided').to.throw(Error);
expect(function() { qb.insert_batch('galaxies',3.5); }, 'float provided').to.throw(Error);
expect(function() { qb.insert_batch('galaxies',true); }, 'true provided').to.throw(Error);
expect(function() { qb.insert_batch('galaxies',Infinity); }, 'Infinity provided').to.throw(Error);
expect(function() { qb.insert_batch('galaxies',[1,2]); }, 'array of numbers provided').to.throw(Error);
expect(function() { qb.insert_batch('galaxies',[Date, /foobar/, null]); }, 'array of non-standard objects provided').to.throw(Error);
expect(function() { qb.insert_batch('galaxies',['abc',2,{foo:'bar'}]); }, 'array of mixed values provided').to.throw(Error);
expect(function() { qb.insert_batch('galaxies',/foobar/); }, 'regex provided').to.throw(Error);
expect(function() { qb.insert_batch('galaxies',NaN); }, 'NaN provided').to.throw(Error);
expect(function() { qb.insert_batch('galaxies',false); }, 'false provided').to.throw(Error);
expect(function() { qb.insert_batch('galaxies',' '); }, 'string full of spaces provided').to.throw(Error);
expect(() => qb.insert_batch('galaxies',test_data), 'array of objects provided').to.not.throw(Error);
expect(() => qb.insert_batch('galaxies',[]), 'empty array provided').to.not.throw(Error);
expect(() => qb.insert_batch('galaxies',[{},{}]), 'array of empty objects provided').to.throw(Error);
expect(() => qb.insert_batch('galaxies',[test_data,test_data]), 'array of arrays provided').to.throw(Error);
expect(() => qb.insert_batch('galaxies',{}), 'empty object provided').to.throw(Error);
expect(() => qb.insert_batch('galaxies',''), 'empty string provided').to.throw(Error);
expect(() => qb.insert_batch('galaxies',null), 'null provided').to.throw(Error);
expect(() => qb.insert_batch('galaxies',undefined), 'undefined provided').to.throw(Error);
expect(() => qb.insert_batch('galaxies'), 'nothing provided').to.throw(Error);
expect(() => qb.insert_batch('galaxies',3), 'integer provided').to.throw(Error);
expect(() => qb.insert_batch('galaxies',3.5), 'float provided').to.throw(Error);
expect(() => qb.insert_batch('galaxies',true), 'true provided').to.throw(Error);
expect(() => qb.insert_batch('galaxies',Infinity), 'Infinity provided').to.throw(Error);
expect(() => qb.insert_batch('galaxies',[1,2]), 'array of numbers provided').to.throw(Error);
expect(() => qb.insert_batch('galaxies',[Date, /foobar/, null]), 'array of non-standard objects provided').to.throw(Error);
expect(() => qb.insert_batch('galaxies',['abc',2,{foo:'bar'}]), 'array of mixed values provided').to.throw(Error);
expect(() => qb.insert_batch('galaxies',/foobar/), 'regex provided').to.throw(Error);
expect(() => qb.insert_batch('galaxies',NaN), 'NaN provided').to.throw(Error);
expect(() => qb.insert_batch('galaxies',false), 'false provided').to.throw(Error);
expect(() => qb.insert_batch('galaxies',' '), 'string full of spaces provided').to.throw(Error);
});
it('should allow for an empty data parameter', function() {
it('should allow for an empty data parameter', () => {
qb.reset_query();
var sql = qb.insert_batch('galaxies',[]);
const sql = qb.insert_batch('galaxies',[]);
sql.should.eql("INSERT INTO `galaxies` () VALUES ()");
});
it('should utilize pre-existing tables set in from_array', function() {
it('should utilize pre-existing tables set in from_array', () => {
qb.reset_query();
qb.from('galaxies');
var sql = qb.insert_batch(null,[]);
const sql = qb.insert_batch(null,[]);
sql.should.eql("INSERT INTO `galaxies` () VALUES ()");
});
it('should fail if any invalid values are passed into one of the data objects in the dataset', function() {
it('should fail if any invalid values are passed into one of the data objects in the dataset', () => {
qb.reset_query();
var func = function() { console.log("foo"); };
var regex = /foobar/;
var arr = [1,2,3];
var obj = {foo: 'bar'};
expect(function() { qb.insert_batch('galaxies',[{id: func}]); }, 'function in data').to.throw(Error);
expect(function() { qb.insert_batch('galaxies',[{id: regex}]); }, 'regex in data').to.throw(Error);
expect(function() { qb.insert_batch('galaxies',[{id: Infinity}]); }, 'Infinity in data').to.throw(Error);
expect(function() { qb.insert_batch('galaxies',[{id: undefined}]); }, 'undefined in data').to.throw(Error);
expect(function() { qb.insert_batch('galaxies',[{id: NaN}]); }, 'NaN in data').to.throw(Error);
expect(function() { qb.insert_batch('galaxies',[{id: arr}]); }, 'array in data').to.throw(Error);
expect(function() { qb.insert_batch('galaxies',[{id: obj}]); }, 'object in data').to.throw(Error);
const func = () => console.log("foo");
const regex = /foobar/;
const arr = [1,2,3];
const obj = {foo: 'bar'};
expect(() => qb.insert_batch('galaxies',[{id: func}]), 'function in data').to.throw(Error);
expect(() => qb.insert_batch('galaxies',[{id: regex}]), 'regex in data').to.throw(Error);
expect(() => qb.insert_batch('galaxies',[{id: Infinity}]), 'Infinity in data').to.throw(Error);
expect(() => qb.insert_batch('galaxies',[{id: undefined}]), 'undefined in data').to.throw(Error);
expect(() => qb.insert_batch('galaxies',[{id: NaN}]), 'NaN in data').to.throw(Error);
expect(() => qb.insert_batch('galaxies',[{id: arr}]), 'array in data').to.throw(Error);
expect(() => qb.insert_batch('galaxies',[{id: obj}]), 'object in data').to.throw(Error);
});
it('should support insert ignore statements', function() {
it('should support insert ignore statements', () => {
qb.reset_query();
var sql = qb.insert_batch('galaxies', test_data, true, 'ON DUPLICATE KEY UPDATE last_update = NOW()');
const sql = qb.insert_batch('galaxies', test_data, true, 'ON DUPLICATE KEY UPDATE last_update = NOW()');
sql.should.eql("INSERT IGNORE INTO `galaxies` (`id`, `name`, `type`) VALUES (3, 'Milky Way', 'spiral'), (4, 'Andromeda', 'spiral') ON DUPLICATE KEY UPDATE last_update = NOW()");
});
});

@@ -1,18 +0,18 @@

var should = require('chai').should();
var expect = require('chai').expect;
var qb = require('../../drivers/mysql/query_builder.js').QueryBuilder();
const should = require('chai').should();
const expect = require('chai').expect;
const qb = require('../../drivers/mysql/query_builder.js').QueryBuilder();
var test_data = {id:3, name:'Milky Way', type: 'spiral'};
var test_data_set = [{id:3, name:'Milky Way', type: 'spiral'}, {id:4, name: 'Andromeda', type: 'spiral'}];
const test_data = {id:3, name:'Milky Way', type: 'spiral'};
const test_data_set = [{id:3, name:'Milky Way', type: 'spiral'}, {id:4, name: 'Andromeda', type: 'spiral'}];
// table, data, callback, ignore, suffix
describe('insert()', function() {
it('should exist', function() {
describe('insert()', () => {
it('should exist', () => {
should.exist(qb.insert);
});
it('should be a function', function() {
it('should be a function', () => {
qb.insert.should.be.a('function');
});
it('should add a table to from_array when a table is supplied', function() {
it('should add a table to from_array when a table is supplied', () => {
qb.reset_query();

@@ -22,3 +22,3 @@ qb.insert('galaxies', test_data);

});
it('should only accept nothing or a string for the table (first) parameter', function() {
it('should only accept nothing or a string for the table (first) parameter', () => {
qb.reset_query();

@@ -29,94 +29,94 @@

expect(function() { qb.insert([], test_data); }, 'empty array provided').to.throw(Error);
expect(function() { qb.insert({}, test_data); }, 'empty object provided').to.throw(Error);
expect(function() { qb.insert(3, test_data); }, 'integer provided').to.throw(Error);
expect(function() { qb.insert(3.5, test_data); }, 'float provided').to.throw(Error);
expect(function() { qb.insert(true, test_data); }, 'true provided').to.throw(Error);
expect(function() { qb.insert(Infinity, test_data); }, 'Infinity provided').to.throw(Error);
expect(function() { qb.insert([1,2], test_data); }, 'array of numbers provided').to.throw(Error);
expect(function() { qb.insert(/foobar/, test_data); }, 'regex provided').to.throw(Error);
expect(() => qb.insert([], test_data), 'empty array provided').to.throw(Error);
expect(() => qb.insert({}, test_data), 'empty object provided').to.throw(Error);
expect(() => qb.insert(3, test_data), 'integer provided').to.throw(Error);
expect(() => qb.insert(3.5, test_data), 'float provided').to.throw(Error);
expect(() => qb.insert(true, test_data), 'true provided').to.throw(Error);
expect(() => qb.insert(Infinity, test_data), 'Infinity provided').to.throw(Error);
expect(() => qb.insert([1,2], test_data), 'array of numbers provided').to.throw(Error);
expect(() => qb.insert(/foobar/, test_data), 'regex provided').to.throw(Error);
expect(function() { qb.insert(NaN, test_data); }, 'NaN provided').to.not.throw(Error);
expect(function() { qb.insert(false, test_data); }, 'false provided').to.not.throw(Error);
expect(function() { qb.insert('', test_data); }, 'empty string provided').to.not.throw(Error);
expect(function() { qb.insert(' ', test_data); }, 'string full of spaces provided').to.not.throw(Error);
expect(function() { qb.insert(null, test_data); }, 'null provided').to.not.throw(Error);
expect(function() { qb.insert(undefined, test_data);},'undefined provided').to.not.throw(Error);
expect(() => qb.insert(NaN, test_data), 'NaN provided').to.not.throw(Error);
expect(() => qb.insert(false, test_data), 'false provided').to.not.throw(Error);
expect(() => qb.insert('', test_data), 'empty string provided').to.not.throw(Error);
expect(() => qb.insert(' ', test_data), 'string full of spaces provided').to.not.throw(Error);
expect(() => qb.insert(null, test_data), 'null provided').to.not.throw(Error);
expect(() => qb.insert(undefined, test_data),'undefined provided').to.not.throw(Error);
});
it('should fail if a number, non-standard object, regex, boolean, array of non-objects, or non-empty string is provided in data parameter', function() {
it('should fail if a number, non-standard object, regex, boolean, array of non-objects, or non-empty string is provided in data parameter', () => {
qb.reset_query();
expect(function() { qb.insert('galaxies',test_data); }, 'non-empty array provided').to.not.throw(Error);
expect(function() { qb.insert('galaxies',[]); }, 'empty array provided').to.not.throw(Error);
expect(function() { qb.insert('galaxies',[test_data,test_data]);}, 'array of non-empty standard objects provided').to.not.throw(Error);
expect(function() { qb.insert('galaxies',{}); }, 'empty object provided').to.not.throw(Error);
expect(function() { qb.insert('galaxies',''); }, 'empty string provided').to.not.throw(Error);
expect(function() { qb.insert('galaxies',null); }, 'null provided').to.not.throw(Error);
expect(function() { qb.insert('galaxies',undefined); }, 'undefined provided').to.not.throw(Error);
expect(function() { qb.insert('galaxies'); }, 'nothing provided').to.not.throw(Error);
expect(() => qb.insert('galaxies',test_data), 'non-empty array provided').to.not.throw(Error);
expect(() => qb.insert('galaxies',[]), 'empty array provided').to.not.throw(Error);
expect(() => qb.insert('galaxies',[test_data,test_data]), 'array of non-empty standard objects provided').to.not.throw(Error);
expect(() => qb.insert('galaxies',{}), 'empty object provided').to.not.throw(Error);
expect(() => qb.insert('galaxies',''), 'empty string provided').to.not.throw(Error);
expect(() => qb.insert('galaxies',null), 'null provided').to.not.throw(Error);
expect(() => qb.insert('galaxies',undefined), 'undefined provided').to.not.throw(Error);
expect(() => qb.insert('galaxies'), 'nothing provided').to.not.throw(Error);
expect(function() { qb.insert('galaxies',3); }, 'integer provided').to.throw(Error);
expect(function() { qb.insert('galaxies',3.5); }, 'float provided').to.throw(Error);
expect(function() { qb.insert('galaxies',true); }, 'true provided').to.throw(Error);
expect(function() { qb.insert('galaxies',Infinity); }, 'Infinity provided').to.throw(Error);
expect(function() { qb.insert('galaxies',[{},{}]); }, 'array of empty objects provided').to.throw(Error);
expect(function() { qb.insert('galaxies',[1,2]); }, 'array of numbers provided').to.throw(Error);
expect(function() { qb.insert('galaxies',['abc',2,{foo:'bar'}]);}, 'array of mixed values provided').to.throw(Error);
expect(function() { qb.insert('galaxies',/foobar/); }, 'regex provided').to.throw(Error);
expect(function() { qb.insert('galaxies',NaN); }, 'NaN provided').to.throw(Error);
expect(function() { qb.insert('galaxies',false); }, 'false provided').to.throw(Error);
expect(function() { qb.insert('galaxies',' '); }, 'string full of spaces provided').to.throw(Error);
expect(() => qb.insert('galaxies',3), 'integer provided').to.throw(Error);
expect(() => qb.insert('galaxies',3.5), 'float provided').to.throw(Error);
expect(() => qb.insert('galaxies',true), 'true provided').to.throw(Error);
expect(() => qb.insert('galaxies',Infinity), 'Infinity provided').to.throw(Error);
expect(() => qb.insert('galaxies',[{},{}]), 'array of empty objects provided').to.throw(Error);
expect(() => qb.insert('galaxies',[1,2]), 'array of numbers provided').to.throw(Error);
expect(() => qb.insert('galaxies',['abc',2,{foo:'bar'}]), 'array of mixed values provided').to.throw(Error);
expect(() => qb.insert('galaxies',/foobar/), 'regex provided').to.throw(Error);
expect(() => qb.insert('galaxies',NaN), 'NaN provided').to.throw(Error);
expect(() => qb.insert('galaxies',false), 'false provided').to.throw(Error);
expect(() => qb.insert('galaxies',' '), 'string full of spaces provided').to.throw(Error);
});
it('should allow for an empty data parameter', function() {
it('should allow for an empty data parameter', () => {
qb.reset_query();
var sql = qb.insert('galaxies');
const sql = qb.insert('galaxies');
sql.should.eql("INSERT INTO `galaxies` () VALUES ()");
});
it('should utilize pre-existing tables set in from_array', function() {
it('should utilize pre-existing tables set in from_array', () => {
qb.reset_query();
qb.from('galaxies');
var sql = qb.insert();
const sql = qb.insert();
sql.should.eql("INSERT INTO `galaxies` () VALUES ()");
});
it('should utilize pre-existing values set in in set_array', function() {
it('should utilize pre-existing values set in in set_array', () => {
qb.reset_query();
qb.set(test_data);
var sql = qb.insert('galaxies');
const sql = qb.insert('galaxies');
sql.should.eql("INSERT INTO `galaxies` (`id`, `name`, `type`) VALUES (3, 'Milky Way', 'spiral')");
});
it('should utilize pre-existing tables and values from from_aray and set_array, respectively', function() {
it('should utilize pre-existing tables and values from from_aray and set_array, respectively', () => {
qb.reset_query();
qb.from('galaxies').set(test_data);
var sql = qb.insert();
const sql = qb.insert();
sql.should.eql("INSERT INTO `galaxies` (`id`, `name`, `type`) VALUES (3, 'Milky Way', 'spiral')");
});
it('should accept a non-empty object for the data parameter', function() {
it('should accept a non-empty object for the data parameter', () => {
qb.reset_query();
var sql = qb.insert('galaxies', test_data);
const sql = qb.insert('galaxies', test_data);
sql.should.eql("INSERT INTO `galaxies` (`id`, `name`, `type`) VALUES (3, 'Milky Way', 'spiral')");
});
it('should convert call to insert_batch() if an array of non-emtpy objects is passed in the data parameter', function() {
it('should convert call to insert_batch() if an array of non-emtpy objects is passed in the data parameter', () => {
qb.reset_query();
var sql = qb.insert('galaxies', test_data_set);
var sql_b = qb.insert_batch('galaxies', test_data_set);
const sql = qb.insert('galaxies', test_data_set);
const sql_b = qb.insert_batch('galaxies', test_data_set);
sql.should.eql(sql_b);
});
it('should fail if any invalid values are passed in the data object.', function() {
it('should fail if any invalid values are passed in the data object.', () => {
qb.reset_query();
var func = function() { console.log("foo"); };
var regex = /foobar/;
var arr = [1,2,3];
var obj = {foo: 'bar'};
const func = () => console.log("foo");
const regex = /foobar/;
const arr = [1,2,3];
const obj = {foo: 'bar'};
expect(function() { qb.insert('galaxies',{id: 1}); }, 'number in data').to.not.throw(Error);
expect(function() { qb.insert('galaxies',{id: 'foo'}); }, 'string in data').to.not.throw(Error);
expect(function() { qb.insert('galaxies',{id: false}); }, 'boolean in data').to.not.throw(Error);
expect(function() { qb.insert('galaxies',{id: null}); }, 'null in data').to.not.throw(Error);
expect(function() { qb.insert('galaxies',{id: undefined}); }, 'undefined in data').to.not.throw(Error);
expect(function() { qb.insert('galaxies',{id: func}); }, 'function in data').to.throw(Error);
expect(function() { qb.insert('galaxies',{id: regex}); }, 'regex in data').to.throw(Error);
expect(function() { qb.insert('galaxies',{id: Infinity}); }, 'Infinity in data').to.throw(Error);
expect(function() { qb.insert('galaxies',{id: NaN}); }, 'NaN in data').to.throw(Error);
expect(function() { qb.insert('galaxies',{id: arr}); }, 'array in data').to.throw(Error);
expect(function() { qb.insert('galaxies',{id: obj}); }, 'object in data').to.throw(Error);
expect(() => qb.insert('galaxies',{id: 1}), 'number in data').to.not.throw(Error);
expect(() => qb.insert('galaxies',{id: 'foo'}), 'string in data').to.not.throw(Error);
expect(() => qb.insert('galaxies',{id: false}), 'boolean in data').to.not.throw(Error);
expect(() => qb.insert('galaxies',{id: null}), 'null in data').to.not.throw(Error);
expect(() => qb.insert('galaxies',{id: undefined}), 'undefined in data').to.not.throw(Error);
expect(() => qb.insert('galaxies',{id: func}), 'function in data').to.throw(Error);
expect(() => qb.insert('galaxies',{id: regex}), 'regex in data').to.throw(Error);
expect(() => qb.insert('galaxies',{id: Infinity}), 'Infinity in data').to.throw(Error);
expect(() => qb.insert('galaxies',{id: NaN}), 'NaN in data').to.throw(Error);
expect(() => qb.insert('galaxies',{id: arr}), 'array in data').to.throw(Error);
expect(() => qb.insert('galaxies',{id: obj}), 'object in data').to.throw(Error);

@@ -126,30 +126,30 @@ });

describe('insert_ignore()', function() {
it('should exist', function() {
describe('insert_ignore()', () => {
it('should exist', () => {
should.exist(qb.insert_ignore);
});
it('should be a function', function() {
it('should be a function', () => {
qb.insert_ignore.should.be.a('function');
});
it('should create an INSERT IGNORE statement', function() {
it('should create an INSERT IGNORE statement', () => {
qb.reset_query();
var sql = qb.insert_ignore('galaxies', test_data);
const sql = qb.insert_ignore('galaxies', test_data);
sql.should.eql("INSERT IGNORE INTO `galaxies` (`id`, `name`, `type`) VALUES (3, 'Milky Way', 'spiral')");
});
it('should be just a wrapper of insert() that passes true to the 3rd parameter', function() {
it('should be just a wrapper of insert() that passes true to the 3rd parameter', () => {
qb.reset_query();
var sql = qb.insert_ignore('galaxies', test_data);
var sql_b = qb.insert('galaxies', test_data, true);
const sql = qb.insert_ignore('galaxies', test_data);
const sql_b = qb.insert('galaxies', test_data, true);
sql.should.eql(sql_b);
});
it('should convert to insert_batch() if an array of data is supplied to second parameter', function() {
it('should convert to insert_batch() if an array of data is supplied to second parameter', () => {
qb.reset_query();
var sql = qb.insert_ignore('galaxies', test_data_set);
const sql = qb.insert_ignore('galaxies', test_data_set);
sql.should.eql("INSERT IGNORE INTO `galaxies` (`id`, `name`, `type`) VALUES (3, 'Milky Way', 'spiral'), (4, 'Andromeda', 'spiral')");
});
it('should support the "on_dupe" suffix parameter... effectively appending to the query anything supplied in this parameter', function() {
it('should support the "on_dupe" suffix parameter... effectively appending to the query anything supplied in this parameter', () => {
qb.reset_query();
var sql = qb.insert_ignore('galaxies', test_data, 'ON DUPLICATE KEY UPDATE last_update = NOW()');
const sql = qb.insert_ignore('galaxies', test_data, 'ON DUPLICATE KEY UPDATE last_update = NOW()');
sql.should.eql("INSERT IGNORE INTO `galaxies` (`id`, `name`, `type`) VALUES (3, 'Milky Way', 'spiral') ON DUPLICATE KEY UPDATE last_update = NOW()");
});
});

@@ -1,32 +0,32 @@

var should = require('chai').should();
var expect = require('chai').expect;
var qb = require('../../drivers/mysql/query_builder.js').QueryBuilder();
const should = require('chai').should();
const expect = require('chai').expect;
const qb = require('../../drivers/mysql/query_builder.js').QueryBuilder();
describe('join()', function() {
it('should exist', function() {
describe('join()', () => {
it('should exist', () => {
should.exist(qb.join);
});
it('should be a function', function() {
it('should be a function', () => {
qb.join.should.be.a('function');
});
it('should have an array to put fields into', function() {
it('should have an array to put fields into', () => {
qb.should.have.property('join_array');
});
it('should have an empty array to put fields into at the beginning', function() {
it('should have an empty array to put fields into at the beginning', () => {
qb.join_array.should.be.empty;
});
it('should require a string to be passed as first parameter', function() {
var invalid_match = /must provide a table/;
expect(function() { qb.join(); }, 'nothing provided').to.throw(Error, invalid_match);
expect(function() { qb.join(true); }, 'true provided').to.throw(Error, invalid_match);
expect(function() { qb.join(null); }, 'null provided').to.throw(Error, invalid_match);
expect(function() { qb.join(false); }, 'false provided').to.throw(Error, invalid_match);
expect(function() { qb.join({}); }, 'object provided').to.throw(Error, invalid_match);
expect(function() { qb.join([]); }, 'empty array provided').to.throw(Error, invalid_match);
expect(function() { qb.join(''); }, 'empty string provided').to.throw(Error, invalid_match);
expect(function() { qb.join(' '); }, 'string of spaces provided').to.throw(Error, invalid_match);
expect(function() { qb.join('foo'); }, 'valid string provided').to.not.throw(Error);
expect(function() { qb.join('foo'); }, 'valid string provided').to.not.throw(Error);
it('should require a string to be passed as first parameter', () => {
const invalid_match = /must provide a table/;
expect(() => qb.join(), 'nothing provided').to.throw(Error, invalid_match);
expect(() => qb.join(true), 'true provided').to.throw(Error, invalid_match);
expect(() => qb.join(null), 'null provided').to.throw(Error, invalid_match);
expect(() => qb.join(false), 'false provided').to.throw(Error, invalid_match);
expect(() => qb.join({}), 'object provided').to.throw(Error, invalid_match);
expect(() => qb.join([]), 'empty array provided').to.throw(Error, invalid_match);
expect(() => qb.join(''), 'empty string provided').to.throw(Error, invalid_match);
expect(() => qb.join(' '), 'string of spaces provided').to.throw(Error, invalid_match);
expect(() => qb.join('foo'), 'valid string provided').to.not.throw(Error);
expect(() => qb.join('foo'), 'valid string provided').to.not.throw(Error);
});
it('should except single item and add it to join array as basic join and escape item', function() {
it('should except single item and add it to join array as basic join and escape item', () => {
qb.reset_query();

@@ -36,3 +36,3 @@ qb.join('universe');

});
it('should except single item with alias and add it to join array as basic join and escape each part', function() {
it('should except single item with alias and add it to join array as basic join and escape each part', () => {
qb.reset_query();

@@ -42,40 +42,40 @@ qb.join('universe u');

});
it('should allow a string (and only a string) to be passed as second parameter but only if a valid (or no) third parameter is provided', function() {
var invalid_2nd_param = /You must provide a valid condition to join on when providing a join direction/;
var invalid_direction = /Invalid join direction provided as third parameter/;
it('should allow a string (and only a string) to be passed as second parameter but only if a valid (or no) third parameter is provided', () => {
const invalid_2nd_param = /You must provide a valid condition to join on when providing a join direction/;
const invalid_direction = /Invalid join direction provided as third parameter/;
expect(function() { qb.join('universe',null,'left'); }, 'null 2nd param').to.throw(Error,invalid_2nd_param);
expect(function() { qb.join('universe',false,'left'); }, 'false 2nd param').to.throw(Error,invalid_2nd_param);
expect(function() { qb.join('universe','','left'); }, 'empty string 2nd param').to.throw(Error,invalid_2nd_param);
expect(function() { qb.join('universe',' ','left'); }, 'just spaces 2nd param').to.throw(Error,invalid_2nd_param);
expect(function() { qb.join('universe',5,'left'); }, 'integer 2nd param').to.throw(Error,invalid_2nd_param);
expect(function() { qb.join('universe',5.6,'left'); }, 'float 2nd param').to.throw(Error,invalid_2nd_param);
expect(function() { qb.join('universe',[],'left'); }, 'array 2nd param').to.throw(Error,invalid_2nd_param);
expect(function() { qb.join('universe',{},'left'); }, 'object 2nd param').to.throw(Error,invalid_2nd_param);
expect(function() { qb.join('universe','foo = bar','fake'); }, 'invalid 3rd param').to.throw(Error,invalid_direction);
expect(function() { qb.join('universe','foo = bar'); }, 'no 3rd param').to.not.throw(Error);
expect(function() { qb.join('universe','foo = bar','left'); }, '3 valid params').to.not.throw(Error);
expect(() => qb.join('universe',null,'left'), 'null 2nd param').to.throw(Error,invalid_2nd_param);
expect(() => qb.join('universe',false,'left'), 'false 2nd param').to.throw(Error,invalid_2nd_param);
expect(() => qb.join('universe','','left'), 'empty string 2nd param').to.throw(Error,invalid_2nd_param);
expect(() => qb.join('universe',' ','left'), 'just spaces 2nd param').to.throw(Error,invalid_2nd_param);
expect(() => qb.join('universe',5,'left'), 'integer 2nd param').to.throw(Error,invalid_2nd_param);
expect(() => qb.join('universe',5.6,'left'), 'float 2nd param').to.throw(Error,invalid_2nd_param);
expect(() => qb.join('universe',[],'left'), 'array 2nd param').to.throw(Error,invalid_2nd_param);
expect(() => qb.join('universe',{},'left'), 'object 2nd param').to.throw(Error,invalid_2nd_param);
expect(() => qb.join('universe','foo = bar','fake'), 'invalid 3rd param').to.throw(Error,invalid_direction);
expect(() => qb.join('universe','foo = bar'), 'no 3rd param').to.not.throw(Error);
expect(() => qb.join('universe','foo = bar','left'), '3 valid params').to.not.throw(Error);
});
it('should allow valid join direction to be passed in third parameter', function() {
it('should allow valid join direction to be passed in third parameter', () => {
// NOTE: A lot of this functionality was already tested when testing second param
var invalid_direction = /Invalid join direction provided as third parameter/;
const invalid_direction = /Invalid join direction provided as third parameter/;
expect(function() { qb.join('universe','foo = bar','fake'); }, 'invalid 3rd param').to.throw(Error,invalid_direction);
expect(function() { qb.join('universe',null,null); }, 'invalid 2nd and 3rd params').to.not.throw(Error);
expect(function() { qb.join('universe','foo = bar',''); }, 'empty third param').to.not.throw(Error);
expect(function() { qb.join('universe','foo = bar',' '); }, 'just spaces').to.not.throw(Error);
expect(function() { qb.join('universe','foo = bar',null); }, 'null third param').to.not.throw(Error);
expect(function() { qb.join('universe','foo = bar',false); }, 'false third param').to.not.throw(Error);
expect(function() { qb.join('universe','foo = bar',5); }, 'integer third param').to.not.throw(Error);
expect(function() { qb.join('universe','foo = bar',5.5); }, 'float third param').to.not.throw(Error);
expect(function() { qb.join('universe','foo = bar',{}); }, 'object third param').to.not.throw(Error);
expect(function() { qb.join('universe','foo = bar',[]); }, 'array third param').to.not.throw(Error);
expect(function() { qb.join('universe','foo = bar','left '); }, 'trailing space').to.not.throw(Error);
expect(function() { qb.join('universe','foo = bar',' left '); }, 'leading and trailing space').to.not.throw(Error);
expect(function() { qb.join('universe','foo = bar',' left'); }, 'leading space').to.not.throw(Error);
expect(function() { qb.join('universe','foo = bar','left'); }, 'lowercase direction').to.not.throw(Error);
expect(function() { qb.join('universe','foo = bar','LEFT'); }, 'uppercase direction').to.not.throw(Error);
expect(function() { qb.join('universe','foo = bar','LEFT OUTER'); }, 'two word direction').to.not.throw(Error);
expect(() => qb.join('universe','foo = bar','fake'), 'invalid 3rd param').to.throw(Error,invalid_direction);
expect(() => qb.join('universe',null,null), 'invalid 2nd and 3rd params').to.not.throw(Error);
expect(() => qb.join('universe','foo = bar',''), 'empty third param').to.not.throw(Error);
expect(() => qb.join('universe','foo = bar',' '), 'just spaces').to.not.throw(Error);
expect(() => qb.join('universe','foo = bar',null), 'null third param').to.not.throw(Error);
expect(() => qb.join('universe','foo = bar',false), 'false third param').to.not.throw(Error);
expect(() => qb.join('universe','foo = bar',5), 'integer third param').to.not.throw(Error);
expect(() => qb.join('universe','foo = bar',5.5), 'float third param').to.not.throw(Error);
expect(() => qb.join('universe','foo = bar',{}), 'object third param').to.not.throw(Error);
expect(() => qb.join('universe','foo = bar',[]), 'array third param').to.not.throw(Error);
expect(() => qb.join('universe','foo = bar','left '), 'trailing space').to.not.throw(Error);
expect(() => qb.join('universe','foo = bar',' left '), 'leading and trailing space').to.not.throw(Error);
expect(() => qb.join('universe','foo = bar',' left'), 'leading space').to.not.throw(Error);
expect(() => qb.join('universe','foo = bar','left'), 'lowercase direction').to.not.throw(Error);
expect(() => qb.join('universe','foo = bar','LEFT'), 'uppercase direction').to.not.throw(Error);
expect(() => qb.join('universe','foo = bar','LEFT OUTER'), 'two word direction').to.not.throw(Error);
});
it('should except a valid second parameter as a join condition and escape it properly', function() {
it('should except a valid second parameter as a join condition and escape it properly', () => {
qb.reset_query();

@@ -85,3 +85,3 @@ qb.join('universe u','u.type_id = ut.id');

});
it('should escape compound objects properly', function() {
it('should escape compound objects properly', () => {
qb.reset_query();

@@ -91,3 +91,3 @@ qb.join('universe.galaxy.star_system s','s.type_id = st.id');

});
it('should add aliases to alias-tracking array', function() {
it('should add aliases to alias-tracking array', () => {
qb.reset_query();

@@ -97,3 +97,3 @@ qb.join('universe.galaxy.star_system s');

});
it('should properly place join direction into join clause', function() {
it('should properly place join direction into join clause', () => {
qb.reset_query();

@@ -103,3 +103,3 @@ qb.join('universe.galaxy.star_system s', 's.type_id = st.id', 'left outer');

});
it('should be chainable to allow for multiple join clauses', function() {
it('should be chainable to allow for multiple join clauses', () => {
qb.reset_query();

@@ -109,3 +109,3 @@ qb.join('star_system s', 's.type_id = st.id', 'left outer').join('planets p','p.star_system_id = s.id','left');

});
it('should escape complex join conditions', function() {
it('should escape complex join conditions', () => {
qb.reset_query();

@@ -115,3 +115,3 @@ qb.join('star_system s', "s.type_id = st.id AND st.active = 1 AND st.created_on > '2014-01-01'", 'left');

});
it('should NOT escape any part of join query when asked not to', function() {
it('should NOT escape any part of join query when asked not to', () => {
qb.reset_query();

@@ -118,0 +118,0 @@ qb.join('star_system s', "s.type_id = st.id AND st.active = 1 AND st.created_on > '2014-01-01'", 'left', false);

@@ -1,66 +0,66 @@

var should = require('chai').should();
var expect = require('chai').expect;
var qb = require('../../drivers/mysql/query_builder.js').QueryBuilder();
const should = require('chai').should();
const expect = require('chai').expect;
const qb = require('../../drivers/mysql/query_builder.js').QueryBuilder();
describe('like()', function() {
it('should exist', function() {
describe('like()', () => {
it('should exist', () => {
should.exist(qb.like);
});
it('should be a function', function() {
it('should be a function', () => {
qb.like.should.be.a('function');
});
it('should require first parameter to be a valid string or object with key value pairs', function() {
expect(function() { qb.like(); }, 'nothing provided').to.throw(Error);
expect(function() { qb.like(null); }, 'null provided').to.throw(Error);
expect(function() { qb.like(false); }, 'false provided').to.throw(Error);
expect(function() { qb.like(true); }, 'true provided').to.throw(Error);
expect(function() { qb.like({}); }, 'empty object provided').to.throw(Error);
expect(function() { qb.like(3); }, 'integer provided').to.throw(Error);
expect(function() { qb.like(3.5); }, 'float provided').to.throw(Error);
expect(function() { qb.like([]); }, 'empty array provided').to.throw(Error);
expect(function() { qb.like(''); }, 'empty string provided').to.throw(Error);
it('should require first parameter to be a valid string or object with key value pairs', () => {
expect(() => qb.like(), 'nothing provided').to.throw(Error);
expect(() => qb.like(null), 'null provided').to.throw(Error);
expect(() => qb.like(false), 'false provided').to.throw(Error);
expect(() => qb.like(true), 'true provided').to.throw(Error);
expect(() => qb.like({}), 'empty object provided').to.throw(Error);
expect(() => qb.like(3), 'integer provided').to.throw(Error);
expect(() => qb.like(3.5), 'float provided').to.throw(Error);
expect(() => qb.like([]), 'empty array provided').to.throw(Error);
expect(() => qb.like(''), 'empty string provided').to.throw(Error);
expect(function() { qb.like('planet_name','ear','after'); }, 'valid string').to.not.throw(Error);
expect(function() { qb.like({planet_name: 'ear'}); }, 'valid object').to.not.throw(Error);
expect(() => qb.like('planet_name','ear','after'), 'valid string').to.not.throw(Error);
expect(() => qb.like({planet_name: 'ear'}), 'valid object').to.not.throw(Error);
});
it('should require second parameter if first paramter is a string', function() {
expect(function() { qb.like('planet_name'); }, 'no second param provided').to.throw(Error);
expect(function() { qb.like('planet_name','ear'); }, 'valid second param provided').to.not.throw(Error);
expect(function() { qb.like({planet_name: 'ear'}); }, 'object provided as first param').to.not.throw(Error);
it('should require second parameter if first paramter is a string', () => {
expect(() => qb.like('planet_name'), 'no second param provided').to.throw(Error);
expect(() => qb.like('planet_name','ear'), 'valid second param provided').to.not.throw(Error);
expect(() => qb.like({planet_name: 'ear'}), 'object provided as first param').to.not.throw(Error);
});
it('should require second parameter (when provided) to be a string, number, or boolean', function() {
expect(function() { qb.like('planet_name',null); }, 'null provided').to.throw(Error);
expect(function() { qb.like('planet_name',{}); }, 'empty object provided').to.throw(Error);
expect(function() { qb.like('planet_name',[]); }, 'empty array provided').to.throw(Error);
expect(function() { qb.like('planet_name',NaN); }, 'empty array provided').to.throw(Error);
expect(function() { qb.like('planet_name',Infinity);}, 'empty array provided').to.throw(Error);
it('should require second parameter (when provided) to be a string, number, or boolean', () => {
expect(() => qb.like('planet_name',null), 'null provided').to.throw(Error);
expect(() => qb.like('planet_name',{}), 'empty object provided').to.throw(Error);
expect(() => qb.like('planet_name',[]), 'empty array provided').to.throw(Error);
expect(() => qb.like('planet_name',NaN), 'empty array provided').to.throw(Error);
expect(() => qb.like('planet_name',Infinity), 'empty array provided').to.throw(Error);
expect(function() { qb.like('planet_name',false); }, 'false provided').to.not.throw(Error);
expect(function() { qb.like('planet_name',true); }, 'true provided').to.not.throw(Error);
expect(function() { qb.like('planet_name',3); }, 'integer provided').to.not.throw(Error);
expect(function() { qb.like('planet_name',3.5); }, 'float provided').to.not.throw(Error);
expect(function() { qb.like('planet_name',''); }, 'empty string provided').to.not.throw(Error);
expect(function() { qb.like('planet_name','ear'); }, 'non-empty string provided').to.not.throw(Error);
expect(() => qb.like('planet_name',false), 'false provided').to.not.throw(Error);
expect(() => qb.like('planet_name',true), 'true provided').to.not.throw(Error);
expect(() => qb.like('planet_name',3), 'integer provided').to.not.throw(Error);
expect(() => qb.like('planet_name',3.5), 'float provided').to.not.throw(Error);
expect(() => qb.like('planet_name',''), 'empty string provided').to.not.throw(Error);
expect(() => qb.like('planet_name','ear'), 'non-empty string provided').to.not.throw(Error);
});
it('should only accept the following direction strings in the third parameter: undefined, "both", "right", "left", "before", "after"', function() {
expect(function() { qb.like('galaxy_name','milk',null); }, 'null provided').to.throw(Error);
expect(function() { qb.like('galaxy_name','milk',{}); }, 'empty object provided').to.throw(Error);
expect(function() { qb.like('galaxy_name','milk',[]); }, 'empty array provided').to.throw(Error);
expect(function() { qb.like('galaxy_name','milk',NaN); }, 'empty array provided').to.throw(Error);
expect(function() { qb.like('galaxy_name','milk',Infinity); }, 'empty array provided').to.throw(Error);
expect(function() { qb.like('galaxy_name','milk',false); }, 'false provided').to.throw(Error);
expect(function() { qb.like('galaxy_name','milk',true); }, 'true provided').to.throw(Error);
expect(function() { qb.like('galaxy_name','milk',3); }, 'integer provided').to.throw(Error);
expect(function() { qb.like('galaxy_name','milk',3.5); }, 'float provided').to.throw(Error);
expect(function() { qb.like('galaxy_name','milk',''); }, 'empty string provided').to.throw(Error);
expect(function() { qb.like('galaxy_name','milk','foo'); }, 'non-empty string provided').to.throw(Error);
it('should only accept the following direction strings in the third parameter: undefined, "both", "right", "left", "before", "after"', () => {
expect(() => qb.like('galaxy_name','milk',null), 'null provided').to.throw(Error);
expect(() => qb.like('galaxy_name','milk',{}), 'empty object provided').to.throw(Error);
expect(() => qb.like('galaxy_name','milk',[]), 'empty array provided').to.throw(Error);
expect(() => qb.like('galaxy_name','milk',NaN), 'empty array provided').to.throw(Error);
expect(() => qb.like('galaxy_name','milk',Infinity), 'empty array provided').to.throw(Error);
expect(() => qb.like('galaxy_name','milk',false), 'false provided').to.throw(Error);
expect(() => qb.like('galaxy_name','milk',true), 'true provided').to.throw(Error);
expect(() => qb.like('galaxy_name','milk',3), 'integer provided').to.throw(Error);
expect(() => qb.like('galaxy_name','milk',3.5), 'float provided').to.throw(Error);
expect(() => qb.like('galaxy_name','milk',''), 'empty string provided').to.throw(Error);
expect(() => qb.like('galaxy_name','milk','foo'), 'non-empty string provided').to.throw(Error);
expect(function() { qb.like('galaxy_name','milk'); }, 'no third param provided').to.not.throw(Error);
expect(function() { qb.like('galaxy_name','milk','right'); }, 'right as third param').to.not.throw(Error);
expect(function() { qb.like('galaxy_name','milk','left'); }, 'left as third param').to.not.throw(Error);
expect(function() { qb.like('galaxy_name','milk','both'); }, 'both as third param').to.not.throw(Error);
expect(function() { qb.like('galaxy_name','milk','before'); }, 'before as third param').to.not.throw(Error);
expect(function() { qb.like('galaxy_name','milk','after'); }, 'after as third param').to.not.throw(Error);
expect(() => qb.like('galaxy_name','milk'), 'no third param provided').to.not.throw(Error);
expect(() => qb.like('galaxy_name','milk','right'), 'right as third param').to.not.throw(Error);
expect(() => qb.like('galaxy_name','milk','left'), 'left as third param').to.not.throw(Error);
expect(() => qb.like('galaxy_name','milk','both'), 'both as third param').to.not.throw(Error);
expect(() => qb.like('galaxy_name','milk','before'), 'before as third param').to.not.throw(Error);
expect(() => qb.like('galaxy_name','milk','after'), 'after as third param').to.not.throw(Error);
});
it('should put percentage signs on the right side of the condition if "right" or "after" are passed as the 3rd parameter', function() {
it('should put percentage signs on the right side of the condition if "right" or "after" are passed as the 3rd parameter', () => {
qb.reset_query();

@@ -74,3 +74,3 @@ qb.like('galaxy_name', 'milky', 'after');

});
it('should put percentage signs on the left side of the condition if "before" or "left" are passed as the 3rd parameter', function() {
it('should put percentage signs on the left side of the condition if "before" or "left" are passed as the 3rd parameter', () => {
qb.reset_query();

@@ -84,3 +84,3 @@ qb.like('galaxy_name', 'milky', 'before');

});
it('should put percentage signs on both sides of the condition if "both" or undefined are passed as the 3rd parameter', function() {
it('should put percentage signs on both sides of the condition if "both" or undefined are passed as the 3rd parameter', () => {
qb.reset_query();

@@ -94,3 +94,3 @@ qb.like('galaxy_name', 'milky');

});
it('should put AND in between multiple LIKE clauses', function() {
it('should put AND in between multiple LIKE clauses', () => {
qb.reset_query();

@@ -101,3 +101,3 @@ qb.like('galaxy_name', 'milky');

});
it('should be chainable', function() {
it('should be chainable', () => {
qb.reset_query();

@@ -109,10 +109,10 @@ qb.like('galaxy_name', 'milky').like('planet_name', 'ear', 'right');

describe('or_like()', function() {
it('should exist', function() {
describe('or_like()', () => {
it('should exist', () => {
should.exist(qb.or_like);
});
it('should be a function', function() {
it('should be a function', () => {
qb.or_like.should.be.a('function');
});
it('should put OR in between multiple OR LIKE clauses', function() {
it('should put OR in between multiple OR LIKE clauses', () => {
qb.reset_query();

@@ -123,3 +123,3 @@ qb.or_like('galaxy_name', 'milky');

});
it('should be chainable', function() {
it('should be chainable', () => {
qb.reset_query();

@@ -129,3 +129,3 @@ qb.or_like('galaxy_name', 'milky').or_like('planet_name', 'ear', 'right');

});
it('should be chainable with regular like clauses', function() {
it('should be chainable with regular like clauses', () => {
qb.reset_query();

@@ -137,10 +137,10 @@ qb.like('galaxy_name', 'milky').like('planet_name', 'ear', 'right').or_like('planet_name','Jup','right');

describe('not_like()', function() {
it('should exist', function() {
describe('not_like()', () => {
it('should exist', () => {
should.exist(qb.not_like);
});
it('should be a function', function() {
it('should be a function', () => {
qb.not_like.should.be.a('function');
});
it('should put NOT before LIKE', function() {
it('should put NOT before LIKE', () => {
qb.reset_query();

@@ -150,3 +150,3 @@ qb.not_like('galaxy_name', 'milky');

});
it('should put AND in between multiple NOT LIKE clauses', function() {
it('should put AND in between multiple NOT LIKE clauses', () => {
qb.reset_query();

@@ -157,3 +157,3 @@ qb.not_like('galaxy_name', 'milky');

});
it('should be chainable', function() {
it('should be chainable', () => {
qb.reset_query();

@@ -163,3 +163,3 @@ qb.not_like('galaxy_name', 'milky').not_like('planet_name', 'ear', 'right');

});
it('should be chainable with regular like clauses', function() {
it('should be chainable with regular like clauses', () => {
qb.reset_query();

@@ -171,10 +171,10 @@ qb.like('galaxy_name', 'milky').not_like('planet_name', 'ear', 'right')

describe('or_not_like()', function() {
it('should exist', function() {
describe('or_not_like()', () => {
it('should exist', () => {
should.exist(qb.or_not_like);
});
it('should be a function', function() {
it('should be a function', () => {
qb.or_not_like.should.be.a('function');
});
it('should put NOT before LIKE', function() {
it('should put NOT before LIKE', () => {
qb.reset_query();

@@ -184,3 +184,3 @@ qb.or_not_like('galaxy_name', 'milky');

});
it('should put OR in between multiple NOT LIKE clauses', function() {
it('should put OR in between multiple NOT LIKE clauses', () => {
qb.reset_query();

@@ -191,3 +191,3 @@ qb.or_not_like('galaxy_name', 'milky');

});
it('should be chainable', function() {
it('should be chainable', () => {
qb.reset_query();

@@ -197,3 +197,3 @@ qb.or_not_like('galaxy_name', 'milky').or_not_like('planet_name', 'ear', 'right');

});
it('should be chainable with regular like clauses', function() {
it('should be chainable with regular like clauses', () => {
qb.reset_query();

@@ -200,0 +200,0 @@ qb.like('galaxy_name', 'milky').like('galaxy_name', 'meda', 'before').or_not_like('planet_name', 'ear', 'right')

@@ -1,52 +0,52 @@

var should = require('chai').should();
var expect = require('chai').expect;
var qb = require('../../drivers/mysql/query_builder.js').QueryBuilder();
const should = require('chai').should();
const expect = require('chai').expect;
const qb = require('../../drivers/mysql/query_builder.js').QueryBuilder();
describe('limit()', function() {
it('should exist', function() {
describe('limit()', () => {
it('should exist', () => {
should.exist(qb.limit);
});
it('should be a function', function() {
it('should be a function', () => {
qb.limit.should.be.a('function');
});
it('should have an array to put fields into', function() {
it('should have an array to put fields into', () => {
qb.should.have.property('limit_to');
});
it('should have an empty array to put fields into at the beginning', function() {
it('should have an empty array to put fields into at the beginning', () => {
qb.limit_to.should.be.empty;
});
it('should require an integer (or integer in string form) in first parameter', function() {
it('should require an integer (or integer in string form) in first parameter', () => {
qb.reset_query();
expect(function() { qb.limit(5); }, 'integer provided').to.not.throw(Error);
expect(function() { qb.limit('5'); }, '5 in string form provided').to.not.throw(Error);
expect(function() { qb.limit(5.7); }, 'float provided').to.throw(Error);
expect(function() { qb.limit('5.7');}, 'float provided').to.throw(Error);
expect(function() { qb.limit('abc');}, 'alpha provided').to.throw(Error);
expect(function() { qb.limit('abc7');}, 'alpha numerics provided').to.throw(Error);
expect(function() { qb.limit(); }, 'nothing provided').to.throw(Error);
expect(function() { qb.limit(null); }, 'null provided').to.throw(Error);
expect(function() { qb.limit(true); }, 'true provided').to.throw(Error);
expect(function() { qb.limit(false);}, 'false provided').to.throw(Error);
expect(function() { qb.limit(''); }, 'empty string provided').to.throw(Error);
expect(function() { qb.limit({}); }, 'empty object provided').to.throw(Error);
expect(function() { qb.limit([]); }, 'empty array provided').to.throw(Error);
expect(function() { qb.limit([5]); }, 'array with integer in it provided').to.throw(Error);
expect(() => qb.limit(5), 'integer provided').to.not.throw(Error);
expect(() => qb.limit('5'), '5 in string form provided').to.not.throw(Error);
expect(() => qb.limit(5.7), 'float provided').to.throw(Error);
expect(() => qb.limit('5.7'), 'float provided').to.throw(Error);
expect(() => qb.limit('abc'), 'alpha provided').to.throw(Error);
expect(() => qb.limit('abc7'), 'alpha numerics provided').to.throw(Error);
expect(() => qb.limit(), 'nothing provided').to.throw(Error);
expect(() => qb.limit(null), 'null provided').to.throw(Error);
expect(() => qb.limit(true), 'true provided').to.throw(Error);
expect(() => qb.limit(false), 'false provided').to.throw(Error);
expect(() => qb.limit(''), 'empty string provided').to.throw(Error);
expect(() => qb.limit({}), 'empty object provided').to.throw(Error);
expect(() => qb.limit([]), 'empty array provided').to.throw(Error);
expect(() => qb.limit([5]), 'array with integer in it provided').to.throw(Error);
});
it('should allow an integer (or integer in string form) in second parameter. Nothing else is allowed.', function() {
it('should allow an integer (or integer in string form) in second parameter. Nothing else is allowed.', () => {
qb.reset_query();
expect(function() { qb.limit(10,5); }, 'integer provided').to.not.throw(Error);
expect(function() { qb.limit(10,'5'); }, '5 in string form provided').to.not.throw(Error);
expect(function() { qb.limit(10,5.7); }, 'float provided').to.throw(Error);
expect(function() { qb.limit(10,'5.7'); }, 'float provided').to.throw(Error);
expect(function() { qb.limit(10,'abc'); }, 'alpha provided').to.throw(Error);
expect(function() { qb.limit(10,'abc7');}, 'alphanumerics provided').to.throw(Error);
expect(function() { qb.limit(10,null); }, 'null provided').to.throw(Error);
expect(function() { qb.limit(10,true); }, 'true provided').to.throw(Error);
expect(function() { qb.limit(10,false); }, 'false provided').to.throw(Error);
expect(function() { qb.limit(10,''); }, 'empty string provided').to.throw(Error);
expect(function() { qb.limit(10,{}); }, 'empty object provided').to.throw(Error);
expect(function() { qb.limit(10,[]); }, 'empty array provided').to.throw(Error);
expect(function() { qb.limit(10,[5]); }, 'array with integer in it provided').to.throw(Error);
expect(() => qb.limit(10,5), 'integer provided').to.not.throw(Error);
expect(() => qb.limit(10,'5'), '5 in string form provided').to.not.throw(Error);
expect(() => qb.limit(10,5.7), 'float provided').to.throw(Error);
expect(() => qb.limit(10,'5.7'), 'float provided').to.throw(Error);
expect(() => qb.limit(10,'abc'), 'alpha provided').to.throw(Error);
expect(() => qb.limit(10,'abc7'), 'alphanumerics provided').to.throw(Error);
expect(() => qb.limit(10,null), 'null provided').to.throw(Error);
expect(() => qb.limit(10,true), 'true provided').to.throw(Error);
expect(() => qb.limit(10,false), 'false provided').to.throw(Error);
expect(() => qb.limit(10,''), 'empty string provided').to.throw(Error);
expect(() => qb.limit(10,{}), 'empty object provided').to.throw(Error);
expect(() => qb.limit(10,[]), 'empty array provided').to.throw(Error);
expect(() => qb.limit(10,[5]), 'array with integer in it provided').to.throw(Error);
});
it('should override the default limit_to value when a limit is provided', function() {
it('should override the default limit_to value when a limit is provided', () => {
qb.reset_query();

@@ -56,3 +56,3 @@ qb.limit(10);

});
it('should override the default limit_to and offset_val values when a limit and an offset are provided', function() {
it('should override the default limit_to and offset_val values when a limit and an offset are provided', () => {
qb.reset_query();

@@ -63,3 +63,3 @@ qb.limit(10,20);

});
it('should trim string values that are provided', function() {
it('should trim string values that are provided', () => {
qb.reset_query();

@@ -69,3 +69,3 @@ qb.limit('10 ');

});
it('should trim string values that are provided', function() {
it('should trim string values that are provided', () => {
qb.reset_query();

@@ -76,3 +76,3 @@ qb.limit(' 10 ',' 12');

});
it('should override values set by any previous calls to itself', function() {
it('should override values set by any previous calls to itself', () => {
qb.reset_query();

@@ -84,3 +84,3 @@ qb.limit(10);

});
it('should be chainable whereby the last call to the method will contain the value(s) used', function() {
it('should be chainable whereby the last call to the method will contain the value(s) used', () => {
qb.reset_query();

@@ -87,0 +87,0 @@ qb.limit(10,5).limit(20).limit(100,30);

@@ -1,36 +0,36 @@

var should = require('chai').should();
var expect = require('chai').expect;
var qb = require('../../drivers/mysql/query_builder.js').QueryBuilder();
const should = require('chai').should();
const expect = require('chai').expect;
const qb = require('../../drivers/mysql/query_builder.js').QueryBuilder();
describe('offset()', function() {
it('should exist', function() {
describe('offset()', () => {
it('should exist', () => {
should.exist(qb.offset);
});
it('should be a function', function() {
it('should be a function', () => {
qb.offset.should.be.a('function');
});
it('should have an array to put fields into', function() {
it('should have an array to put fields into', () => {
qb.should.have.property('offset_val');
});
it('should have an empty array to put fields into at the beginning', function() {
it('should have an empty array to put fields into at the beginning', () => {
qb.offset_val.should.be.empty;
});
it('should require an integer (or integer in string form) in first parameter', function() {
it('should require an integer (or integer in string form) in first parameter', () => {
qb.reset_query();
expect(function() { qb.offset(5); }, 'integer provided').to.not.throw(Error);
expect(function() { qb.offset('5'); }, '5 in string form provided').to.not.throw(Error);
expect(function() { qb.offset(5.7); }, 'float provided').to.throw(Error);
expect(function() { qb.offset('5.7'); }, 'float provided').to.throw(Error);
expect(function() { qb.offset('abc') }, 'alpha provided').to.throw(Error);
expect(function() { qb.offset('abc7'); }, 'alpha numerics provided').to.throw(Error);
expect(function() { qb.offset(); }, 'nothing provided').to.throw(Error);
expect(function() { qb.offset(null); }, 'null provided').to.throw(Error);
expect(function() { qb.offset(true); }, 'true provided').to.throw(Error);
expect(function() { qb.offset(false); }, 'false provided').to.throw(Error);
expect(function() { qb.offset(''); }, 'empty string provided').to.throw(Error);
expect(function() { qb.offset({}); }, 'empty object provided').to.throw(Error);
expect(function() { qb.offset([]); }, 'empty array provided').to.throw(Error);
expect(function() { qb.offset([5]); }, 'array with integer in it provided').to.throw(Error);
expect(() => qb.offset(5), 'integer provided').to.not.throw(Error);
expect(() => qb.offset('5'), '5 in string form provided').to.not.throw(Error);
expect(() => qb.offset(5.7), 'float provided').to.throw(Error);
expect(() => qb.offset('5.7'), 'float provided').to.throw(Error);
expect(() => qb.offset('abc'), 'alpha provided').to.throw(Error);
expect(() => qb.offset('abc7'), 'alpha numerics provided').to.throw(Error);
expect(() => qb.offset(), 'nothing provided').to.throw(Error);
expect(() => qb.offset(null), 'null provided').to.throw(Error);
expect(() => qb.offset(true), 'true provided').to.throw(Error);
expect(() => qb.offset(false), 'false provided').to.throw(Error);
expect(() => qb.offset(''), 'empty string provided').to.throw(Error);
expect(() => qb.offset({}), 'empty object provided').to.throw(Error);
expect(() => qb.offset([]), 'empty array provided').to.throw(Error);
expect(() => qb.offset([5]), 'array with integer in it provided').to.throw(Error);
});
it('should override the default offset_val value when a offset is provided', function() {
it('should override the default offset_val value when a offset is provided', () => {
qb.reset_query();

@@ -40,3 +40,3 @@ qb.offset(10);

});
it('should trim string values that are provided', function() {
it('should trim string values that are provided', () => {
qb.reset_query();

@@ -48,3 +48,3 @@ qb.offset('10 ');

});
it('should override values set by any previous calls to itself', function() {
it('should override values set by any previous calls to itself', () => {
qb.reset_query();

@@ -56,3 +56,3 @@ qb.offset(10);

});
it('should be chainable whereby the last call to the method will contain the value used', function() {
it('should be chainable whereby the last call to the method will contain the value used', () => {
qb.reset_query();

@@ -59,0 +59,0 @@ qb.offset(10).offset(20).offset(100);

@@ -1,36 +0,36 @@

var should = require('chai').should();
var expect = require('chai').expect;
var qb = require('../../drivers/mysql/query_builder.js').QueryBuilder();
const should = require('chai').should();
const expect = require('chai').expect;
const qb = require('../../drivers/mysql/query_builder.js').QueryBuilder();
describe('order_by()', function() {
it('should exist', function() {
describe('order_by()', () => {
it('should exist', () => {
should.exist(qb.order_by);
});
it('should be a function', function() {
it('should be a function', () => {
qb.order_by.should.be.a('function');
});
it('should have an array to put fields into', function() {
it('should have an array to put fields into', () => {
qb.should.have.property('order_by_array');
});
it('should have an empty array to put fields into at the beginning', function() {
it('should have an empty array to put fields into at the beginning', () => {
qb.order_by_array.should.be.empty;
});
it('should require non-empty string or array as first param unless random is provided as second parameter', function() {
expect(function() { qb.order_by(); }, 'nothing provided').to.throw(Error);
expect(function() { qb.order_by(null); }, 'null provided').to.throw(Error);
expect(function() { qb.order_by(false); }, 'false provided').to.throw(Error);
expect(function() { qb.order_by(true); }, 'true provided').to.throw(Error);
expect(function() { qb.order_by({}); }, 'empty object provided').to.throw(Error);
expect(function() { qb.order_by(3); }, 'integer provided').to.throw(Error);
expect(function() { qb.order_by(3.5); }, 'float provided').to.throw(Error);
expect(function() { qb.order_by([]); }, 'empty array provided').to.throw(Error);
expect(function() { qb.order_by(''); }, 'empty string provided').to.throw(Error);
it('should require non-empty string or array as first param unless random is provided as second parameter', () => {
expect(() => qb.order_by(), 'nothing provided').to.throw(Error);
expect(() => qb.order_by(null), 'null provided').to.throw(Error);
expect(() => qb.order_by(false), 'false provided').to.throw(Error);
expect(() => qb.order_by(true), 'true provided').to.throw(Error);
expect(() => qb.order_by({}), 'empty object provided').to.throw(Error);
expect(() => qb.order_by(3), 'integer provided').to.throw(Error);
expect(() => qb.order_by(3.5), 'float provided').to.throw(Error);
expect(() => qb.order_by([]), 'empty array provided').to.throw(Error);
expect(() => qb.order_by(''), 'empty string provided').to.throw(Error);
// If random
expect(function() { qb.order_by('','rand'); }, 'empty string and random direction provided').to.not.throw(Error);
expect(function() { qb.order_by(undefined,'rand'); }, 'undefined and random direction provided').to.not.throw(Error);
expect(function() { qb.order_by(null,'rand'); }, 'null and random direction provided').to.not.throw(Error);
expect(function() { qb.order_by(false,'rand'); }, 'false and random direction provided').to.not.throw(Error);
expect(function() { qb.order_by([],'rand'); }, 'empty array and random direction provided').to.not.throw(Error);
expect(() => qb.order_by('','rand'), 'empty string and random direction provided').to.not.throw(Error);
expect(() => qb.order_by(undefined,'rand'), 'undefined and random direction provided').to.not.throw(Error);
expect(() => qb.order_by(null,'rand'), 'null and random direction provided').to.not.throw(Error);
expect(() => qb.order_by(false,'rand'), 'false and random direction provided').to.not.throw(Error);
expect(() => qb.order_by([],'rand'), 'empty array and random direction provided').to.not.throw(Error);
});
it('should accept a field and direction separated by a space as first parameter and escape the field', function() {
it('should accept a field and direction separated by a space as first parameter and escape the field', () => {
qb.reset_query();

@@ -40,3 +40,3 @@ qb.order_by('planet_position asc');

});
it('should accept a field and direction as seperate parameters and escape the field', function() {
it('should accept a field and direction as seperate parameters and escape the field', () => {
qb.reset_query();

@@ -46,3 +46,3 @@ qb.order_by('planet_position', 'asc');

});
it('should add additional order_by calls to teh order by array', function() {
it('should add additional order_by calls to teh order by array', () => {
qb.reset_query();

@@ -53,3 +53,3 @@ qb.order_by('planet_position', 'asc');

});
it('should be chainable', function() {
it('should be chainable', () => {
qb.reset_query();

@@ -59,3 +59,3 @@ qb.order_by('planet_position', 'asc').order_by('planet_size', 'desc');

});
it('should assume ASC when no direction is provided', function() {
it('should assume ASC when no direction is provided', () => {
qb.reset_query();

@@ -65,21 +65,21 @@ qb.order_by('planet_position');

});
it('should only accept valid ordering directions (ASC, DESC, random)', function() {
it('should only accept valid ordering directions (ASC, DESC, random)', () => {
qb.reset_query();
expect(function() { qb.order_by('planet_position'); }).to.not.throw(Error);
expect(function() { qb.order_by('planet_position','ASC'); }).to.not.throw(Error);
expect(function() { qb.order_by('planet_position','DESC'); }).to.not.throw(Error);
expect(function() { qb.order_by('planet_position','random'); }).to.not.throw(Error);
expect(function() { qb.order_by('planet_position',null); }).to.not.throw(Error);
expect(function() { qb.order_by('planet_position',undefined); }).to.not.throw(Error);
expect(function() { qb.order_by('planet_position',false); }).to.not.throw(Error);
expect(function() { qb.order_by('planet_position',3); }).to.not.throw(Error);
expect(function() { qb.order_by('planet_position',true); }).to.not.throw(Error);
expect(function() { qb.order_by('planet_position',[]); }).to.not.throw(Error);
expect(function() { qb.order_by('planet_position',{}); }).to.not.throw(Error);
expect(function() { qb.order_by('planet_position',''); }).to.not.throw(Error);
expect(() => qb.order_by('planet_position')).to.not.throw(Error);
expect(() => qb.order_by('planet_position','ASC')).to.not.throw(Error);
expect(() => qb.order_by('planet_position','DESC')).to.not.throw(Error);
expect(() => qb.order_by('planet_position','random')).to.not.throw(Error);
expect(() => qb.order_by('planet_position',null)).to.not.throw(Error);
expect(() => qb.order_by('planet_position',undefined)).to.not.throw(Error);
expect(() => qb.order_by('planet_position',false)).to.not.throw(Error);
expect(() => qb.order_by('planet_position',3)).to.not.throw(Error);
expect(() => qb.order_by('planet_position',true)).to.not.throw(Error);
expect(() => qb.order_by('planet_position',[])).to.not.throw(Error);
expect(() => qb.order_by('planet_position',{})).to.not.throw(Error);
expect(() => qb.order_by('planet_position','')).to.not.throw(Error);
// Only an invalid string will throw an error
expect(function() { qb.order_by('planet_position','FAKE'); }).to.throw(Error);
expect(() => qb.order_by('planet_position','FAKE')).to.throw(Error);
});
it('should accept a comma-separated list of fields to order by with a single direction at the end', function() {
it('should accept a comma-separated list of fields to order by with a single direction at the end', () => {
qb.reset_query();

@@ -89,3 +89,3 @@ qb.order_by('planet_position, planet_size asc');

});
it('should accept a comma-separated list of field + direction pairs', function() {
it('should accept a comma-separated list of field + direction pairs', () => {
qb.reset_query();

@@ -95,19 +95,19 @@ qb.order_by('planet_position desc, planet_size asc');

});
it('should accept a random direction in three forms: "random", "RAND", "RAND()" (case-insensitively) and remove field(s) from statement', function() {
it('should accept a random direction in three forms: "random", "RAND", "RAND()" (case-insensitively) and remove field(s) from statement', () => {
qb.reset_query();
qb.order_by('planet_position', 'random');
qb.order_by_array.should.eql(['RAND()']);
qb.reset_query();
qb.order_by('planet_size', 'RAND');
qb.order_by_array.should.eql(['RAND()']);
qb.reset_query();
qb.order_by('planet_position, planet_size', 'rand');
qb.order_by_array.should.eql(['RAND()']);
qb.reset_query();
qb.order_by(null, 'RAND()');
qb.order_by_array.should.eql(['RAND()']);
qb.reset_query();

@@ -117,3 +117,3 @@ qb.order_by('', 'rand');

});
it('should accept an array of field + direction pairs', function() {
it('should accept an array of field + direction pairs', () => {
qb.reset_query();

@@ -123,7 +123,7 @@ qb.order_by(['planet_position DESC', 'planet_size ASC']);

});
it('should use direction parameter as default when an array of field + direction pairs is provided (when a pair does not contain a direction)', function() {
it('should use direction parameter as default when an array of field + direction pairs is provided (when a pair does not contain a direction)', () => {
qb.reset_query();
qb.order_by(['planet_position', 'planet_size'], 'desc');
qb.order_by_array.should.eql(['`planet_position` DESC', '`planet_size` DESC']);
qb.reset_query();

@@ -133,3 +133,3 @@ qb.order_by(['planet_position DESC', 'planet_size'], 'desc');

});
it('should accept a simple array of fields as first param and default to ASC for the direction if none is provided', function() {
it('should accept a simple array of fields as first param and default to ASC for the direction if none is provided', () => {
qb.reset_query();

@@ -136,0 +136,0 @@ qb.order_by(['planet_position', 'planet_size']);

@@ -1,33 +0,33 @@

var should = require('chai').should();
var expect = require('chai').expect;
var qb = require('../../drivers/mysql/query_builder.js').QueryBuilder();
const should = require('chai').should();
const expect = require('chai').expect;
const qb = require('../../drivers/mysql/query_builder.js').QueryBuilder();
describe('select()', function() {
it('should exist', function() {
describe('select()', () => {
it('should exist', () => {
should.exist(qb.select);
});
it('should be a function', function() {
it('should be a function', () => {
qb.select.should.be.a('function');
});
it('should have an array to put fields into', function() {
it('should have an array to put fields into', () => {
qb.should.have.property('select_array');
});
it('should have an empty array to put fields into at the beginning', function() {
it('should have an empty array to put fields into at the beginning', () => {
qb.select_array.should.be.empty;
});
it('should require an array or string to be passed as first parameter', function() {
var invalid_match = /requires a string or array/;
var empty_str_match = /string is empty/;
var empty_arr_match = /array is empty/;
expect(function() { qb.select(); }, 'nothing provided').to.throw(Error, invalid_match);
expect(function() { qb.select(true); }, 'true provided').to.throw(Error, invalid_match);
expect(function() { qb.select(null); }, 'null provided').to.throw(Error, invalid_match);
expect(function() { qb.select(false); }, 'false provided').to.throw(Error, invalid_match);
expect(function() { qb.select({}); }, 'object provided').to.throw(Error, invalid_match);
expect(function() { qb.select([]); }, 'empty array provided').to.throw(Error, empty_arr_match);
expect(function() { qb.select(''); }, 'empty string provided').to.throw(Error, empty_str_match);
expect(function() { qb.select(' '); }, 'string of spaces provided').to.throw(Error, empty_str_match);
expect(function() { qb.select('blah'); }, 'valid string provided').to.not.throw(Error);
it('should require an array or string to be passed as first parameter', () => {
const invalid_match = /requires a string or array/;
const empty_str_match = /string is empty/;
const empty_arr_match = /array is empty/;
expect(() => qb.select(), 'nothing provided').to.throw(Error, invalid_match);
expect(() => qb.select(true), 'true provided').to.throw(Error, invalid_match);
expect(() => qb.select(null), 'null provided').to.throw(Error, invalid_match);
expect(() => qb.select(false), 'false provided').to.throw(Error, invalid_match);
expect(() => qb.select({}), 'object provided').to.throw(Error, invalid_match);
expect(() => qb.select([]), 'empty array provided').to.throw(Error, empty_arr_match);
expect(() => qb.select(''), 'empty string provided').to.throw(Error, empty_str_match);
expect(() => qb.select(' '), 'string of spaces provided').to.throw(Error, empty_str_match);
expect(() => qb.select('blah'), 'valid string provided').to.not.throw(Error);
});
it('should add field to array and escape it properly', function() {
it('should add field to array and escape it properly', () => {
qb.reset_query();

@@ -37,3 +37,3 @@ qb.select('notes');

});
it('should trim fields properly before placing them into the select array', function() {
it('should trim fields properly before placing them into the select array', () => {
qb.reset_query();

@@ -43,7 +43,7 @@ qb.select(' notes ');

});
it('should have an empty array after resetting', function() {
it('should have an empty array after resetting', () => {
qb.reset_query();
qb.select_array.should.be.empty;
});
it('should not escape fields if asked not to', function() {
it('should not escape fields if asked not to', () => {
qb.reset_query();

@@ -53,3 +53,3 @@ qb.select('foo',false);

});
it('should accept a comma-delimited string of field names and trim and escape each properly', function() {
it('should accept a comma-delimited string of field names and trim and escape each properly', () => {
qb.reset_query();

@@ -59,3 +59,3 @@ qb.select('do,re , mi, fa');

});
it('should be allowed to be called multiple times to add multiple fields to the select array', function() {
it('should be allowed to be called multiple times to add multiple fields to the select array', () => {
qb.reset_query();

@@ -65,3 +65,3 @@ qb.select('do').select('re').select('mi').select('fa');

});
it('should be allowed to be called multiple times to add multiple escaped and/or non-escaped fields to the select array', function() {
it('should be allowed to be called multiple times to add multiple escaped and/or non-escaped fields to the select array', () => {
qb.reset_query();

@@ -71,3 +71,3 @@ qb.select('do').select('re',false).select('mi',false).select('fa');

});
it('should accept an array of fields and add them individually to the select array', function() {
it('should accept an array of fields and add them individually to the select array', () => {
qb.reset_query();

@@ -77,3 +77,3 @@ qb.select(['sol','la','ti','do']);

});
it('should accept an array of fields and add them individually to the select array without escaping, if asked not to', function() {
it('should accept an array of fields and add them individually to the select array without escaping, if asked not to', () => {
qb.reset_query();

@@ -83,3 +83,3 @@ qb.select(['sol','la','ti','do'],false);

});
it('should accept an array of fields (some manually escaped) and add them individually to the select array without auto-escaping, if asked not to', function() {
it('should accept an array of fields (some manually escaped) and add them individually to the select array without auto-escaping, if asked not to', () => {
qb.reset_query();

@@ -89,3 +89,3 @@ qb.select(['`sol`','la','ti','`do`'],false);

});
it('should not double-escape a field', function() {
it('should not double-escape a field', () => {
qb.reset_query();

@@ -95,3 +95,3 @@ qb.select('`do`');

});
it('should not double-escape fields when provided with an array of pre-escaped fields', function() {
it('should not double-escape fields when provided with an array of pre-escaped fields', () => {
qb.reset_query();

@@ -101,3 +101,3 @@ qb.select(['`do`','`re`','`mi`']);

});
it('should not double-escape fields when provided with an array of pre-escaped fields but should escpae non-pre-escaped fields', function() {
it('should not double-escape fields when provided with an array of pre-escaped fields but should escpae non-pre-escaped fields', () => {
qb.reset_query();

@@ -107,3 +107,3 @@ qb.select(['`do`','re','`mi`']);

});
it('should allow for field aliases to be provided and those fields and aliases should be properly escaped', function() {
it('should allow for field aliases to be provided and those fields and aliases should be properly escaped', () => {
qb.reset_query();

@@ -113,3 +113,3 @@ qb.select('foo as bar');

});
it('should not double-escape aliases', function() {
it('should not double-escape aliases', () => {
qb.reset_query();

@@ -119,3 +119,3 @@ qb.select(['foo as `bar`']);

});
it('should allow for multiple fields with aliases to be provided and those fields and aliases should be properly escaped', function() {
it('should allow for multiple fields with aliases to be provided and those fields and aliases should be properly escaped', () => {
qb.reset_query();

@@ -125,3 +125,3 @@ qb.select(['foo as bar','bar as foo']);

});
it('should allow for field aliases with spaces in them', function() {
it('should allow for field aliases with spaces in them', () => {
qb.reset_query();

@@ -131,3 +131,3 @@ qb.select('notes as The Notes');

});
it('should allow for a comma-delimited list of fields with aliases to be provided and those fields and aliases should be properly escaped', function() {
it('should allow for a comma-delimited list of fields with aliases to be provided and those fields and aliases should be properly escaped', () => {
qb.reset_query();

@@ -137,11 +137,11 @@ qb.select('foo as bar, bar as foo, foobar as `Foo Bar`');

});
it('should allow for namespacing in field name (host.db.table.field)', function() {
it('should allow for namespacing in field name (host.db.table.field)', () => {
qb.reset_query();
qb.select('star_system.planet');
qb.select_array.should.eql(['`star_system`.`planet`']);
qb.reset_query();
qb.select('galaxy.star_system.planet');
qb.select_array.should.eql(['`galaxy`.`star_system`.`planet`']);
qb.reset_query();

@@ -151,3 +151,3 @@ qb.select('universe.galaxy.star_system.planet');

});
it('should allow for namespacing in field name (host.db.table.column) + alias', function() {
it('should allow for namespacing in field name (host.db.table.column) + alias', () => {
qb.reset_query();

@@ -157,42 +157,42 @@ qb.select('universe.galaxy.star_system.planet as planet');

});
it('should not allow subqueries or functions with commas in them without the second parameter being false', function() {
it('should not allow subqueries or functions with commas in them without the second parameter being false', () => {
qb.reset_query();
expect(function() {
qb.select('s.star_systems, (select count(p.*) as count from planets p where p.star_system_id IN(2,3,5)) as num_planets');
}).to.throw(Error);
expect(function() {
qb.select('s.star_systems, (select count(p.*) as count from planets p where p.star_system_id IN(2,3,5)) as num_planets',false);
}).to.not.throw(Error);
expect(
() => qb.select('s.star_systems, (select count(p.*) as count from planets p where p.star_system_id IN(2,3,5)) as num_planets')
).to.throw(Error);
expect(
() => qb.select('s.star_systems, (select count(p.*) as count from planets p where p.star_system_id IN(2,3,5)) as num_planets',false)
).to.not.throw(Error);
});
it('should allow for functions and subqueries in statement without escaping them (aliases at the end will still be escaped)', function() {
it('should allow for functions and subqueries in statement without escaping them (aliases at the end will still be escaped)', () => {
qb.reset_query();
qb.select('count(*) as count', false);
qb.select_array.should.eql(['count(*) AS `count`']);
qb.reset_query();
qb.select('count(*) as count, m.*, MIN(id) as min', false);
qb.select_array.should.eql(['count(*) as count, m.*, MIN(id) AS `min`']);
qb.reset_query();
qb.select('(select count(p.*) as count from planets p) as num_planets', false);
qb.select_array.should.eql(['(select count(p.*) as count from planets p) AS `num_planets`']);
qb.reset_query();
qb.select('s.star_systems, (select count(p.*) as count from planets p where p.star_system_id = s.id) as num_planets', false);
qb.select_array.should.eql(['s.star_systems, (select count(p.*) as count from planets p where p.star_system_id = s.id) AS `num_planets`']);
});
});
var prefixes = ['min','max','avg','sum'];
for (var i in prefixes) {
var type = prefixes[i];
describe('select_' + type+'()', function() {
it('should exist', function() {
const prefixes = ['min','max','avg','sum'];
for (const i in prefixes) {
const type = prefixes[i];
describe('select_' + type+'()', () => {
it('should exist', () => {
should.exist(qb['select_' + type]);
});
it('should be a function', function() {
it('should be a function', () => {
qb['select_' + type].should.be.a('function');
});
it('should place given field as parameter in a ' + type.toUpperCase() + '() MySQL function and alias the result with the original field name', function() {
it('should place given field as parameter in a ' + type.toUpperCase() + '() MySQL function and alias the result with the original field name', () => {
qb.reset_query();

@@ -199,0 +199,0 @@ qb['select_' + type]('s.star_systems');

@@ -1,59 +0,59 @@

var should = require('chai').should();
var expect = require('chai').expect;
var qb = require('../../drivers/mysql/query_builder.js').QueryBuilder();
const should = require('chai').should();
const expect = require('chai').expect;
const qb = require('../../drivers/mysql/query_builder.js').QueryBuilder();
describe('set()', function() {
it('should exist', function() {
describe('set()', () => {
it('should exist', () => {
should.exist(qb.set);
});
it('should be a function', function() {
it('should be a function', () => {
qb.set.should.be.a('function');
});
it('should have an object to put fields into', function() {
it('should have an object to put fields into', () => {
qb.should.have.property('set_array');
});
it('should have an empty array to put fields into at the beginning', function() {
it('should have an empty array to put fields into at the beginning', () => {
qb.set_array.should.be.empty;
});
it('should not accept anything but a non-empty string or a non-empty object as first param', function() {
it('should not accept anything but a non-empty string or a non-empty object as first param', () => {
qb.reset_query();
expect(function() { qb.set(); }, 'nothing provided').to.throw(Error);
expect(function() { qb.set(null); }, 'null provided').to.throw(Error);
expect(function() { qb.set(false); }, 'false provided').to.throw(Error);
expect(function() { qb.set(true); }, 'true provided').to.throw(Error);
expect(function() { qb.set({}); }, 'empty object provided').to.throw(Error);
expect(function() { qb.set(3); }, 'integer provided').to.throw(Error);
expect(function() { qb.set(3.5); }, 'float provided').to.throw(Error);
expect(function() { qb.set(NaN); }, 'NaN provided').to.throw(Error);
expect(function() { qb.set(Infinity); }, 'Infinity provided').to.throw(Error);
expect(function() { qb.set([]); }, 'empty array provided').to.throw(Error);
expect(function() { qb.set([1,2]); }, 'array of numbers provided').to.throw(Error);
expect(function() { qb.set(''); }, 'empty string provided').to.throw(Error);
expect(function() { qb.set(' '); }, 'string full of spaces provided').to.throw(Error);
expect(function() { qb.set(/foobar/); }, 'regex provided').to.throw(Error);
expect(() => qb.set(), 'nothing provided').to.throw(Error);
expect(() => qb.set(null), 'null provided').to.throw(Error);
expect(() => qb.set(false), 'false provided').to.throw(Error);
expect(() => qb.set(true), 'true provided').to.throw(Error);
expect(() => qb.set({}), 'empty object provided').to.throw(Error);
expect(() => qb.set(3), 'integer provided').to.throw(Error);
expect(() => qb.set(3.5), 'float provided').to.throw(Error);
expect(() => qb.set(NaN), 'NaN provided').to.throw(Error);
expect(() => qb.set(Infinity), 'Infinity provided').to.throw(Error);
expect(() => qb.set([]), 'empty array provided').to.throw(Error);
expect(() => qb.set([1,2]), 'array of numbers provided').to.throw(Error);
expect(() => qb.set(''), 'empty string provided').to.throw(Error);
expect(() => qb.set(' '), 'string full of spaces provided').to.throw(Error);
expect(() => qb.set(/foobar/), 'regex provided').to.throw(Error);
expect(function() { qb.set('planet_position',3); }, 'valid string provided').to.not.throw(Error);
expect(function() { qb.set({planet_position: 3}); }, 'valid object provided').to.not.throw(Error);
expect(() => qb.set('planet_position',3), 'valid string provided').to.not.throw(Error);
expect(() => qb.set({planet_position: 3}), 'valid object provided').to.not.throw(Error);
});
it('should not accept anything but a string, number, date, null, or boolean as second param if first param is a string.', function() {
it('should not accept anything but a string, number, date, null, or boolean as second param if first param is a string.', () => {
qb.reset_query();
expect(function() { qb.set('planet_position'); }, 'nothing provided').to.throw(Error);
expect(function() { qb.set('planet_position',{}); }, 'empty object provided').to.throw(Error);
expect(function() { qb.set('planet_position',NaN); }, 'NaN provided').to.throw(Error);
expect(function() { qb.set('planet_position',Infinity); }, 'Infinity provided').to.throw(Error);
expect(function() { qb.set('planet_position',[]); }, 'empty array provided').to.throw(Error);
expect(function() { qb.set('planet_position',[1,2]); }, 'array of numbers provided').to.throw(Error);
expect(function() { qb.set('planet_position',/foobar/); }, 'regex provided').to.throw(Error);
expect(() => qb.set('planet_position'), 'nothing provided').to.throw(Error);
expect(() => qb.set('planet_position',{}), 'empty object provided').to.throw(Error);
expect(() => qb.set('planet_position',NaN), 'NaN provided').to.throw(Error);
expect(() => qb.set('planet_position',Infinity), 'Infinity provided').to.throw(Error);
expect(() => qb.set('planet_position',[]), 'empty array provided').to.throw(Error);
expect(() => qb.set('planet_position',[1,2]), 'array of numbers provided').to.throw(Error);
expect(() => qb.set('planet_position',/foobar/), 'regex provided').to.throw(Error);
expect(function() { qb.set('planet_position',new Date()); }, 'date provided').to.not.throw(Error);
expect(function() { qb.set('planet_position',null); }, 'null provided').to.not.throw(Error);
expect(function() { qb.set('planet_position',3); }, 'Integer provided').to.not.throw(Error);
expect(function() { qb.set('planet_position',3.5); }, 'float provided').to.not.throw(Error);
expect(function() { qb.set('planet_position',false); }, 'false provided').to.not.throw(Error);
expect(function() { qb.set('planet_position',true); }, 'true provided').to.not.throw(Error);
expect(function() { qb.set('planet_position',''); }, 'empty string provided').to.not.throw(Error);
expect(function() { qb.set('planet_position',' '); }, 'string full of spaces provided').to.not.throw(Error);
expect(function() { qb.set('planet_position','Three'); }, 'non-empty string provided').to.not.throw(Error);
expect(() => qb.set('planet_position',new Date()), 'date provided').to.not.throw(Error);
expect(() => qb.set('planet_position',null), 'null provided').to.not.throw(Error);
expect(() => qb.set('planet_position',3), 'Integer provided').to.not.throw(Error);
expect(() => qb.set('planet_position',3.5), 'float provided').to.not.throw(Error);
expect(() => qb.set('planet_position',false), 'false provided').to.not.throw(Error);
expect(() => qb.set('planet_position',true), 'true provided').to.not.throw(Error);
expect(() => qb.set('planet_position',''), 'empty string provided').to.not.throw(Error);
expect(() => qb.set('planet_position',' '), 'string full of spaces provided').to.not.throw(Error);
expect(() => qb.set('planet_position','Three'), 'non-empty string provided').to.not.throw(Error);
});
it('should add first param (key) and second param (value) to hash and escape them properly', function() {
it('should add first param (key) and second param (value) to hash and escape them properly', () => {
qb.reset_query();

@@ -63,3 +63,3 @@ qb.set('galaxy_name','Milky Way');

});
it('should merge passed object into set_array and escape items properly', function() {
it('should merge passed object into set_array and escape items properly', () => {
qb.reset_query();

@@ -73,3 +73,3 @@ qb.set({galaxy_name: 'Milky Way'});

});
it('should not escape items if asked not to', function() {
it('should not escape items if asked not to', () => {
qb.reset_query();

@@ -79,3 +79,3 @@ qb.set({galaxy_name: 'Milky Way'}, null, false);

});
it('should append more items to set_array as set() is called', function() {
it('should append more items to set_array as set() is called', () => {
qb.reset_query();

@@ -87,3 +87,3 @@ qb.set({galaxy_name: 'Milky Way'}, null, false);

});
it('should be chainable', function() {
it('should be chainable', () => {
qb.reset_query();

@@ -93,3 +93,3 @@ qb.set({galaxy_name: 'Milky Way', galaxy_class: 'C'}, null, false).set('galaxy_size','D');

});
it('should overwrite values of keys that have been set already', function() {
it('should overwrite values of keys that have been set already', () => {
qb.reset_query();

@@ -101,3 +101,3 @@ qb.set({galaxy_name: 'Milky Way'}, null, false);

});
it('should NOT overwrite values of keys that are the same but have different escape flags', function() {
it('should NOT overwrite values of keys that are the same but have different escape flags', () => {
qb.reset_query();

@@ -104,0 +104,0 @@ qb.set({galaxy_name: 'Milky Way'}, null, false);

@@ -1,15 +0,15 @@

var should = require('chai').should();
var expect = require('chai').expect;
var qb = require('../../drivers/mysql/query_builder.js').QueryBuilder();
const should = require('chai').should();
const expect = require('chai').expect;
const qb = require('../../drivers/mysql/query_builder.js').QueryBuilder();
describe('truncate()', function() {
it('should exist', function() {
describe('truncate()', () => {
it('should exist', () => {
should.exist(qb.truncate);
});
it('should be a function', function() {
it('should be a function', () => {
qb.truncate.should.be.a('function');
});
it('should return a string', function() {
it('should return a string', () => {
qb.reset_query();
var sql = qb.truncate('galaxies');
const sql = qb.truncate('galaxies');
expect(sql).to.be.a('string');

@@ -19,7 +19,7 @@ expect(sql).to.exist;

});
it('should build a proper truncate statement', function() {
it('should build a proper truncate statement', () => {
qb.reset_query();
var sql = qb.truncate('galaxies');
const sql = qb.truncate('galaxies');
sql.should.eql('TRUNCATE `galaxies`');
});
});

@@ -1,20 +0,20 @@

var should = require('chai').should();
var expect = require('chai').expect;
var qb = require('../../drivers/mysql/query_builder.js').QueryBuilder();
const should = require('chai').should();
const expect = require('chai').expect;
const qb = require('../../drivers/mysql/query_builder.js').QueryBuilder();
var test_where = {id:3};
var test_data = [{id:3, name:'Milky Way', type: 'spiral'}, {id:4, name: 'Andromeda', type: 'spiral'}];
const test_where = {id:3};
const test_data = [{id:3, name:'Milky Way', type: 'spiral'}, {id:4, name: 'Andromeda', type: 'spiral'}];
describe('update_batch()', function() {
it('should exist', function() {
describe('update_batch()', () => {
it('should exist', () => {
should.exist(qb.update_batch);
});
it('should be a function', function() {
it('should be a function', () => {
qb.update_batch.should.be.a('function');
});
it('should build a proper batch UPDATE string', function() {
it('should build a proper batch UPDATE string', () => {
qb.reset_query();
var sql = qb.update_batch('galaxies', test_data, 'id');
const sql = qb.update_batch('galaxies', test_data, 'id');
sql.should.eql(["UPDATE (`galaxies`) SET `name` = CASE WHEN `id` = 3 THEN 'Milky Way' WHEN `id` = 4 THEN 'Andromeda' ELSE `name` END, `type` = CASE WHEN `id` = 3 THEN 'spiral' WHEN `id` = 4 THEN 'spiral' ELSE `type` END WHERE `id` IN (3,4)"]);
});
});

@@ -1,19 +0,19 @@

var should = require('chai').should();
var expect = require('chai').expect;
var qb = require('../../drivers/mysql/query_builder.js').QueryBuilder();
const should = require('chai').should();
const expect = require('chai').expect;
const qb = require('../../drivers/mysql/query_builder.js').QueryBuilder();
var test_where = {id:3};
var test_data = {name:'Milky Way', type: 'spiral'};
var test_data_set = [{id:3, name:'Milky Way', type: 'spiral'}, {id:4, name: 'Andromeda', type: 'spiral'}];
const test_where = {id:3};
const test_data = {name:'Milky Way', type: 'spiral'};
const test_data_set = [{id:3, name:'Milky Way', type: 'spiral'}, {id:4, name: 'Andromeda', type: 'spiral'}];
// table, data, callback, ignore, suffix
describe('update()', function() {
it('should exist', function() {
describe('update()', () => {
it('should exist', () => {
should.exist(qb.update);
});
it('should be a function', function() {
it('should be a function', () => {
qb.update.should.be.a('function');
});
it('should add a table to from_array when a table is supplied', function() {
it('should add a table to from_array when a table is supplied', () => {
qb.reset_query();

@@ -23,105 +23,105 @@ qb.update('galaxies', test_data, test_where);

});
it('should accept a string or falsy value for the table (first) parameter', function() {
it('should accept a string or falsy value for the table (first) parameter', () => {
qb.reset_query();
// One could choose to pass a falsy value to the first param because they have or will
// supply it with the from() method instead.
qb.reset_query(); expect(function() { qb.from('galaxies').update([], test_data); }, 'empty array provided').to.throw(Error);
qb.reset_query(); expect(function() { qb.from('galaxies').update({}, test_data); }, 'empty object provided').to.throw(Error);
qb.reset_query(); expect(function() { qb.from('galaxies').update(3, test_data); }, 'integer provided').to.throw(Error);
qb.reset_query(); expect(function() { qb.from('galaxies').update(3.5, test_data); }, 'float provided').to.throw(Error);
qb.reset_query(); expect(function() { qb.from('galaxies').update(true, test_data); }, 'true provided').to.throw(Error);
qb.reset_query(); expect(function() { qb.from('galaxies').update(Infinity, test_data); }, 'Infinity provided').to.throw(Error);
qb.reset_query(); expect(function() { qb.from('galaxies').update([1,2], test_data); }, 'array of numbers provided').to.throw(Error);
qb.reset_query(); expect(function() { qb.from('galaxies').update(/foobar/, test_data); }, 'regex provided').to.throw(Error);
qb.reset_query(); expect(function() { qb.from('galaxies').update(NaN, test_data); }, 'NaN provided').to.not.throw(Error);
qb.reset_query(); expect(function() { qb.from('galaxies').update(false, test_data); }, 'false provided').to.not.throw(Error);
qb.reset_query(); expect(function() { qb.from('galaxies').update('', test_data); }, 'empty string provided').to.not.throw(Error);
qb.reset_query(); expect(function() { qb.from('galaxies').update(' ', test_data); }, 'string full of spaces provided').to.not.throw(Error);
qb.reset_query(); expect(function() { qb.from('galaxies').update(null, test_data); }, 'null provided').to.not.throw(Error);
qb.reset_query(); expect(function() { qb.from('galaxies').update(undefined, test_data); },'undefined provided').to.not.throw(Error);
qb.reset_query(); expect(() => qb.from('galaxies').update([], test_data), 'empty array provided').to.throw(Error);
qb.reset_query(); expect(() => qb.from('galaxies').update({}, test_data), 'empty object provided').to.throw(Error);
qb.reset_query(); expect(() => qb.from('galaxies').update(3, test_data), 'integer provided').to.throw(Error);
qb.reset_query(); expect(() => qb.from('galaxies').update(3.5, test_data), 'float provided').to.throw(Error);
qb.reset_query(); expect(() => qb.from('galaxies').update(true, test_data), 'true provided').to.throw(Error);
qb.reset_query(); expect(() => qb.from('galaxies').update(Infinity, test_data), 'Infinity provided').to.throw(Error);
qb.reset_query(); expect(() => qb.from('galaxies').update([1,2], test_data), 'array of numbers provided').to.throw(Error);
qb.reset_query(); expect(() => qb.from('galaxies').update(/foobar/, test_data), 'regex provided').to.throw(Error);
qb.reset_query(); expect(() => qb.from('galaxies').update(NaN, test_data), 'NaN provided').to.not.throw(Error);
qb.reset_query(); expect(() => qb.from('galaxies').update(false, test_data), 'false provided').to.not.throw(Error);
qb.reset_query(); expect(() => qb.from('galaxies').update('', test_data), 'empty string provided').to.not.throw(Error);
qb.reset_query(); expect(() => qb.from('galaxies').update(' ', test_data), 'string full of spaces provided').to.not.throw(Error);
qb.reset_query(); expect(() => qb.from('galaxies').update(null, test_data), 'null provided').to.not.throw(Error);
qb.reset_query(); expect(() => qb.from('galaxies').update(undefined, test_data),'undefined provided').to.not.throw(Error);
});
it('should fail if a number, non-standard object, regex, boolean, array of non-objects, or non-empty string is provided in data parameter', function() {
it('should fail if a number, non-standard object, regex, boolean, array of non-objects, or non-empty string is provided in data parameter', () => {
// One could choose to pass a falsy value to the second param because they have or will
// supply data with the set() method instead.
qb.reset_query(); expect(function() { qb.update('galaxies',test_data); }, 'non-empty array provided').to.not.throw(Error);
qb.reset_query(); expect(function() { qb.update('galaxies',test_data_set); }, 'array of non-empty standard objects provided').to.not.throw(Error);
qb.reset_query(); expect(function() { qb.set({id:2}).update('galaxies',NaN); }, 'NaN provided').to.not.throw(Error);
qb.reset_query(); expect(function() { qb.set({id:2}).update('galaxies',false); }, 'false provided').to.not.throw(Error);
qb.reset_query(); expect(function() { qb.set({id:2}).update('galaxies',''); }, 'empty string provided').to.not.throw(Error);
qb.reset_query(); expect(function() { qb.set({id:2}).update('galaxies',null); }, 'null provided').to.not.throw(Error);
qb.reset_query(); expect(function() { qb.set({id:2}).update('galaxies',undefined); }, 'undefined provided').to.not.throw(Error);
qb.reset_query(); expect(function() { qb.set({id:2}).update('galaxies'); }, 'nothing provided').to.not.throw(Error);
qb.reset_query(); expect(function() { qb.set({id:2}).update('galaxies',3); }, 'integer provided').to.throw(Error);
qb.reset_query(); expect(function() { qb.set({id:2}).update('galaxies',3.5); }, 'float provided').to.throw(Error);
qb.reset_query(); expect(function() { qb.set({id:2}).update('galaxies',true); }, 'true provided').to.throw(Error);
qb.reset_query(); expect(function() { qb.set({id:2}).update('galaxies',Infinity); }, 'Infinity provided').to.throw(Error);
qb.reset_query(); expect(function() { qb.set({id:2}).update('foobar',{}); }, 'empty object provided').to.throw(Error);
qb.reset_query(); expect(function() { qb.set({id:2}).update('galaxies',[{},{}]); }, 'array of empty objects provided').to.throw(Error);
qb.reset_query(); expect(function() { qb.set({id:2}).update('galaxies',[]); }, 'empty array provided').to.throw(Error);
qb.reset_query(); expect(function() { qb.set({id:2}).update('galaxies',[1,2]); }, 'array of numbers provided').to.throw(Error);
qb.reset_query(); expect(function() { qb.set({id:2}).update('galaxies',['abc',2,{foo:'bar'}]); }, 'array of mixed values provided').to.throw(Error);
qb.reset_query(); expect(function() { qb.set({id:2}).update('galaxies',/foobar/); }, 'regex provided').to.throw(Error);
qb.reset_query(); expect(function() { qb.set({id:2}).update('galaxies',' '); }, 'string full of spaces provided').to.throw(Error);
qb.reset_query(); expect(() => qb.update('galaxies',test_data), 'non-empty array provided').to.not.throw(Error);
qb.reset_query(); expect(() => qb.update('galaxies',test_data_set), 'array of non-empty standard objects provided').to.not.throw(Error);
qb.reset_query(); expect(() => qb.set({id:2}).update('galaxies',NaN), 'NaN provided').to.not.throw(Error);
qb.reset_query(); expect(() => qb.set({id:2}).update('galaxies',false), 'false provided').to.not.throw(Error);
qb.reset_query(); expect(() => qb.set({id:2}).update('galaxies',''), 'empty string provided').to.not.throw(Error);
qb.reset_query(); expect(() => qb.set({id:2}).update('galaxies',null), 'null provided').to.not.throw(Error);
qb.reset_query(); expect(() => qb.set({id:2}).update('galaxies',undefined), 'undefined provided').to.not.throw(Error);
qb.reset_query(); expect(() => qb.set({id:2}).update('galaxies'), 'nothing provided').to.not.throw(Error);
qb.reset_query(); expect(() => qb.set({id:2}).update('galaxies',3), 'integer provided').to.throw(Error);
qb.reset_query(); expect(() => qb.set({id:2}).update('galaxies',3.5), 'float provided').to.throw(Error);
qb.reset_query(); expect(() => qb.set({id:2}).update('galaxies',true), 'true provided').to.throw(Error);
qb.reset_query(); expect(() => qb.set({id:2}).update('galaxies',Infinity), 'Infinity provided').to.throw(Error);
qb.reset_query(); expect(() => qb.set({id:2}).update('foobar',{}), 'empty object provided').to.throw(Error);
qb.reset_query(); expect(() => qb.set({id:2}).update('galaxies',[{},{}]), 'array of empty objects provided').to.throw(Error);
qb.reset_query(); expect(() => qb.set({id:2}).update('galaxies',[]), 'empty array provided').to.throw(Error);
qb.reset_query(); expect(() => qb.set({id:2}).update('galaxies',[1,2]), 'array of numbers provided').to.throw(Error);
qb.reset_query(); expect(() => qb.set({id:2}).update('galaxies',['abc',2,{foo:'bar'}]), 'array of mixed values provided').to.throw(Error);
qb.reset_query(); expect(() => qb.set({id:2}).update('galaxies',/foobar/), 'regex provided').to.throw(Error);
qb.reset_query(); expect(() => qb.set({id:2}).update('galaxies',' '), 'string full of spaces provided').to.throw(Error);
});
it('should require that there is at least something being updated', function() {
it('should require that there is at least something being updated', () => {
// @todo
});
it('should utilize pre-existing tables set in from_array', function() {
it('should utilize pre-existing tables set in from_array', () => {
qb.reset_query();
qb.from('galaxies');
var sql = qb.update(null, test_data, test_where);
const sql = qb.update(null, test_data, test_where);
sql.should.eql("UPDATE (`galaxies`) SET `name` = 'Milky Way', `type` = 'spiral' WHERE `id` = 3");
});
it('should utilize pre-existing value set in in set_array', function() {
it('should utilize pre-existing value set in in set_array', () => {
qb.reset_query();
qb.set(test_data);
var sql = qb.update('galaxies');
const sql = qb.update('galaxies');
sql.should.eql("UPDATE (`galaxies`) SET `name` = 'Milky Way', `type` = 'spiral'");
});
it('should utilize pre-existing tables and values from from_aray and set_array, respectively', function() {
it('should utilize pre-existing tables and values from from_aray and set_array, respectively', () => {
qb.reset_query();
qb.from('galaxies').set(test_data);
var sql = qb.update();
const sql = qb.update();
sql.should.eql("UPDATE (`galaxies`) SET `name` = 'Milky Way', `type` = 'spiral'");
});
it('should accept a non-empty object for the data parameter', function() {
it('should accept a non-empty object for the data parameter', () => {
qb.reset_query();
var sql = qb.update('galaxies', test_data);
const sql = qb.update('galaxies', test_data);
sql.should.eql("UPDATE (`galaxies`) SET `name` = 'Milky Way', `type` = 'spiral'");
});
it('should convert call to update_batch() if an array of non-emtpy objects is passed in the data parameter', function() {
it('should convert call to update_batch() if an array of non-emtpy objects is passed in the data parameter', () => {
qb.reset_query();
var sql = qb.update('galaxies', test_data_set);
const sql = qb.update('galaxies', test_data_set);
qb.reset_query();
var sql_b = qb.update_batch('galaxies', test_data_set, 'id');
const sql_b = qb.update_batch('galaxies', test_data_set, 'id');
sql.should.eql(sql_b);
});
it('should fail if any invalid values are passed in the data object.', function() {
it('should fail if any invalid values are passed in the data object.', () => {
qb.reset_query();
var func = function() { console.log("foo"); };
var regex = /foobar/;
var arr = [1,2,3];
var obj = {foo: 'bar'};
qb.reset_query(); expect(function() { qb.update('galaxies',{id: func}); }, 'function in data').to.throw(Error);
qb.reset_query(); expect(function() { qb.update('galaxies',{id: regex}); }, 'regex in data').to.throw(Error);
qb.reset_query(); expect(function() { qb.update('galaxies',{id: Infinity}); }, 'Infinity in data').to.throw(Error);
qb.reset_query(); expect(function() { qb.update('galaxies',{id: undefined}); }, 'undefined in data').to.throw(Error);
qb.reset_query(); expect(function() { qb.update('galaxies',{id: NaN}); }, 'NaN in data').to.throw(Error);
qb.reset_query(); expect(function() { qb.update('galaxies',{id: arr}); }, 'array in data').to.throw(Error);
qb.reset_query(); expect(function() { qb.update('galaxies',{id: obj}); }, 'object in data').to.throw(Error);
const func = () => console.log("foo");
const regex = /foobar/;
const arr = [1,2,3];
const obj = {foo: 'bar'};
qb.reset_query(); expect(() => qb.update('galaxies',{id: func}), 'function in data').to.throw(Error);
qb.reset_query(); expect(() => qb.update('galaxies',{id: regex}), 'regex in data').to.throw(Error);
qb.reset_query(); expect(() => qb.update('galaxies',{id: Infinity}), 'Infinity in data').to.throw(Error);
qb.reset_query(); expect(() => qb.update('galaxies',{id: undefined}), 'undefined in data').to.throw(Error);
qb.reset_query(); expect(() => qb.update('galaxies',{id: NaN}), 'NaN in data').to.throw(Error);
qb.reset_query(); expect(() => qb.update('galaxies',{id: arr}), 'array in data').to.throw(Error);
qb.reset_query(); expect(() => qb.update('galaxies',{id: obj}), 'object in data').to.throw(Error);
});
/*
it('should support insert ignore statements', function() {
it('should support insert ignore statements', () => {
qb.reset_query();
var sql = qb.insert_ignore('galaxies', test_data, 'ON DUPLICATE KEY UPDATE last_update = NOW()');
const sql = qb.insert_ignore('galaxies', test_data, 'ON DUPLICATE KEY UPDATE last_update = NOW()');
sql.should.eql("INSERT IGNORE INTO `galaxies` (`id`, `name`, `type`) VALUES (3, 'Milky Way', 'spiral') ON DUPLICATE KEY UPDATE last_update = NOW()");
}); */
});

@@ -1,56 +0,56 @@

var should = require('chai').should();
var expect = require('chai').expect;
var qb = require('../../drivers/mysql/query_builder.js').QueryBuilder();
const should = require('chai').should();
const expect = require('chai').expect;
const qb = require('../../drivers/mysql/query_builder.js').QueryBuilder();
describe('where_in()', function() {
it('should exist', function() {
describe('where_in()', () => {
it('should exist', () => {
should.exist(qb.where_in);
});
it('should be a function', function() {
it('should be a function', () => {
qb.where_in.should.be.a('function');
});
it('should have an array to put fields into', function() {
it('should have an array to put fields into', () => {
qb.should.have.property('where_in_array');
});
it('should have an empty array to put fields into at the beginning', function() {
it('should have an empty array to put fields into at the beginning', () => {
qb.where_in_array.should.be.empty;
});
it('should not accept anything but a non-empty string as first parameter', function() {
it('should not accept anything but a non-empty string as first parameter', () => {
qb.reset_query();
expect(function() { qb.where_in(); }, 'nothing provided').to.throw(Error);
expect(function() { qb.where_in(null); }, 'null provided').to.throw(Error);
expect(function() { qb.where_in(false); }, 'false provided').to.throw(Error);
expect(function() { qb.where_in(true); }, 'true provided').to.throw(Error);
expect(function() { qb.where_in({}); }, 'empty object provided').to.throw(Error);
expect(function() { qb.where_in({foo:'bar'}); }, 'empty object provided').to.throw(Error);
expect(function() { qb.where_in(3); }, 'integer provided').to.throw(Error);
expect(function() { qb.where_in(3.5); }, 'float provided').to.throw(Error);
expect(function() { qb.where_in(NaN); }, 'NaN provided').to.throw(Error);
expect(function() { qb.where_in(Infinity); }, 'Infinity provided').to.throw(Error);
expect(function() { qb.where_in([]); }, 'empty array provided').to.throw(Error);
expect(function() { qb.where_in([1,2]); }, 'array of numbers provided').to.throw(Error);
expect(function() { qb.where_in(''); }, 'empty string provided').to.throw(Error);
expect(function() { qb.where_in(/foobar/); }, 'regex provided').to.throw(Error);
expect(function() { qb.where_in('planet_position',[1,2,3]); }, 'valid string provided').to.not.throw(Error);
expect(() => qb.where_in(), 'nothing provided').to.throw(Error);
expect(() => qb.where_in(null), 'null provided').to.throw(Error);
expect(() => qb.where_in(false), 'false provided').to.throw(Error);
expect(() => qb.where_in(true), 'true provided').to.throw(Error);
expect(() => qb.where_in({}), 'empty object provided').to.throw(Error);
expect(() => qb.where_in({foo:'bar'}), 'empty object provided').to.throw(Error);
expect(() => qb.where_in(3), 'integer provided').to.throw(Error);
expect(() => qb.where_in(3.5), 'float provided').to.throw(Error);
expect(() => qb.where_in(NaN), 'NaN provided').to.throw(Error);
expect(() => qb.where_in(Infinity), 'Infinity provided').to.throw(Error);
expect(() => qb.where_in([]), 'empty array provided').to.throw(Error);
expect(() => qb.where_in([1,2]), 'array of numbers provided').to.throw(Error);
expect(() => qb.where_in(''), 'empty string provided').to.throw(Error);
expect(() => qb.where_in(/foobar/), 'regex provided').to.throw(Error);
expect(() => qb.where_in('planet_position',[1,2,3]), 'valid string provided').to.not.throw(Error);
});
it('should not accept anything but a non-empty array of values as second parameter', function() {
it('should not accept anything but a non-empty array of values as second parameter', () => {
qb.reset_query();
expect(function() { qb.where_in('planet'); }, 'nothing provided').to.throw(Error);
expect(function() { qb.where_in('planet',null); }, 'null provided').to.throw(Error);
expect(function() { qb.where_in('planet',false); }, 'false provided').to.throw(Error);
expect(function() { qb.where_in('planet',true); }, 'true provided').to.throw(Error);
expect(function() { qb.where_in('planet',{}); }, 'empty object provided').to.throw(Error);
expect(function() { qb.where_in('planet',{foo:'bar'}); }, 'empty object provided').to.throw(Error);
expect(function() { qb.where_in('planet',3); }, 'integer provided').to.throw(Error);
expect(function() { qb.where_in('planet',3.5); }, 'float provided').to.throw(Error);
expect(function() { qb.where_in('planet',NaN); }, 'NaN provided').to.throw(Error);
expect(function() { qb.where_in('planet',Infinity); }, 'Infinity provided').to.throw(Error);
expect(function() { qb.where_in('planet',[]); }, 'empty array provided').to.throw(Error);
expect(function() { qb.where_in('planet',''); }, 'empty string provided').to.throw(Error);
expect(function() { qb.where_in('planet',/foobar/); }, 'regex provided').to.throw(Error);
expect(function() { qb.where_in('planet',['Mars','Earth','Venus','Mercury']); }, 'non-empty array provided').to.not.throw(Error);
expect(() => qb.where_in('planet'), 'nothing provided').to.throw(Error);
expect(() => qb.where_in('planet',null), 'null provided').to.throw(Error);
expect(() => qb.where_in('planet',false), 'false provided').to.throw(Error);
expect(() => qb.where_in('planet',true), 'true provided').to.throw(Error);
expect(() => qb.where_in('planet',{}), 'empty object provided').to.throw(Error);
expect(() => qb.where_in('planet',{foo:'bar'}), 'empty object provided').to.throw(Error);
expect(() => qb.where_in('planet',3), 'integer provided').to.throw(Error);
expect(() => qb.where_in('planet',3.5), 'float provided').to.throw(Error);
expect(() => qb.where_in('planet',NaN), 'NaN provided').to.throw(Error);
expect(() => qb.where_in('planet',Infinity), 'Infinity provided').to.throw(Error);
expect(() => qb.where_in('planet',[]), 'empty array provided').to.throw(Error);
expect(() => qb.where_in('planet',''), 'empty string provided').to.throw(Error);
expect(() => qb.where_in('planet',/foobar/), 'regex provided').to.throw(Error);
expect(() => qb.where_in('planet',['Mars','Earth','Venus','Mercury']), 'non-empty array provided').to.not.throw(Error);
});
it('should require both a field name an array of values as first and second parameters, respectively', function() {
it('should require both a field name an array of values as first and second parameters, respectively', () => {
qb.reset_query();

@@ -60,3 +60,3 @@ qb.where_in('planet_position',[1,2,3]);

});
it('should concatenate multiple WHERE IN clauses with AND ', function() {
it('should concatenate multiple WHERE IN clauses with AND ', () => {
qb.reset_query();

@@ -67,3 +67,3 @@ qb.where_in('planet',['Mercury','Venus','Earth','Mars']);

});
it('should be chainable', function() {
it('should be chainable', () => {
qb.reset_query();

@@ -73,3 +73,3 @@ qb.where_in('planet',['Mercury','Venus','Earth','Mars']).where_in('planet_position',[1,2,3,4]);

});
it('should not escape fields if asked not to', function() {
it('should not escape fields if asked not to', () => {
qb.reset_query();

@@ -81,10 +81,10 @@ qb.where_in('planet_position',[1,2,3],false);

describe('where_not_in()', function() {
it('should exist', function() {
describe('where_not_in()', () => {
it('should exist', () => {
should.exist(qb.where_not_in);
});
it('should be a function', function() {
it('should be a function', () => {
qb.where_not_in.should.be.a('function');
});
it('should prepend "NOT " to "IN"', function() {
it('should prepend "NOT " to "IN"', () => {
qb.reset_query();

@@ -94,3 +94,3 @@ qb.where_not_in('planet_position',[1,2,3]);

});
it('should prepend tertiary WHERE clauses with "AND"', function() {
it('should prepend tertiary WHERE clauses with "AND"', () => {
qb.reset_query();

@@ -101,3 +101,3 @@ qb.where_not_in('planet_position',[1,2,3]);

});
it('should be chainable', function() {
it('should be chainable', () => {
qb.reset_query();

@@ -107,3 +107,3 @@ qb.where_not_in('planet_position',[1,2,3]).where_not_in('planet_position',[5,6,7]);

});
it('should be chainable with normal where', function() {
it('should be chainable with normal where', () => {
qb.reset_query();

@@ -113,3 +113,3 @@ qb.where('planet','Mars').where('galaxy','Milky Way').where_not_in('planet_position',[5,6,7]);

});
it('should not escape fields if asked not to', function() {
it('should not escape fields if asked not to', () => {
qb.reset_query();

@@ -121,10 +121,10 @@ qb.where_not_in('planet_position',[1,2,3],false);

describe('or_where_in()', function() {
it('should exist', function() {
describe('or_where_in()', () => {
it('should exist', () => {
should.exist(qb.or_where_in);
});
it('should be a function', function() {
it('should be a function', () => {
qb.or_where_in.should.be.a('function');
});
it('should prepend tertiary WHERE clauses with "OR"', function() {
it('should prepend tertiary WHERE clauses with "OR"', () => {
qb.reset_query();

@@ -135,3 +135,3 @@ qb.or_where_in('planet_position',[1,2,3]);

});
it('should be chainable', function() {
it('should be chainable', () => {
qb.reset_query();

@@ -141,3 +141,3 @@ qb.or_where_in('planet_position',[1,2,3]).or_where_in('planet_position',[5,6,7]);

});
it('should be chainable with normal where', function() {
it('should be chainable with normal where', () => {
qb.reset_query();

@@ -147,3 +147,3 @@ qb.where('planet','Mars').where('galaxy','Milky Way').or_where_in('planet_position',[5,6,7]);

});
it('should not escape fields if asked not to', function() {
it('should not escape fields if asked not to', () => {
qb.reset_query();

@@ -155,10 +155,10 @@ qb.or_where_in('planet_position',[1,2,3],false);

describe('or_where_not_in()', function() {
it('should exist', function() {
describe('or_where_not_in()', () => {
it('should exist', () => {
should.exist(qb.or_where_in);
});
it('should be a function', function() {
it('should be a function', () => {
qb.or_where_in.should.be.a('function');
});
it('should prepend "NOT " to "IN"', function() {
it('should prepend "NOT " to "IN"', () => {
qb.reset_query();

@@ -168,3 +168,3 @@ qb.or_where_not_in('planet_position',[1,2,3]);

});
it('should prepend tertiary WHERE clauses with "OR"', function() {
it('should prepend tertiary WHERE clauses with "OR"', () => {
qb.reset_query();

@@ -175,3 +175,3 @@ qb.or_where_not_in('planet_position',[1,2,3]);

});
it('should be chainable', function() {
it('should be chainable', () => {
qb.reset_query();

@@ -181,3 +181,3 @@ qb.or_where_not_in('planet_position',[1,2,3]).or_where_not_in('planet_position',[5,6,7]);

});
it('should be chainable with normal where', function() {
it('should be chainable with normal where', () => {
qb.reset_query();

@@ -187,3 +187,3 @@ qb.where('planet','Mars').where('galaxy','Milky Way').or_where_not_in('planet_position',[5,6,7]);

});
it('should not escape fields if asked not to', function() {
it('should not escape fields if asked not to', () => {
qb.reset_query();

@@ -190,0 +190,0 @@ qb.or_where_not_in('planet_position',[1,2,3],false);

@@ -1,36 +0,36 @@

var should = require('chai').should();
var expect = require('chai').expect;
var qb = require('../../drivers/mysql/query_builder.js').QueryBuilder();
const should = require('chai').should();
const expect = require('chai').expect;
const qb = require('../../drivers/mysql/query_builder.js').QueryBuilder();
describe('where()', function() {
it('should exist', function() {
describe('where()', () => {
it('should exist', () => {
should.exist(qb.where);
});
it('should be a function', function() {
it('should be a function', () => {
qb.where.should.be.a('function');
});
it('should have an array to put fields into', function() {
it('should have an array to put fields into', () => {
qb.should.have.property('where_array');
});
it('should have an empty array to put fields into at the beginning', function() {
it('should have an empty array to put fields into at the beginning', () => {
qb.where_array.should.be.empty;
});
it('should not accept anything but a non-empty string or a non-empty object', function() {
it('should not accept anything but a non-empty string or a non-empty object', () => {
qb.reset_query();
expect(function() { qb.where(); }, 'nothing provided').to.throw(Error);
expect(function() { qb.where(null); }, 'null provided').to.throw(Error);
expect(function() { qb.where(false); }, 'false provided').to.throw(Error);
expect(function() { qb.where(true); }, 'true provided').to.throw(Error);
expect(function() { qb.where({}); }, 'empty object provided').to.throw(Error);
expect(function() { qb.where(3); }, 'integer provided').to.throw(Error);
expect(function() { qb.where(3.5); }, 'float provided').to.throw(Error);
expect(function() { qb.where([]); }, 'empty array provided').to.throw(Error);
expect(function() { qb.where([1,2]); }, 'array of numbers provided').to.throw(Error);
expect(function() { qb.where(''); }, 'empty string provided').to.throw(Error);
expect(function() { qb.where('planet_position',3); }, 'valid string provided').to.not.throw(Error);
expect(function() { qb.where({planet_position: 3}); }, 'valid object provided').to.not.throw(Error);
expect(() => qb.where(), 'nothing provided').to.throw(Error);
expect(() => qb.where(null), 'null provided').to.throw(Error);
expect(() => qb.where(false), 'false provided').to.throw(Error);
expect(() => qb.where(true), 'true provided').to.throw(Error);
expect(() => qb.where({}), 'empty object provided').to.throw(Error);
expect(() => qb.where(3), 'integer provided').to.throw(Error);
expect(() => qb.where(3.5), 'float provided').to.throw(Error);
expect(() => qb.where([]), 'empty array provided').to.throw(Error);
expect(() => qb.where([1,2]), 'array of numbers provided').to.throw(Error);
expect(() => qb.where(''), 'empty string provided').to.throw(Error);
expect(() => qb.where('planet_position',3), 'valid string provided').to.not.throw(Error);
expect(() => qb.where({planet_position: 3}), 'valid object provided').to.not.throw(Error);
});
it('should accept a field name in the form of a string as the first parameter', function() {
it('should accept a field name in the form of a string as the first parameter', () => {
qb.reset_query();

@@ -40,3 +40,3 @@ qb.where('planet');

});
it('should assume second param is NULL if not provided', function() {
it('should assume second param is NULL if not provided', () => {
qb.reset_query();

@@ -46,3 +46,3 @@ qb.where('planet');

});
it('should accept NULL as second parameter and assume IS NULL', function() {
it('should accept NULL as second parameter and assume IS NULL', () => {
qb.reset_query();

@@ -52,7 +52,7 @@ qb.where('planet',null);

});
it('should accept boolean values and will transform them properly', function() {
it('should accept boolean values and will transform them properly', () => {
qb.reset_query();
qb.where('planet',true);
qb.where_array.should.eql(['`planet` = 1']);
qb.reset_query();

@@ -62,7 +62,7 @@ qb.where('planet',false);

});
it('should accept integer and float values', function() {
it('should accept integer and float values', () => {
qb.reset_query();
qb.where('planet',5);
qb.where_array.should.eql(['`planet` = 5']);
qb.reset_query();

@@ -72,7 +72,7 @@ qb.where('planet',123.456);

});
it('should accept string values', function() {
it('should accept string values', () => {
qb.reset_query();
qb.where('planet','Earth');
qb.where_array.should.eql(["`planet` = 'Earth'"]);
qb.reset_query();

@@ -82,3 +82,3 @@ qb.where('galaxy','Milky Way');

});
it('should accept arrays of values and assume a WHERE IN clause', function() {
it('should accept arrays of values and assume a WHERE IN clause', () => {
qb.reset_query();

@@ -88,3 +88,3 @@ qb.where('planet',['Mercury','Venus','Earth','Mars']);

});
it('should concatenate multiple where clauses with AND by default', function() {
it('should concatenate multiple where clauses with AND by default', () => {
qb.reset_query();

@@ -95,3 +95,3 @@ qb.where('planet',['Mercury','Venus','Earth','Mars']);

});
it('should be chainable', function() {
it('should be chainable', () => {
qb.reset_query();

@@ -101,3 +101,3 @@ qb.where('planet',['Mercury','Venus','Earth','Mars']).where('galaxy','Milky Way');

});
it('should accept an object of key/value pairs (field: value)', function() {
it('should accept an object of key/value pairs (field: value)', () => {
qb.reset_query();

@@ -107,3 +107,3 @@ qb.where({planet:'Earth',star_system:'Solar'});

});
it('should accept an object of key/value pairs (field: value) where values can be arrays', function() {
it('should accept an object of key/value pairs (field: value) where values can be arrays', () => {
qb.reset_query();

@@ -113,23 +113,23 @@ qb.where({star_system:'Solar',planet:['Earth','Mars']});

});
it('should accept an operators in the first parameter', function() {
it('should accept an operators in the first parameter', () => {
qb.reset_query();
qb.where('position >',3);
qb.where_array.should.eql(["`position` > 3"]);
qb.reset_query();
qb.where('position <',3);
qb.where_array.should.eql(["`position` < 3"]);
qb.reset_query();
qb.where('position >=',3);
qb.where_array.should.eql(["`position` >= 3"]);
qb.reset_query();
qb.where('position <=',3);
qb.where_array.should.eql(["`position` <= 3"]);
qb.reset_query();
qb.where('position <>',3);
qb.where_array.should.eql(["`position` <> 3"]);
qb.reset_query();

@@ -139,3 +139,3 @@ qb.where('position !=',3);

});
it('should not escape fields if asked not to', function() {
it('should not escape fields if asked not to', () => {
qb.reset_query();

@@ -145,3 +145,3 @@ qb.where({star_system:'Solar',planet:['Earth','Mars']},false);

});
it("should split out and escape custom WHERE strings when that is the only thing provided (except when string contains parenthesis)", function() {
it("should split out and escape custom WHERE strings when that is the only thing provided (except when string contains parenthesis)", () => {
qb.reset_query();

@@ -151,3 +151,3 @@ qb.where("planet_id = 3 AND galaxy_id > 21645 OR planet = 'Earth'");

});
it("should not try to escape where clauses utilizing functions or subqueries when provided as a string in the first and only parameter", function() {
it("should not try to escape where clauses utilizing functions or subqueries when provided as a string in the first and only parameter", () => {
qb.reset_query();

@@ -157,3 +157,3 @@ qb.where("planet_id = 3 AND galaxy_id > (SELECT MIN(id) first_galaxy FROM galaxies WHERE id IN('Milky Way','Andromeda'))");

});
it("should escape (quote) functions and subqueries as strings when provided as second parameter", function() {
it("should escape (quote) functions and subqueries as strings when provided as second parameter", () => {
qb.reset_query();

@@ -165,10 +165,10 @@ qb.where('galaxy_id >', "(SELECT MIN(id) first_galaxy FROM galaxies WHERE id IN('Milky Way','Andromeda'))");

describe('or_where()', function() {
it('should exist', function() {
describe('or_where()', () => {
it('should exist', () => {
should.exist(qb.or_where);
});
it('should be a function', function() {
it('should be a function', () => {
qb.or_where.should.be.a('function');
});
it('should prepend tertiary WHERE clauses with "OR"', function() {
it('should prepend tertiary WHERE clauses with "OR"', () => {
qb.reset_query();

@@ -179,3 +179,3 @@ qb.or_where('planet','Mars');

});
it('should be chainable', function() {
it('should be chainable', () => {
qb.reset_query();

@@ -185,3 +185,3 @@ qb.or_where('planet','Mars').or_where('planet','Venus');

});
it('should be chainable with normal where', function() {
it('should be chainable with normal where', () => {
qb.reset_query();

@@ -188,0 +188,0 @@ qb.where('planet','Mars').where('galaxy','Milky Way').or_where('planet','Venus');

@@ -9,3 +9,3 @@ mocha --timeout 5000 --reporter markdown test/*.js

<a name=""></a>
<a name="from"></a>

@@ -188,3 +188,3 @@ # from()

```js
var qb = new QueryBuilder();
const qb = new QueryBuilder();
qb.should.be.instanceOf(Object);

@@ -222,13 +222,13 @@ ```

```js
var invalid_match = /must provide a table/;
expect(function() { qb.join(); }, 'nothing provided').to.throw(Error, invalid_match);
expect(function() { qb.join(true); }, 'true provided').to.throw(Error, invalid_match);
expect(function() { qb.join(null); }, 'null provided').to.throw(Error, invalid_match);
expect(function() { qb.join(false); }, 'false provided').to.throw(Error, invalid_match);
expect(function() { qb.join({}); }, 'object provided').to.throw(Error, invalid_match);
expect(function() { qb.join([]); }, 'empty array provided').to.throw(Error, invalid_match);
expect(function() { qb.join(''); }, 'empty string provided').to.throw(Error, invalid_match);
expect(function() { qb.join(' '); }, 'string of spaces provided').to.throw(Error, invalid_match);
expect(function() { qb.join('foo'); }, 'valid string provided').to.not.throw(Error);
expect(function() { qb.join('foo'); }, 'valid string provided').to.not.throw(Error);
const invalid_match = /must provide a table/;
expect(() => qb.join(), 'nothing provided').to.throw(Error, invalid_match);
expect(() => qb.join(true), 'true provided').to.throw(Error, invalid_match);
expect(() => qb.join(null), 'null provided').to.throw(Error, invalid_match);
expect(() => qb.join(false), 'false provided').to.throw(Error, invalid_match);
expect(() => qb.join({}), 'object provided').to.throw(Error, invalid_match);
expect(() => qb.join([]), 'empty array provided').to.throw(Error, invalid_match);
expect(() => qb.join(''), 'empty string provided').to.throw(Error, invalid_match);
expect(() => qb.join(' '), 'string of spaces provided').to.throw(Error, invalid_match);
expect(() => qb.join('foo'), 'valid string provided').to.not.throw(Error);
expect(() => qb.join('foo'), 'valid string provided').to.not.throw(Error);
```

@@ -255,16 +255,16 @@

```js
var invalid_2nd_param = /You must provide a valid condition to join on when providing a join direction/;
var invalid_direction = /Invalid join direction provided as third parameter/;
const invalid_2nd_param = /You must provide a valid condition to join on when providing a join direction/;
const invalid_direction = /Invalid join direction provided as third parameter/;
expect(function() { qb.join('universe',null,'left'); }, 'null 2nd param').to.throw(Error,invalid_2nd_param);
expect(function() { qb.join('universe',false,'left'); }, 'false 2nd param').to.throw(Error,invalid_2nd_param);
expect(function() { qb.join('universe','','left'); }, 'empty string 2nd param').to.throw(Error,invalid_2nd_param);
expect(function() { qb.join('universe',' ','left'); }, 'just spaces 2nd param').to.throw(Error,invalid_2nd_param);
expect(function() { qb.join('universe',5,'left'); }, 'integer 2nd param').to.throw(Error,invalid_2nd_param);
expect(function() { qb.join('universe',5.6,'left'); }, 'float 2nd param').to.throw(Error,invalid_2nd_param);
expect(function() { qb.join('universe',[],'left'); }, 'array 2nd param').to.throw(Error,invalid_2nd_param);
expect(function() { qb.join('universe',{},'left'); }, 'object 2nd param').to.throw(Error,invalid_2nd_param);
expect(function() { qb.join('universe','foo = bar','fake'); }, 'invalid 3rd param').to.throw(Error,invalid_direction);
expect(function() { qb.join('universe','foo = bar'); }, 'no 3rd param').to.not.throw(Error);
expect(function() { qb.join('universe','foo = bar','left'); }, '3 valid params').to.not.throw(Error);
expect(() => qb.join('universe',null,'left'), 'null 2nd param').to.throw(Error,invalid_2nd_param);
expect(() => qb.join('universe',false,'left'), 'false 2nd param').to.throw(Error,invalid_2nd_param);
expect(() => qb.join('universe','','left'), 'empty string 2nd param').to.throw(Error,invalid_2nd_param);
expect(() => qb.join('universe',' ','left'), 'just spaces 2nd param').to.throw(Error,invalid_2nd_param);
expect(() => qb.join('universe',5,'left'), 'integer 2nd param').to.throw(Error,invalid_2nd_param);
expect(() => qb.join('universe',5.6,'left'), 'float 2nd param').to.throw(Error,invalid_2nd_param);
expect(() => qb.join('universe',[],'left'), 'array 2nd param').to.throw(Error,invalid_2nd_param);
expect(() => qb.join('universe',{},'left'), 'object 2nd param').to.throw(Error,invalid_2nd_param);
expect(() => qb.join('universe','foo = bar','fake'), 'invalid 3rd param').to.throw(Error,invalid_direction);
expect(() => qb.join('universe','foo = bar'), 'no 3rd param').to.not.throw(Error);
expect(() => qb.join('universe','foo = bar','left'), '3 valid params').to.not.throw(Error);
```

@@ -276,20 +276,20 @@

// NOTE: A lot of this functionality was already tested when testing second param
var invalid_direction = /Invalid join direction provided as third parameter/;
const invalid_direction = /Invalid join direction provided as third parameter/;
expect(function() { qb.join('universe','foo = bar','fake'); }, 'invalid 3rd param').to.throw(Error,invalid_direction);
expect(function() { qb.join('universe',null,null); }, 'invalid 2nd and 3rd params').to.not.throw(Error);
expect(function() { qb.join('universe','foo = bar',''); }, 'empty third param').to.not.throw(Error);
expect(function() { qb.join('universe','foo = bar',' '); }, 'just spaces').to.not.throw(Error);
expect(function() { qb.join('universe','foo = bar',null); }, 'null third param').to.not.throw(Error);
expect(function() { qb.join('universe','foo = bar',false); }, 'false third param').to.not.throw(Error);
expect(function() { qb.join('universe','foo = bar',5); }, 'integer third param').to.not.throw(Error);
expect(function() { qb.join('universe','foo = bar',5.5); }, 'float third param').to.not.throw(Error);
expect(function() { qb.join('universe','foo = bar',{}); }, 'object third param').to.not.throw(Error);
expect(function() { qb.join('universe','foo = bar',[]); }, 'array third param').to.not.throw(Error);
expect(function() { qb.join('universe','foo = bar','left '); }, 'trailing space').to.not.throw(Error);
expect(function() { qb.join('universe','foo = bar',' left '); }, 'leading and trailing space').to.not.throw(Error);
expect(function() { qb.join('universe','foo = bar',' left'); }, 'leading space').to.not.throw(Error);
expect(function() { qb.join('universe','foo = bar','left'); }, 'lowercase direction').to.not.throw(Error);
expect(function() { qb.join('universe','foo = bar','LEFT'); }, 'uppercase direction').to.not.throw(Error);
expect(function() { qb.join('universe','foo = bar','LEFT OUTER'); }, 'two word direction').to.not.throw(Error);
expect(() => qb.join('universe','foo = bar','fake'), 'invalid 3rd param').to.throw(Error,invalid_direction);
expect(() => qb.join('universe',null,null), 'invalid 2nd and 3rd params').to.not.throw(Error);
expect(() => qb.join('universe','foo = bar',''), 'empty third param').to.not.throw(Error);
expect(() => qb.join('universe','foo = bar',' '), 'just spaces').to.not.throw(Error);
expect(() => qb.join('universe','foo = bar',null), 'null third param').to.not.throw(Error);
expect(() => qb.join('universe','foo = bar',false), 'false third param').to.not.throw(Error);
expect(() => qb.join('universe','foo = bar',5), 'integer third param').to.not.throw(Error);
expect(() => qb.join('universe','foo = bar',5.5), 'float third param').to.not.throw(Error);
expect(() => qb.join('universe','foo = bar',{}), 'object third param').to.not.throw(Error);
expect(() => qb.join('universe','foo = bar',[]), 'array third param').to.not.throw(Error);
expect(() => qb.join('universe','foo = bar','left '), 'trailing space').to.not.throw(Error);
expect(() => qb.join('universe','foo = bar',' left '), 'leading and trailing space').to.not.throw(Error);
expect(() => qb.join('universe','foo = bar',' left'), 'leading space').to.not.throw(Error);
expect(() => qb.join('universe','foo = bar','left'), 'lowercase direction').to.not.throw(Error);
expect(() => qb.join('universe','foo = bar','LEFT'), 'uppercase direction').to.not.throw(Error);
expect(() => qb.join('universe','foo = bar','LEFT OUTER'), 'two word direction').to.not.throw(Error);
```

@@ -374,14 +374,14 @@

```js
var invalid_match = /requires a string or array/;
var empty_str_match = /string is empty/;
var empty_arr_match = /array is empty/;
expect(function() { qb.select(); }, 'nothing provided').to.throw(Error, invalid_match);
expect(function() { qb.select(true); }, 'true provided').to.throw(Error, invalid_match);
expect(function() { qb.select(null); }, 'null provided').to.throw(Error, invalid_match);
expect(function() { qb.select(false); }, 'false provided').to.throw(Error, invalid_match);
expect(function() { qb.select({}); }, 'object provided').to.throw(Error, invalid_match);
expect(function() { qb.select([]); }, 'empty array provided').to.throw(Error, empty_arr_match);
expect(function() { qb.select(''); }, 'empty string provided').to.throw(Error, empty_str_match);
expect(function() { qb.select(' '); }, 'string of spaces provided').to.throw(Error, empty_str_match);
expect(function() { qb.select('blah'); }, 'valid string provided').to.not.throw(Error);
const invalid_match = /requires a string or array/;
const empty_str_match = /string is empty/;
const empty_arr_match = /array is empty/;
expect(() => qb.select(), 'nothing provided').to.throw(Error, invalid_match);
expect(() => qb.select(true), 'true provided').to.throw(Error, invalid_match);
expect(() => qb.select(null), 'null provided').to.throw(Error, invalid_match);
expect(() => qb.select(false), 'false provided').to.throw(Error, invalid_match);
expect(() => qb.select({}), 'object provided').to.throw(Error, invalid_match);
expect(() => qb.select([]), 'empty array provided').to.throw(Error, empty_arr_match);
expect(() => qb.select(''), 'empty string provided').to.throw(Error, empty_str_match);
expect(() => qb.select(' '), 'string of spaces provided').to.throw(Error, empty_str_match);
expect(() => qb.select('blah'), 'valid string provided').to.not.throw(Error);
```

@@ -560,9 +560,9 @@

qb.resetQuery();
expect(function() {
qb.select('s.star_systems, (select count(p.*) as count from planets p where p.star_system_id IN(2,3,5)) as num_planets');
}).to.throw(Error);
expect(
() => qb.select('s.star_systems, (select count(p.*) as count from planets p where p.star_system_id IN(2,3,5)) as num_planets')
).to.throw(Error);
expect(function() {
qb.select('s.star_systems, (select count(p.*) as count from planets p where p.star_system_id IN(2,3,5)) as num_planets',false);
}).to.not.throw(Error);
expect(
() => qb.select('s.star_systems, (select count(p.*) as count from planets p where p.star_system_id IN(2,3,5)) as num_planets',false)
).to.not.throw(Error);
```

@@ -569,0 +569,0 @@

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc