Update docs

This commit is contained in:
Timothy Warren 2014-10-27 13:36:32 -04:00
parent 83af1d3946
commit 16cab60352
3 changed files with 65 additions and 37 deletions

View File

@ -85,6 +85,7 @@ var helpers = require('./helpers');
var d = { var d = {
identifierChar: '"', identifierChar: '"',
tablePrefix: null, tablePrefix: null,
hasTruncate: true,
/** /**
* Low level function for naive quoting of strings * Low level function for naive quoting of strings
@ -214,6 +215,22 @@ var d = {
} }
return raw; return raw;
},
/**
* SQL to truncate the passed table
*
* @param {String} table
* @return {String} - sql
*/
truncate: function(table) {
var sql = (d.hasTruncate)
? 'TRUNCATE '
: 'DELETE FROM ';
sql += d.quoteTable(table);
return sql;
} }
}; };

View File

@ -309,7 +309,7 @@
<ul class="dummy"> <ul class="dummy">
<li> <li>
<a href="query-builder.js.html">query-builder.js</a>, <a href="query-builder.js.html">query-builder.js</a>,
<a href="query-builder.js.html#sunlight-1-line-396">line 396</a> <a href="query-builder.js.html#sunlight-1-line-399">line 399</a>
</li> </li>
</ul> </ul>
</dd> </dd>
@ -554,7 +554,7 @@
<ul class="dummy"> <ul class="dummy">
<li> <li>
<a href="query-builder.js.html">query-builder.js</a>, <a href="query-builder.js.html">query-builder.js</a>,
<a href="query-builder.js.html#sunlight-1-line-738">line 738</a> <a href="query-builder.js.html#sunlight-1-line-741">line 741</a>
</li> </li>
</ul> </ul>
</dd> </dd>
@ -745,7 +745,7 @@
<ul class="dummy"> <ul class="dummy">
<li> <li>
<a href="query-builder.js.html">query-builder.js</a>, <a href="query-builder.js.html">query-builder.js</a>,
<a href="query-builder.js.html#sunlight-1-line-849">line 849</a> <a href="query-builder.js.html#sunlight-1-line-860">line 860</a>
</li> </li>
</ul> </ul>
</dd> </dd>
@ -944,7 +944,7 @@
<ul class="dummy"> <ul class="dummy">
<li> <li>
<a href="query-builder.js.html">query-builder.js</a>, <a href="query-builder.js.html">query-builder.js</a>,
<a href="query-builder.js.html#sunlight-1-line-827">line 827</a> <a href="query-builder.js.html#sunlight-1-line-838">line 838</a>
</li> </li>
</ul> </ul>
</dd> </dd>
@ -1145,7 +1145,7 @@
<ul class="dummy"> <ul class="dummy">
<li> <li>
<a href="query-builder.js.html">query-builder.js</a>, <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-822">line 822</a>
</li> </li>
</ul> </ul>
</dd> </dd>
@ -1336,7 +1336,7 @@
<ul class="dummy"> <ul class="dummy">
<li> <li>
<a href="query-builder.js.html">query-builder.js</a>, <a href="query-builder.js.html">query-builder.js</a>,
<a href="query-builder.js.html#sunlight-1-line-838">line 838</a> <a href="query-builder.js.html#sunlight-1-line-849">line 849</a>
</li> </li>
</ul> </ul>
</dd> </dd>
@ -1431,7 +1431,7 @@
<ul class="dummy"> <ul class="dummy">
<li> <li>
<a href="query-builder.js.html">query-builder.js</a>, <a href="query-builder.js.html">query-builder.js</a>,
<a href="query-builder.js.html#sunlight-1-line-343">line 343</a> <a href="query-builder.js.html#sunlight-1-line-346">line 346</a>
</li> </li>
</ul> </ul>
</dd> </dd>
@ -1578,7 +1578,7 @@
<ul class="dummy"> <ul class="dummy">
<li> <li>
<a href="query-builder.js.html">query-builder.js</a>, <a href="query-builder.js.html">query-builder.js</a>,
<a href="query-builder.js.html#sunlight-1-line-620">line 620</a> <a href="query-builder.js.html#sunlight-1-line-623">line 623</a>
</li> </li>
</ul> </ul>
</dd> </dd>
@ -1665,7 +1665,7 @@
<ul class="dummy"> <ul class="dummy">
<li> <li>
<a href="query-builder.js.html">query-builder.js</a>, <a href="query-builder.js.html">query-builder.js</a>,
<a href="query-builder.js.html#sunlight-1-line-719">line 719</a> <a href="query-builder.js.html#sunlight-1-line-722">line 722</a>
</li> </li>
</ul> </ul>
</dd> </dd>
@ -1752,7 +1752,7 @@
<ul class="dummy"> <ul class="dummy">
<li> <li>
<a href="query-builder.js.html">query-builder.js</a>, <a href="query-builder.js.html">query-builder.js</a>,
<a href="query-builder.js.html#sunlight-1-line-683">line 683</a> <a href="query-builder.js.html#sunlight-1-line-686">line 686</a>
</li> </li>
</ul> </ul>
</dd> </dd>
@ -1937,7 +1937,7 @@
<ul class="dummy"> <ul class="dummy">
<li> <li>
<a href="query-builder.js.html">query-builder.js</a>, <a href="query-builder.js.html">query-builder.js</a>,
<a href="query-builder.js.html#sunlight-1-line-469">line 469</a> <a href="query-builder.js.html#sunlight-1-line-472">line 472</a>
</li> </li>
</ul> </ul>
</dd> </dd>
@ -2147,7 +2147,7 @@
<ul class="dummy"> <ul class="dummy">
<li> <li>
<a href="query-builder.js.html">query-builder.js</a>, <a href="query-builder.js.html">query-builder.js</a>,
<a href="query-builder.js.html#sunlight-1-line-761">line 761</a> <a href="query-builder.js.html#sunlight-1-line-764">line 764</a>
</li> </li>
</ul> </ul>
</dd> </dd>
@ -2373,7 +2373,7 @@
<ul class="dummy"> <ul class="dummy">
<li> <li>
<a href="query-builder.js.html">query-builder.js</a>, <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-598">line 598</a>
</li> </li>
</ul> </ul>
</dd> </dd>
@ -2599,7 +2599,7 @@
<ul class="dummy"> <ul class="dummy">
<li> <li>
<a href="query-builder.js.html">query-builder.js</a>, <a href="query-builder.js.html">query-builder.js</a>,
<a href="query-builder.js.html#sunlight-1-line-418">line 418</a> <a href="query-builder.js.html#sunlight-1-line-421">line 421</a>
</li> </li>
</ul> </ul>
</dd> </dd>
@ -2778,7 +2778,7 @@
<ul class="dummy"> <ul class="dummy">
<li> <li>
<a href="query-builder.js.html">query-builder.js</a>, <a href="query-builder.js.html">query-builder.js</a>,
<a href="query-builder.js.html#sunlight-1-line-671">line 671</a> <a href="query-builder.js.html#sunlight-1-line-674">line 674</a>
</li> </li>
</ul> </ul>
</dd> </dd>
@ -3004,7 +3004,7 @@
<ul class="dummy"> <ul class="dummy">
<li> <li>
<a href="query-builder.js.html">query-builder.js</a>, <a href="query-builder.js.html">query-builder.js</a>,
<a href="query-builder.js.html#sunlight-1-line-431">line 431</a> <a href="query-builder.js.html#sunlight-1-line-434">line 434</a>
</li> </li>
</ul> </ul>
</dd> </dd>
@ -3195,7 +3195,7 @@
<ul class="dummy"> <ul class="dummy">
<li> <li>
<a href="query-builder.js.html">query-builder.js</a>, <a href="query-builder.js.html">query-builder.js</a>,
<a href="query-builder.js.html#sunlight-1-line-643">line 643</a> <a href="query-builder.js.html#sunlight-1-line-646">line 646</a>
</li> </li>
</ul> </ul>
</dd> </dd>
@ -3283,7 +3283,7 @@ prefixed with 'OR'</p>
<ul class="dummy"> <ul class="dummy">
<li> <li>
<a href="query-builder.js.html">query-builder.js</a>, <a href="query-builder.js.html">query-builder.js</a>,
<a href="query-builder.js.html#sunlight-1-line-696">line 696</a> <a href="query-builder.js.html#sunlight-1-line-699">line 699</a>
</li> </li>
</ul> </ul>
</dd> </dd>
@ -3468,7 +3468,7 @@ prefixed with 'OR'</p>
<ul class="dummy"> <ul class="dummy">
<li> <li>
<a href="query-builder.js.html">query-builder.js</a>, <a href="query-builder.js.html">query-builder.js</a>,
<a href="query-builder.js.html#sunlight-1-line-483">line 483</a> <a href="query-builder.js.html#sunlight-1-line-486">line 486</a>
</li> </li>
</ul> </ul>
</dd> </dd>
@ -3694,7 +3694,7 @@ prefixed with 'OR'</p>
<ul class="dummy"> <ul class="dummy">
<li> <li>
<a href="query-builder.js.html">query-builder.js</a>, <a href="query-builder.js.html">query-builder.js</a>,
<a href="query-builder.js.html#sunlight-1-line-444">line 444</a> <a href="query-builder.js.html#sunlight-1-line-447">line 447</a>
</li> </li>
</ul> </ul>
</dd> </dd>
@ -3782,7 +3782,7 @@ prefixed with 'OR NOT'</p>
<ul class="dummy"> <ul class="dummy">
<li> <li>
<a href="query-builder.js.html">query-builder.js</a>, <a href="query-builder.js.html">query-builder.js</a>,
<a href="query-builder.js.html#sunlight-1-line-708">line 708</a> <a href="query-builder.js.html#sunlight-1-line-711">line 711</a>
</li> </li>
</ul> </ul>
</dd> </dd>
@ -4008,7 +4008,7 @@ prefixed with 'OR NOT'</p>
<ul class="dummy"> <ul class="dummy">
<li> <li>
<a href="query-builder.js.html">query-builder.js</a>, <a href="query-builder.js.html">query-builder.js</a>,
<a href="query-builder.js.html#sunlight-1-line-457">line 457</a> <a href="query-builder.js.html#sunlight-1-line-460">line 460</a>
</li> </li>
</ul> </ul>
</dd> </dd>
@ -4193,7 +4193,7 @@ prefixed with 'OR NOT'</p>
<ul class="dummy"> <ul class="dummy">
<li> <li>
<a href="query-builder.js.html">query-builder.js</a>, <a href="query-builder.js.html">query-builder.js</a>,
<a href="query-builder.js.html#sunlight-1-line-509">line 509</a> <a href="query-builder.js.html#sunlight-1-line-512">line 512</a>
</li> </li>
</ul> </ul>
</dd> </dd>
@ -4352,7 +4352,7 @@ prefixed with 'OR NOT'</p>
<ul class="dummy"> <ul class="dummy">
<li> <li>
<a href="query-builder.js.html">query-builder.js</a>, <a href="query-builder.js.html">query-builder.js</a>,
<a href="query-builder.js.html#sunlight-1-line-533">line 533</a> <a href="query-builder.js.html#sunlight-1-line-536">line 536</a>
</li> </li>
</ul> </ul>
</dd> </dd>
@ -4511,7 +4511,7 @@ prefixed with 'OR NOT'</p>
<ul class="dummy"> <ul class="dummy">
<li> <li>
<a href="query-builder.js.html">query-builder.js</a>, <a href="query-builder.js.html">query-builder.js</a>,
<a href="query-builder.js.html#sunlight-1-line-557">line 557</a> <a href="query-builder.js.html#sunlight-1-line-560">line 560</a>
</li> </li>
</ul> </ul>
</dd> </dd>
@ -4650,7 +4650,7 @@ prefixed with 'OR NOT'</p>
<ul class="dummy"> <ul class="dummy">
<li> <li>
<a href="query-builder.js.html">query-builder.js</a>, <a href="query-builder.js.html">query-builder.js</a>,
<a href="query-builder.js.html#sunlight-1-line-362">line 362</a> <a href="query-builder.js.html#sunlight-1-line-365">line 365</a>
</li> </li>
</ul> </ul>
</dd> </dd>
@ -4832,7 +4832,7 @@ prefixed with 'OR NOT'</p>
<ul class="dummy"> <ul class="dummy">
<li> <li>
<a href="query-builder.js.html">query-builder.js</a>, <a href="query-builder.js.html">query-builder.js</a>,
<a href="query-builder.js.html#sunlight-1-line-569">line 569</a> <a href="query-builder.js.html#sunlight-1-line-572">line 572</a>
</li> </li>
</ul> </ul>
</dd> </dd>
@ -5042,7 +5042,7 @@ prefixed with 'OR NOT'</p>
<ul class="dummy"> <ul class="dummy">
<li> <li>
<a href="query-builder.js.html">query-builder.js</a>, <a href="query-builder.js.html">query-builder.js</a>,
<a href="query-builder.js.html#sunlight-1-line-779">line 779</a> <a href="query-builder.js.html#sunlight-1-line-782">line 782</a>
</li> </li>
</ul> </ul>
</dd> </dd>
@ -5227,7 +5227,7 @@ prefixed with 'OR NOT'</p>
<ul class="dummy"> <ul class="dummy">
<li> <li>
<a href="query-builder.js.html">query-builder.js</a>, <a href="query-builder.js.html">query-builder.js</a>,
<a href="query-builder.js.html#sunlight-1-line-497">line 497</a> <a href="query-builder.js.html#sunlight-1-line-500">line 500</a>
</li> </li>
</ul> </ul>
</dd> </dd>
@ -5386,7 +5386,7 @@ prefixed with 'OR NOT'</p>
<ul class="dummy"> <ul class="dummy">
<li> <li>
<a href="query-builder.js.html">query-builder.js</a>, <a href="query-builder.js.html">query-builder.js</a>,
<a href="query-builder.js.html#sunlight-1-line-521">line 521</a> <a href="query-builder.js.html#sunlight-1-line-524">line 524</a>
</li> </li>
</ul> </ul>
</dd> </dd>
@ -5545,7 +5545,7 @@ prefixed with 'OR NOT'</p>
<ul class="dummy"> <ul class="dummy">
<li> <li>
<a href="query-builder.js.html">query-builder.js</a>, <a href="query-builder.js.html">query-builder.js</a>,
<a href="query-builder.js.html#sunlight-1-line-545">line 545</a> <a href="query-builder.js.html#sunlight-1-line-548">line 548</a>
</li> </li>
</ul> </ul>
</dd> </dd>

