diff --git a/docs/adapter.js.html b/docs/adapter.js.html index e98bf2f..756b7c4 100644 --- a/docs/adapter.js.html +++ b/docs/adapter.js.html @@ -110,7 +110,7 @@ module.exports = { Documentation generated by JSDoc 3.3.0-alpha9 - on Tue Nov 4th 2014 using the DocStrap template. diff --git a/docs/driver.js.html b/docs/driver.js.html index ca5d896..daa3b05 100644 --- a/docs/driver.js.html +++ b/docs/driver.js.html @@ -252,7 +252,7 @@ module.exports = d; Documentation generated by JSDoc 3.3.0-alpha9 - on Tue Nov 4th 2014 using the DocStrap template. diff --git a/docs/helpers.js.html b/docs/helpers.js.html index 997432e..caf43be 100644 --- a/docs/helpers.js.html +++ b/docs/helpers.js.html @@ -121,6 +121,57 @@ var h = { isScalar: function(obj) { var scalar = ['string', 'number', 'boolean']; return scalar.indexOf(h.type(obj)) !== -1; + }, + /** + * Get a list of values with a common key from an array of objects + * + * @param {Array} arr - The array of objects to search + * @param {String} key - The key of the object to get + * @return {Array} + */ + arrayPluck: function(arr, key) { + var output = []; + + // Empty case + if (arr.length === 0) return output; + + arr.forEach(function(obj) { + if ( ! h.isUndefined(obj[key])) + { + output.push(obj[key]); + } + }); + + return output; + }, + /** + * Determine if a value matching the passed regular expression is + * in the passed array + * + * @param {Array} arr - The array to search + * @param {RegExp} pattern - The pattern to match + * @return {Boolean} - If an array item matches the pattern + */ + regexInArray: function(arr, pattern) { + // Empty case(s) + if ( ! h.isArray(arr)) return false; + if (arr.length === 0) return false; + + var i, l = arr.length; + + for(i=0; i< l; i++) + { + // Recurse for nested arrays + if (Array.isArray(arr[i])) + { + return h.regexInArray(arr[i], pattern); + } + + // Short circuit if any items match + if (pattern.test(arr[i])) return true; + } + + return false; } }; @@ -168,7 +219,7 @@ module.exports = h; Documentation generated by JSDoc 3.3.0-alpha9 - on Tue Nov 4th 2014 using the DocStrap template. diff --git a/docs/index.html b/docs/index.html index 46ca9b0..6099f99 100644 --- a/docs/index.html +++ b/docs/index.html @@ -148,7 +148,7 @@ query.select('foo') Documentation generated by JSDoc 3.3.0-alpha9 - on Tue Nov 4th 2014 using the DocStrap template. diff --git a/docs/module-adapter.html b/docs/module-adapter.html index 0621a47..08b6b03 100644 --- a/docs/module-adapter.html +++ b/docs/module-adapter.html @@ -354,7 +354,7 @@ Documentation generated by JSDoc 3.3.0-alpha9 - on Tue Nov 4th 2014 using the DocStrap template. diff --git a/docs/module-driver.html b/docs/module-driver.html index af5b957..efcb4bf 100644 --- a/docs/module-driver.html +++ b/docs/module-driver.html @@ -170,7 +170,7 @@ Documentation generated by JSDoc 3.3.0-alpha9 - on Tue Nov 4th 2014 using the DocStrap template. diff --git a/docs/module-helpers.html b/docs/module-helpers.html index cecda21..9f822c3 100644 --- a/docs/module-helpers.html +++ b/docs/module-helpers.html @@ -190,7 +190,7 @@ function name, eg isNumber

@@ -215,6 +215,173 @@ function name, eg isNumber

+
+

<static> arrayPluck(arr, key) → {Array}

+ + +
+
+ + +
+

Get a list of values with a common key from an array of objects

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
arr + + +Array + + + +

The array of objects to search

key + + +String + + + +

The key of the object to get

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ +
+ + + + + + + +
+ + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Array + + +
+
+ + + + + +
+ + +

<static> isScalar(obj) → {bool}

@@ -355,6 +522,180 @@ function name, eg isNumber

+ + + + +
+

<static> regexInArray(arr, pattern) → {Boolean}

+ + +
+
+ + +
+

Determine if a value matching the passed regular expression is +in the passed array

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
arr + + +Array + + + +

The array to search

pattern + + +RegExp + + + +

The pattern to match

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ +
+ + + + + + + +
+ + + + + + + + + + + +
Returns:
+ + +
+
    +
  • If an array item matches the pattern
  • +
+
+ + + +
+
+ Type +
+
+ +Boolean + + +
+
+ + + + +
@@ -686,7 +1027,7 @@ function name, eg isNumber

Documentation generated by JSDoc 3.3.0-alpha9 - on Tue Nov 4th 2014 using the DocStrap template. diff --git a/docs/module-node-query.html b/docs/module-node-query.html index 36ea837..68a30e5 100644 --- a/docs/module-node-query.html +++ b/docs/module-node-query.html @@ -334,6 +334,105 @@ +

Methods

+ +
+ +
+

getQuery() → {queryBuilder}

+ + +
+
+ + +
+

Return an existing query builder instance

+
+ + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ +
+ + + + + + + +
+ + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +queryBuilder + + +
+
+ + + + + +
+ +
+ @@ -358,7 +457,7 @@ Documentation generated by JSDoc 3.3.0-alpha9 - on Tue Nov 4th 2014 using the DocStrap template. diff --git a/docs/module-query-builder.html b/docs/module-query-builder.html index 456ac08..2721e0c 100644 --- a/docs/module-query-builder.html +++ b/docs/module-query-builder.html @@ -383,7 +383,7 @@ @@ -519,7 +519,7 @@ @@ -764,7 +764,7 @@ @@ -955,7 +955,7 @@ @@ -1154,7 +1154,7 @@ @@ -1355,7 +1355,7 @@ @@ -1546,7 +1546,7 @@ @@ -1641,7 +1641,7 @@ @@ -1788,7 +1788,7 @@ @@ -1875,7 +1875,7 @@ @@ -1962,7 +1962,7 @@ @@ -2147,7 +2147,7 @@ @@ -2357,7 +2357,7 @@ @@ -2539,7 +2539,7 @@ @@ -2771,7 +2771,7 @@ @@ -2997,7 +2997,7 @@ @@ -3176,7 +3176,7 @@ @@ -3402,7 +3402,7 @@ @@ -3593,7 +3593,7 @@ @@ -3681,7 +3681,7 @@ prefixed with 'OR'

@@ -3866,7 +3866,7 @@ prefixed with 'OR'

@@ -4092,7 +4092,7 @@ prefixed with 'OR'

@@ -4180,7 +4180,7 @@ prefixed with 'OR NOT'

@@ -4406,7 +4406,7 @@ prefixed with 'OR NOT'

@@ -4591,7 +4591,7 @@ prefixed with 'OR NOT'

@@ -4750,7 +4750,7 @@ prefixed with 'OR NOT'

@@ -4909,7 +4909,7 @@ prefixed with 'OR NOT'

@@ -5048,7 +5048,7 @@ prefixed with 'OR NOT'

@@ -5230,7 +5230,7 @@ prefixed with 'OR NOT'

@@ -5440,7 +5440,7 @@ prefixed with 'OR NOT'

@@ -5625,7 +5625,7 @@ prefixed with 'OR NOT'

@@ -5784,7 +5784,7 @@ prefixed with 'OR NOT'

@@ -5943,7 +5943,7 @@ prefixed with 'OR NOT'

@@ -6007,7 +6007,7 @@ prefixed with 'OR NOT'

Documentation generated by JSDoc 3.3.0-alpha9 - on Tue Nov 4th 2014 using the DocStrap template. diff --git a/docs/module-query-parser.html b/docs/module-query-parser.html index c25bce7..a18b9f6 100644 --- a/docs/module-query-parser.html +++ b/docs/module-query-parser.html @@ -466,7 +466,7 @@ Documentation generated by JSDoc 3.3.0-alpha9 - on Tue Nov 4th 2014 using the DocStrap template. diff --git a/docs/modules.list.html b/docs/modules.list.html index 9d83e69..409d48a 100644 --- a/docs/modules.list.html +++ b/docs/modules.list.html @@ -158,7 +158,7 @@ Documentation generated by JSDoc 3.3.0-alpha9 - on Tue Nov 4th 2014 using the DocStrap template. diff --git a/docs/node-query.js.html b/docs/node-query.js.html index efc9a1e..c7aafe3 100644 --- a/docs/node-query.js.html +++ b/docs/node-query.js.html @@ -76,55 +76,59 @@ class="sunlight-highlight-javascript linenums">"use strict"; /** @module node-query */ -var nodeQuery = {}; +var NodeQuery = function() { -var instance = null; + var instance = null; -/** - * Create a query builder object - * - * @alias module:node-query - * @param {String} drivername - The name of the database type, eg. mysql or pg - * @param {Object} connObject - A connection object from the database library you are connecting with - * @param {String} connLib - The name of the db connection library you are using, eg. mysql or mysql2 - * @return {queryBuilder} - */ -nodeQuery.init = function (driverType, connObject, connLib) { - var fs = require('fs'), - qb = require('./query-builder'); + /** + * Create a query builder object + * + * @alias module:node-query + * @param {String} drivername - The name of the database type, eg. mysql or pg + * @param {Object} connObject - A connection object from the database library you are connecting with + * @param {String} connLib - The name of the db connection library you are using, eg. mysql or mysql2 + * @return {queryBuilder} + */ + this.init = function (driverType, connObject, connLib) { + var fs = require('fs'), + qb = require('./query-builder'); - var paths = { - driver: __dirname + '/drivers/' + driverType + '.js', - adapter: __dirname + '/adapters/' + connLib + '.js' + var paths = { + driver: __dirname + '/drivers/' + driverType + '.js', + adapter: __dirname + '/adapters/' + connLib + '.js' + }; + + Object.keys(paths).forEach(function(type) { + if ( ! fs.existsSync(paths[type])) + { + console.log(paths[type]); + throw new Error('Selected ' + type + ' does not exist!'); + } + }); + + instance = qb(require(paths.driver), require(paths.adapter)(connObject)); + + return instance; }; - Object.keys(paths).forEach(function(type) { - if ( ! fs.existsSync(paths[type])) - { - console.log(paths[type]); - throw new Error('Selected ' + type + ' does not exist!'); + /** + * Return an existing query builder instance + * + * @return {queryBuilder} + */ + this.getQuery = function () { + if ( ! instance) { + throw new Error("No Query Builder instance to return"); } - }); - instance = qb(require(paths.driver), require(paths.adapter)(connObject)); + return instance; + }; - return instance; }; -/** - * Return an existing query builder instance - * - * @return {queryBuilder} - */ -nodeQuery.getQuery = function () { - if ( ! instance) { - throw new Error("No Query Builder instance to return"); - } - return instance; -}; -module.exports = nodeQuery; +module.exports = new NodeQuery(); @@ -145,7 +149,7 @@ module.exports = nodeQuery; Documentation generated by JSDoc 3.3.0-alpha9 - on Tue Nov 4th 2014 using the DocStrap template. diff --git a/docs/query-builder.js.html b/docs/query-builder.js.html index afa561c..1f46b3c 100644 --- a/docs/query-builder.js.html +++ b/docs/query-builder.js.html @@ -280,8 +280,9 @@ var QueryBuilder = function(driver, adapter) { lastItem = state.queryMap[state.queryMap.length - 1]; // Determine the correct conjunction + var conjunctionList = helpers.arrayPluck(state.queryMap, 'conjunction'); var conj = defaultConj; - if (state.queryMap.length === 0 || firstItem.conjunction.contains('JOIN')) + if (state.queryMap.length === 0 || ( ! helpers.regexInArray(conjunctionList, /^ ?WHERE/i))) { conj = " WHERE "; } @@ -987,7 +988,7 @@ module.exports = QueryBuilder; Documentation generated by JSDoc 3.3.0-alpha9 - on Tue Nov 4th 2014 using the DocStrap template. diff --git a/docs/query-parser.js.html b/docs/query-parser.js.html index f645f67..74f5e2b 100644 --- a/docs/query-parser.js.html +++ b/docs/query-parser.js.html @@ -184,7 +184,7 @@ module.exports = QueryParser; Documentation generated by JSDoc 3.3.0-alpha9 - on Tue Nov 4th 2014 using the DocStrap template.