diff --git a/docs/driver.js.html b/docs/driver.js.html index c3a280f..84d2262 100644 --- a/docs/driver.js.html +++ b/docs/driver.js.html @@ -196,7 +196,6 @@ var d = { if (raw.contains('(') && raw.contains(')')) { var funcs = pattern.exec(raw); - console.log(funcs); // Unquote the function raw = raw.replace(funcs[0], funcs[1]); diff --git a/docs/helpers.js.html b/docs/helpers.js.html index d659812..47ada29 100644 --- a/docs/helpers.js.html +++ b/docs/helpers.js.html @@ -69,12 +69,13 @@
/** @module helpers */
+			class="sunlight-highlight-javascript linenums">"use strict";
 
-"use strict";
+/** @module helpers */
 
 require('./es6-polyfill');
 
+/** @alias module:helpers */
 var h = {
 	/**
 	 * Wrap String.prototype.trim in a way that is easily mappable
@@ -134,6 +135,16 @@ var h = {
 // Define an 'is' method for each type
 var types = ['Null','Undefined','Object','Array','String','Number','Boolean','Function','RegExp','NaN','Infinite'];
 types.forEach(function (t) {
+	/**
+	 * Determine whether a variable is of the type specified in the
+	 * function name, eg isNumber
+	 *
+	 * Types available are Null, Undefined, Object, Array, String, Number, Boolean, Function, RegExp, NaN and Infinite
+	 *
+	 * @name is[type]
+	 * @param {mixed} o
+	 * @return {Boolean}
+	 */
     h['is' + t] = function (o) {
         return h.type(o) === t.toLowerCase();
     };
diff --git a/docs/module-helpers.html b/docs/module-helpers.html
index 96cfa44..6649f65 100644
--- a/docs/module-helpers.html
+++ b/docs/module-helpers.html
@@ -109,7 +109,7 @@
 		
 	
@@ -138,7 +138,693 @@
     
 
     
+        

Members

+
+ +
+

<inner> is[type]

+ + +
+
+ +
+

Determine whether a variable is of the type specified in the +function name, eg isNumber

+

Types available are Null, Undefined, Object, Array, String, Number, Boolean, Function, RegExp, NaN and Infinite

+
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ +
+ + + + + + + +
+ + + +
+ +
+ + + +

Methods

+ +
+ +
+

<static> isScalar(obj) → {bool}

+ + +
+
+ + +
+

Determine whether an object is scalar

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
obj + + +mixed + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ +
+ + + + + + + +
+ + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +bool + + +
+
+ + + + + +
+ + + +
+

<static> splitTrim(char, string) → {String}

+ + +
+
+ + +
+

Split a string by a character, trim the string +and rejoin the string

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
char + + +String + + + +
string + + +String + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ +
+ + + + + + + +
+ + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + +
+
+ + + + + +
+ + + +
+

<static> stringTrim(str) → {String}

+ + +
+
+ + +
+

Wrap String.prototype.trim in a way that is easily mappable

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
str + + +String + + + +

The string to trim

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ +
+ + + + + + + +
+ + + + + + + + + + + +
Returns:
+ + +
+
    +
  • The trimmed string
  • +
+
+ + + +
+
+ Type +
+
+ +String + + +
+
+ + + + + +
+ + + +
+

<static> type(o) → {String}

+ + +
+
+ + +
+

Get the type of the variable passed

+
+ + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
o + + +mixed + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ +
+ + + + + +
See:
+
+ +
+ + + +
+ + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +String + + +
+
+ + + + + +
+ +
diff --git a/docs/module-query-builder.html b/docs/module-query-builder.html index 606ac0f..0e170bc 100644 --- a/docs/module-query-builder.html +++ b/docs/module-query-builder.html @@ -305,7 +305,7 @@ @@ -550,7 +550,7 @@ @@ -741,7 +741,7 @@ @@ -940,7 +940,7 @@ @@ -1141,7 +1141,7 @@ @@ -1332,7 +1332,7 @@ @@ -1427,7 +1427,7 @@ @@ -1574,7 +1574,7 @@ @@ -1661,7 +1661,7 @@ @@ -1748,7 +1748,7 @@ @@ -1933,7 +1933,7 @@ @@ -2143,7 +2143,7 @@ @@ -2408,7 +2408,7 @@ @@ -2634,7 +2634,7 @@ @@ -2813,7 +2813,7 @@ @@ -3039,7 +3039,7 @@ @@ -3230,7 +3230,7 @@ @@ -3318,7 +3318,7 @@ prefixed with 'OR'

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

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

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

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

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

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

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

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

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

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

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

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

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

diff --git a/docs/query-builder.js.html b/docs/query-builder.js.html index aeacb93..7cd8728 100644 --- a/docs/query-builder.js.html +++ b/docs/query-builder.js.html @@ -95,10 +95,6 @@ var QueryBuilder = function(driver, adapter) { // That 'new' keyword is annoying if ( ! (this instanceof QueryBuilder)) return new QueryBuilder(driver, adapter); - // Keep these properties as object members so they can be mocked/substituted - this.driver = driver; - this.adapter = adapter; - /** * "Private" methods * @@ -136,7 +132,7 @@ var QueryBuilder = function(driver, adapter) { // Append the limit, if it exists if (helpers.isNumber(state.limit)) { - sql = this.driver.limit(sql, state.limit, state.offset); + sql = driver.limit(sql, state.limit, state.offset); } return sql; @@ -179,7 +175,7 @@ var QueryBuilder = function(driver, adapter) { return sql; }, like: function (field, val, pos, like, conj) { - field = this.driver.quoteIdentifiers(field); + field = driver.quoteIdentifiers(field); like = field + " " + like + " ?"; @@ -266,7 +262,7 @@ var QueryBuilder = function(driver, adapter) { // is an operator such as >, <, !=, etc. var fieldArray = field.split(' '); - var item = this.driver.quoteIdentifiers(fieldArray[0]); + var item = driver.quoteIdentifiers(fieldArray[0]); // Simple key value, or an operator? item += (fieldArray.length === 1) ? '=?' : " " + fieldArray[1] + " ?"; @@ -301,7 +297,7 @@ var QueryBuilder = function(driver, adapter) { // is an operator such as >, <, !=, etc. var fieldArray = field.split(' ').map(helpers.stringTrim); - var item = this.driver.quoteIdentifiers(fieldArray[0]); + var item = driver.quoteIdentifiers(fieldArray[0]); // Simple key value, or an operator? item += (fieldArray.length === 1) ? '=?' : " " + fieldArray[1] + " ?"; @@ -314,7 +310,7 @@ var QueryBuilder = function(driver, adapter) { }); }, whereIn: function(key, val, inClause, conj) { - key = this.driver.quoteIdentifiers(key); + key = driver.quoteIdentifiers(key); var params = []; params.fill('?', 0, val.length); @@ -432,7 +428,7 @@ var QueryBuilder = function(driver, adapter) { } }); - var safeArray = this.driver.quoteIdentifiers(fields); + var safeArray = driver.quoteIdentifiers(fields); // Join the strings back together safeArray.forEach(function (field, index) { @@ -458,8 +454,8 @@ var QueryBuilder = function(driver, adapter) { var identArray = tableName.trim().split(' ').map(helpers.stringTrim); // Quote/prefix identifiers - identArray[0] = this.driver.quoteTable(identArray[0]); - identArray = this.driver.quoteIdentifiers(identArray); + identArray[0] = driver.quoteTable(identArray[0]); + identArray = driver.quoteIdentifiers(identArray); // Put it back together state.fromString = identArray.join(' '); @@ -631,7 +627,7 @@ var QueryBuilder = function(driver, adapter) { // Use the keys of the array to make the insert/update string // and escape the field names - state.setArrayKeys = state.setArrayKeys.map(this.driver._quote); + state.setArrayKeys = state.setArrayKeys.map(driver._quote); // Generate the "set" string state.setString = state.setArrayKeys.join('=?,'); @@ -666,12 +662,12 @@ var QueryBuilder = function(driver, adapter) { this.groupBy = function(field) { if (Array.isArray(field)) { - var newGroupArray = field.map(this.driver.quoteIdentifiers); + var newGroupArray = field.map(driver.quoteIdentifiers); state.groupArray.concat(newGroupArray); } else { - state.groupArray.push(this.driver.quoteIdentifiers(field)); + state.groupArray.push(driver.quoteIdentifiers(field)); } state.groupString = ' GROUP BY ' + state.groupArray.join(','); @@ -690,7 +686,7 @@ var QueryBuilder = function(driver, adapter) { type = type || 'ASC'; // Set the fields for later manipulation - field = this.driver.quoteIdentifiers(field); + field = driver.quoteIdentifiers(field); state.orderArray[field] = type; var orderClauses = []; diff --git a/lib/driver.js b/lib/driver.js index 27b23f5..26c3a3c 100755 --- a/lib/driver.js +++ b/lib/driver.js @@ -125,7 +125,6 @@ var d = { if (raw.contains('(') && raw.contains(')')) { var funcs = pattern.exec(raw); - console.log(funcs); // Unquote the function raw = raw.replace(funcs[0], funcs[1]); diff --git a/lib/helpers.js b/lib/helpers.js index 2fa21e3..f69185d 100755 --- a/lib/helpers.js +++ b/lib/helpers.js @@ -1,9 +1,10 @@ -/** @module helpers */ - "use strict"; +/** @module helpers */ + require('./es6-polyfill'); +/** @alias module:helpers */ var h = { /** * Wrap String.prototype.trim in a way that is easily mappable @@ -63,6 +64,16 @@ var h = { // Define an 'is' method for each type var types = ['Null','Undefined','Object','Array','String','Number','Boolean','Function','RegExp','NaN','Infinite']; types.forEach(function (t) { + /** + * Determine whether a variable is of the type specified in the + * function name, eg isNumber + * + * Types available are Null, Undefined, Object, Array, String, Number, Boolean, Function, RegExp, NaN and Infinite + * + * @name is[type] + * @param {mixed} o + * @return {Boolean} + */ h['is' + t] = function (o) { return h.type(o) === t.toLowerCase(); }; diff --git a/lib/query-builder.js b/lib/query-builder.js index 83ecccb..38f070c 100755 --- a/lib/query-builder.js +++ b/lib/query-builder.js @@ -24,10 +24,6 @@ var QueryBuilder = function(driver, adapter) { // That 'new' keyword is annoying if ( ! (this instanceof QueryBuilder)) return new QueryBuilder(driver, adapter); - // Keep these properties as object members so they can be mocked/substituted - this.driver = driver; - this.adapter = adapter; - /** * "Private" methods * @@ -65,7 +61,7 @@ var QueryBuilder = function(driver, adapter) { // Append the limit, if it exists if (helpers.isNumber(state.limit)) { - sql = this.driver.limit(sql, state.limit, state.offset); + sql = driver.limit(sql, state.limit, state.offset); } return sql; @@ -108,7 +104,7 @@ var QueryBuilder = function(driver, adapter) { return sql; }, like: function (field, val, pos, like, conj) { - field = this.driver.quoteIdentifiers(field); + field = driver.quoteIdentifiers(field); like = field + " " + like + " ?"; @@ -195,7 +191,7 @@ var QueryBuilder = function(driver, adapter) { // is an operator such as >, <, !=, etc. var fieldArray = field.split(' '); - var item = this.driver.quoteIdentifiers(fieldArray[0]); + var item = driver.quoteIdentifiers(fieldArray[0]); // Simple key value, or an operator? item += (fieldArray.length === 1) ? '=?' : " " + fieldArray[1] + " ?"; @@ -230,7 +226,7 @@ var QueryBuilder = function(driver, adapter) { // is an operator such as >, <, !=, etc. var fieldArray = field.split(' ').map(helpers.stringTrim); - var item = this.driver.quoteIdentifiers(fieldArray[0]); + var item = driver.quoteIdentifiers(fieldArray[0]); // Simple key value, or an operator? item += (fieldArray.length === 1) ? '=?' : " " + fieldArray[1] + " ?"; @@ -243,7 +239,7 @@ var QueryBuilder = function(driver, adapter) { }); }, whereIn: function(key, val, inClause, conj) { - key = this.driver.quoteIdentifiers(key); + key = driver.quoteIdentifiers(key); var params = []; params.fill('?', 0, val.length); @@ -361,7 +357,7 @@ var QueryBuilder = function(driver, adapter) { } }); - var safeArray = this.driver.quoteIdentifiers(fields); + var safeArray = driver.quoteIdentifiers(fields); // Join the strings back together safeArray.forEach(function (field, index) { @@ -387,8 +383,8 @@ var QueryBuilder = function(driver, adapter) { var identArray = tableName.trim().split(' ').map(helpers.stringTrim); // Quote/prefix identifiers - identArray[0] = this.driver.quoteTable(identArray[0]); - identArray = this.driver.quoteIdentifiers(identArray); + identArray[0] = driver.quoteTable(identArray[0]); + identArray = driver.quoteIdentifiers(identArray); // Put it back together state.fromString = identArray.join(' '); @@ -560,7 +556,7 @@ var QueryBuilder = function(driver, adapter) { // Use the keys of the array to make the insert/update string // and escape the field names - state.setArrayKeys = state.setArrayKeys.map(this.driver._quote); + state.setArrayKeys = state.setArrayKeys.map(driver._quote); // Generate the "set" string state.setString = state.setArrayKeys.join('=?,'); @@ -595,12 +591,12 @@ var QueryBuilder = function(driver, adapter) { this.groupBy = function(field) { if (Array.isArray(field)) { - var newGroupArray = field.map(this.driver.quoteIdentifiers); + var newGroupArray = field.map(driver.quoteIdentifiers); state.groupArray.concat(newGroupArray); } else { - state.groupArray.push(this.driver.quoteIdentifiers(field)); + state.groupArray.push(driver.quoteIdentifiers(field)); } state.groupString = ' GROUP BY ' + state.groupArray.join(','); @@ -619,7 +615,7 @@ var QueryBuilder = function(driver, adapter) { type = type || 'ASC'; // Set the fields for later manipulation - field = this.driver.quoteIdentifiers(field); + field = driver.quoteIdentifiers(field); state.orderArray[field] = type; var orderClauses = []; diff --git a/tests/helpers_test.js b/tests/helpers_test.js index e1004ec..9381b0d 100644 --- a/tests/helpers_test.js +++ b/tests/helpers_test.js @@ -10,6 +10,17 @@ var helperTests = { test.deepEqual('string', helpers.type(new String("Foo")), "String Wrapper returns 'string' not 'object'"); test.done(); } + }, + 'is..Method tests exist' : function(test) { + test.expect(11); + + var types = ['Null','Undefined','Object','Array','String','Number','Boolean','Function','RegExp','NaN','Infinite']; + + types.forEach(function(type) { + test.ok(helpers['is' + type], 'is' + type + ' method exists'); + }); + + test.done(); } }; diff --git a/tests/query-builder-base.js b/tests/query-builder-base.js index 895a997..6819b19 100644 --- a/tests/query-builder-base.js +++ b/tests/query-builder-base.js @@ -36,6 +36,14 @@ module.exports = (function() { base.qb.from('create_test') .get(base.testCallback.bind(test, test)); test.done(); + }, + 'Get with limit': function(test) { + base.qb.get('create_test', 2, base.testCallback.bind(test, test)); + test.done(); + }, + 'Get with limit and offset': function(test) { + base.qb.get('create_test', 2, 1, base.testCallback.bind(test, test)); + test.done(); } }, 'Select tests' : {