View File

@ -100,6 +100,9 @@ var QueryBuilder = function(driver, adapter) {
var parser = require('./query-parser')(driver); var parser = require('./query-parser')(driver);
this.driver = driver;
this.adapter = adapter;
/** /**
* "Private" methods * "Private" methods
* *
@ -851,13 +854,14 @@ var QueryBuilder = function(driver, adapter) {
* @param {Function} callback - Callback for handling response from the database * @param {Function} callback - Callback for handling response from the database
* @return void * @return void
*/ */
this.update = function(table, data, callback) { this.update = function(/*table, data, callback*/) {
if (data) { var args = getArgs('table:string, [data]:object, callback:function', arguments);
this.set(data); if (args.data) {
this.set(args.data);
} }
// Run the query // Run the query
_p.run('update', table, callback); _p.run('update', args.table, args.callback);
}; };
/** /**
@ -867,9 +871,16 @@ var QueryBuilder = function(driver, adapter) {
* @param {Function} callback - Callback for handling response from the database * @param {Function} callback - Callback for handling response from the database
* @return void * @return void
*/ */
this['delete'] = function (table, callback) { this['delete'] = function (/*table, [where], callback*/) {
var args = getArgs('table:string, [where], callback:function', arguments);
if (args.where)
{
this.where(args.where);
}
// Run the query // Run the query
_p.run('delete', table, callback); _p.run('delete', args.table, args.callback);
}; };
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------