Re-organize test to use main node-query method

This commit is contained in:
Timothy Warren 2014-10-23 13:50:11 -04:00
parent 873bfbc9eb
commit b52f0762e4
10 changed files with 787 additions and 70 deletions

View File

@ -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]);

View File

@ -69,12 +69,13 @@
<section>
<article>
<pre
class="sunlight-highlight-javascript linenums">/** @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();
};

View File

@ -109,7 +109,7 @@
<ul class="dummy">
<li>
<a href="helpers.js.html">helpers.js</a>,
<a href="helpers.js.html#sunlight-1-line-1">line 1</a>
<a href="helpers.js.html#sunlight-1-line-3">line 3</a>
</li>
</ul>
</dd>
@ -138,7 +138,693 @@
<h3 class="subsection-title">Members</h3>
<dl>
<dt class="name" id="is[type]">
<h4><span class="type-signature">&lt;inner> </span>is[type]<span class="type-signature"></span></h4>
</dt>
<dd>
<div class="description">
<p>Determine whether a variable is of the type specified in the
function name, eg isNumber</p>
<p>Types available are Null, Undefined, Object, Array, String, Number, Boolean, Function, RegExp, NaN and Infinite</p>
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source">
<ul class="dummy">
<li>
<a href="helpers.js.html">helpers.js</a>,
<a href="helpers.js.html#sunlight-1-line-67">line 67</a>
</li>
</ul>
</dd>
</dl>
</dd>
</dl>
<h3 class="subsection-title">Methods</h3>
<dl>
<dt>
<h4 class="name" id="isScalar"><span class="type-signature">&lt;static> </span>isScalar<span class="signature">(obj)</span><span class="type-signature"> &rarr; {bool}</span></h4>
</dt>
<dd>
<div class="description">
<p>Determine whether an object is scalar</p>
</div>
<h5>Parameters:</h5>
<table class="params table table-striped">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>obj</code></td>
<td class="type">
<span class="param-type">mixed</span>
</td>
<td class="description last"></td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source">
<ul class="dummy">
<li>
<a href="helpers.js.html">helpers.js</a>,
<a href="helpers.js.html#sunlight-1-line-58">line 58</a>
</li>
</ul>
</dd>
</dl>
<h5>Returns:</h5>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">bool</span>
</dd>
</dl>
</dd>
<dt>
<h4 class="name" id="splitTrim"><span class="type-signature">&lt;static> </span>splitTrim<span class="signature">(char, string)</span><span class="type-signature"> &rarr; {String}</span></h4>
</dt>
<dd>
<div class="description">
<p>Split a string by a character, trim the string
and rejoin the string</p>
</div>
<h5>Parameters:</h5>
<table class="params table table-striped">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>char</code></td>
<td class="type">
<span class="param-type">String</span>
</td>
<td class="description last"></td>
</tr>
<tr>
<td class="name"><code>string</code></td>
<td class="type">
<span class="param-type">String</span>
</td>
<td class="description last"></td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source">
<ul class="dummy">
<li>
<a href="helpers.js.html">helpers.js</a>,
<a href="helpers.js.html#sunlight-1-line-26">line 26</a>
</li>
</ul>
</dd>
</dl>
<h5>Returns:</h5>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">String</span>
</dd>
</dl>
</dd>
<dt>
<h4 class="name" id="stringTrim"><span class="type-signature">&lt;static> </span>stringTrim<span class="signature">(str)</span><span class="type-signature"> &rarr; {String}</span></h4>
</dt>
<dd>
<div class="description">
<p>Wrap String.prototype.trim in a way that is easily mappable</p>
</div>
<h5>Parameters:</h5>
<table class="params table table-striped">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>str</code></td>
<td class="type">
<span class="param-type">String</span>
</td>
<td class="description last"><p>The string to trim</p></td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source">
<ul class="dummy">
<li>
<a href="helpers.js.html">helpers.js</a>,
<a href="helpers.js.html#sunlight-1-line-15">line 15</a>
</li>
</ul>
</dd>
</dl>
<h5>Returns:</h5>
<div class="param-desc">
<ul>
<li>The trimmed string</li>
</ul>
</div>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">String</span>
</dd>
</dl>
</dd>
<dt>
<h4 class="name" id="type"><span class="type-signature">&lt;static> </span>type<span class="signature">(o)</span><span class="type-signature"> &rarr; {String}</span></h4>
</dt>
<dd>
<div class="description">
<p>Get the type of the variable passed</p>
</div>
<h5>Parameters:</h5>
<table class="params table table-striped">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>o</code></td>
<td class="type">
<span class="param-type">mixed</span>
</td>
<td class="description last"></td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source">
<ul class="dummy">
<li>
<a href="helpers.js.html">helpers.js</a>,
<a href="helpers.js.html#sunlight-1-line-37">line 37</a>
</li>
</ul>
</dd>
<dt class="tag-see">See:</dt>
<dd class="tag-see">
<ul>
<li><a href="https://techblog.badoo.com/blog/2013/11/01/type-checking-in-javascript/">https://techblog.badoo.com/blog/2013/11/01/type-checking-in-javascript/</a></li>
<li><a href="http://toddmotto.com/understanding-javascript-types-and-reliable-type-checking/">http://toddmotto.com/understanding-javascript-types-and-reliable-type-checking/</a></li>
</ul>
</dd>
</dl>
<h5>Returns:</h5>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">String</span>
</dd>
</dl>
</dd>
</dl>

View File

@ -305,7 +305,7 @@
<ul class="dummy">
<li>
<a href="query-builder.js.html">query-builder.js</a>,
<a href="query-builder.js.html#sunlight-1-line-385">line 385</a>
<a href="query-builder.js.html#sunlight-1-line-381">line 381</a>
</li>
</ul>
</dd>
@ -550,7 +550,7 @@
<ul class="dummy">
<li>
<a href="query-builder.js.html">query-builder.js</a>,
<a href="query-builder.js.html#sunlight-1-line-712">line 712</a>
<a href="query-builder.js.html#sunlight-1-line-708">line 708</a>
</li>
</ul>
</dd>
@ -741,7 +741,7 @@
<ul class="dummy">
<li>
<a href="query-builder.js.html">query-builder.js</a>,
<a href="query-builder.js.html#sunlight-1-line-822">line 822</a>
<a href="query-builder.js.html#sunlight-1-line-818">line 818</a>
</li>
</ul>
</dd>
@ -940,7 +940,7 @@
<ul class="dummy">
<li>
<a href="query-builder.js.html">query-builder.js</a>,
<a href="query-builder.js.html#sunlight-1-line-800">line 800</a>
<a href="query-builder.js.html#sunlight-1-line-796">line 796</a>
</li>
</ul>
</dd>
@ -1141,7 +1141,7 @@
<ul class="dummy">
<li>
<a href="query-builder.js.html">query-builder.js</a>,
<a href="query-builder.js.html#sunlight-1-line-784">line 784</a>
<a href="query-builder.js.html#sunlight-1-line-780">line 780</a>
</li>
</ul>
</dd>
@ -1332,7 +1332,7 @@
<ul class="dummy">
<li>
<a href="query-builder.js.html">query-builder.js</a>,
<a href="query-builder.js.html#sunlight-1-line-811">line 811</a>
<a href="query-builder.js.html#sunlight-1-line-807">line 807</a>
</li>
</ul>
</dd>
@ -1427,7 +1427,7 @@
<ul class="dummy">
<li>
<a href="query-builder.js.html">query-builder.js</a>,
<a href="query-builder.js.html#sunlight-1-line-332">line 332</a>
<a href="query-builder.js.html#sunlight-1-line-328">line 328</a>
</li>
</ul>
</dd>
@ -1574,7 +1574,7 @@
<ul class="dummy">
<li>
<a href="query-builder.js.html">query-builder.js</a>,
<a href="query-builder.js.html#sunlight-1-line-595">line 595</a>
<a href="query-builder.js.html#sunlight-1-line-591">line 591</a>
</li>
</ul>
</dd>
@ -1661,7 +1661,7 @@
<ul class="dummy">
<li>
<a href="query-builder.js.html">query-builder.js</a>,
<a href="query-builder.js.html#sunlight-1-line-693">line 693</a>
<a href="query-builder.js.html#sunlight-1-line-689">line 689</a>
</li>
</ul>
</dd>
@ -1748,7 +1748,7 @@
<ul class="dummy">
<li>
<a href="query-builder.js.html">query-builder.js</a>,
<a href="query-builder.js.html#sunlight-1-line-657">line 657</a>
<a href="query-builder.js.html#sunlight-1-line-653">line 653</a>
</li>
</ul>
</dd>
@ -1933,7 +1933,7 @@
<ul class="dummy">
<li>
<a href="query-builder.js.html">query-builder.js</a>,
<a href="query-builder.js.html#sunlight-1-line-458">line 458</a>
<a href="query-builder.js.html#sunlight-1-line-454">line 454</a>
</li>
</ul>
</dd>
@ -2143,7 +2143,7 @@
<ul class="dummy">
<li>
<a href="query-builder.js.html">query-builder.js</a>,
<a href="query-builder.js.html#sunlight-1-line-735">line 735</a>
<a href="query-builder.js.html#sunlight-1-line-731">line 731</a>
</li>
</ul>
</dd>
@ -2408,7 +2408,7 @@
<ul class="dummy">
<li>
<a href="query-builder.js.html">query-builder.js</a>,
<a href="query-builder.js.html#sunlight-1-line-581">line 581</a>
<a href="query-builder.js.html#sunlight-1-line-577">line 577</a>
</li>
</ul>
</dd>
@ -2634,7 +2634,7 @@
<ul class="dummy">
<li>
<a href="query-builder.js.html">query-builder.js</a>,
<a href="query-builder.js.html#sunlight-1-line-407">line 407</a>
<a href="query-builder.js.html#sunlight-1-line-403">line 403</a>
</li>
</ul>
</dd>
@ -2813,7 +2813,7 @@
<ul class="dummy">
<li>
<a href="query-builder.js.html">query-builder.js</a>,
<a href="query-builder.js.html#sunlight-1-line-645">line 645</a>
<a href="query-builder.js.html#sunlight-1-line-641">line 641</a>
</li>
</ul>
</dd>
@ -3039,7 +3039,7 @@
<ul class="dummy">
<li>
<a href="query-builder.js.html">query-builder.js</a>,
<a href="query-builder.js.html#sunlight-1-line-420">line 420</a>
<a href="query-builder.js.html#sunlight-1-line-416">line 416</a>
</li>
</ul>
</dd>
@ -3230,7 +3230,7 @@
<ul class="dummy">
<li>
<a href="query-builder.js.html">query-builder.js</a>,
<a href="query-builder.js.html#sunlight-1-line-618">line 618</a>
<a href="query-builder.js.html#sunlight-1-line-614">line 614</a>
</li>
</ul>
</dd>
@ -3318,7 +3318,7 @@ prefixed with 'OR'</p>
<ul class="dummy">
<li>
<a href="query-builder.js.html">query-builder.js</a>,
<a href="query-builder.js.html#sunlight-1-line-670">line 670</a>
<a href="query-builder.js.html#sunlight-1-line-666">line 666</a>
</li>
</ul>
</dd>
@ -3503,7 +3503,7 @@ prefixed with 'OR'</p>
<ul class="dummy">
<li>
<a href="query-builder.js.html">query-builder.js</a>,
<a href="query-builder.js.html#sunlight-1-line-470">line 470</a>
<a href="query-builder.js.html#sunlight-1-line-466">line 466</a>
</li>
</ul>
</dd>
@ -3729,7 +3729,7 @@ prefixed with 'OR'</p>
<ul class="dummy">
<li>
<a href="query-builder.js.html">query-builder.js</a>,
<a href="query-builder.js.html#sunlight-1-line-433">line 433</a>
<a href="query-builder.js.html#sunlight-1-line-429">line 429</a>
</li>
</ul>
</dd>
@ -3817,7 +3817,7 @@ prefixed with 'OR NOT'</p>
<ul class="dummy">
<li>
<a href="query-builder.js.html">query-builder.js</a>,
<a href="query-builder.js.html#sunlight-1-line-682">line 682</a>
<a href="query-builder.js.html#sunlight-1-line-678">line 678</a>
</li>
</ul>
</dd>
@ -4043,7 +4043,7 @@ prefixed with 'OR NOT'</p>
<ul class="dummy">
<li>
<a href="query-builder.js.html">query-builder.js</a>,
<a href="query-builder.js.html#sunlight-1-line-446">line 446</a>
<a href="query-builder.js.html#sunlight-1-line-442">line 442</a>
</li>
</ul>
</dd>
@ -4228,7 +4228,7 @@ prefixed with 'OR NOT'</p>
<ul class="dummy">
<li>
<a href="query-builder.js.html">query-builder.js</a>,
<a href="query-builder.js.html#sunlight-1-line-494">line 494</a>
<a href="query-builder.js.html#sunlight-1-line-490">line 490</a>
</li>
</ul>
</dd>
@ -4387,7 +4387,7 @@ prefixed with 'OR NOT'</p>
<ul class="dummy">
<li>
<a href="query-builder.js.html">query-builder.js</a>,
<a href="query-builder.js.html#sunlight-1-line-518">line 518</a>
<a href="query-builder.js.html#sunlight-1-line-514">line 514</a>
</li>
</ul>
</dd>
@ -4546,7 +4546,7 @@ prefixed with 'OR NOT'</p>
<ul class="dummy">
<li>
<a href="query-builder.js.html">query-builder.js</a>,
<a href="query-builder.js.html#sunlight-1-line-542">line 542</a>
<a href="query-builder.js.html#sunlight-1-line-538">line 538</a>
</li>
</ul>
</dd>
@ -4685,7 +4685,7 @@ prefixed with 'OR NOT'</p>
<ul class="dummy">
<li>
<a href="query-builder.js.html">query-builder.js</a>,
<a href="query-builder.js.html#sunlight-1-line-351">line 351</a>
<a href="query-builder.js.html#sunlight-1-line-347">line 347</a>
</li>
</ul>
</dd>
@ -4867,7 +4867,7 @@ prefixed with 'OR NOT'</p>
<ul class="dummy">
<li>
<a href="query-builder.js.html">query-builder.js</a>,
<a href="query-builder.js.html#sunlight-1-line-554">line 554</a>
<a href="query-builder.js.html#sunlight-1-line-550">line 550</a>
</li>
</ul>
</dd>
@ -5077,7 +5077,7 @@ prefixed with 'OR NOT'</p>
<ul class="dummy">
<li>
<a href="query-builder.js.html">query-builder.js</a>,
<a href="query-builder.js.html#sunlight-1-line-752">line 752</a>
<a href="query-builder.js.html#sunlight-1-line-748">line 748</a>
</li>
</ul>
</dd>
@ -5262,7 +5262,7 @@ prefixed with 'OR NOT'</p>
<ul class="dummy">
<li>
<a href="query-builder.js.html">query-builder.js</a>,
<a href="query-builder.js.html#sunlight-1-line-482">line 482</a>
<a href="query-builder.js.html#sunlight-1-line-478">line 478</a>
</li>
</ul>
</dd>
@ -5421,7 +5421,7 @@ prefixed with 'OR NOT'</p>
<ul class="dummy">
<li>
<a href="query-builder.js.html">query-builder.js</a>,
<a href="query-builder.js.html#sunlight-1-line-506">line 506</a>
<a href="query-builder.js.html#sunlight-1-line-502">line 502</a>
</li>
</ul>
</dd>
@ -5580,7 +5580,7 @@ prefixed with 'OR NOT'</p>
<ul class="dummy">
<li>
<a href="query-builder.js.html">query-builder.js</a>,
<a href="query-builder.js.html#sunlight-1-line-530">line 530</a>
<a href="query-builder.js.html#sunlight-1-line-526">line 526</a>
</li>
</ul>
</dd>

View File

@ -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 >, &lt;, !=, 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 >, &lt;, !=, 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 = [];

View File

@ -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]);

View File

@ -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();
};

View File

@ -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 = [];

View File

@ -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();
}
};

View File

@ -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' : {