updating when dependency, storing the promise on the current object per the spec

This commit is contained in:
Tim Griesser 2013-05-10 14:12:28 -04:00
parent e0cafbb927
commit 9928af4682
3 changed files with 55 additions and 13 deletions

View File

@ -219,6 +219,7 @@
<li> <a href="#Builder-increment">increment</a></li>
<li> <a href="#Builder-decrement">decrement</a></li>
<li> <a href="#Builder-truncate">truncate *</a></li>
<li> <a href="#Builder-debug">debug</a></li>
<li><b><a href="#Schema-Building">Interface:</a></b></li>
<li> <a href="#Builder-then">then</a></li>
<li> <a href="#Builder-exec">exec</a></li>
@ -636,6 +637,24 @@ Knex('accounts')
Decrements a column's value by the specified amount.
</p>
<p id="Builder-increment">
<b class="header">increment</b><code>.increment(column, value)</code>
<br />
Increments a column's value by the specified amount.
</p>
<p id="Builder-truncate">
<b class="header">truncate</b><code>.truncate()</code>
<br />
Truncates the current table.
</p>
<p id="Builder-debug">
<b class="header">debug</b><code>.debug()</code>
<br />
Turns on debugging for the current query chain.
</p>
<h2 id="Transaction">Knex.Transaction</h2>
<p>
@ -868,10 +887,32 @@ Knex.createTable('accounts', function() {
<h2 id="faq">F.A.Q.</h2>
<p>
Once some questions show up, I'll put them here.
<p id="faq-debug">
<b class="header">How do I debug?</b><br />
If you pass <tt>{debug: true}</tt> as one of the options in your initialize settings, you can see
all of the query calls being made. Sometimes you need to dive a bit further into
the various calls and see what all is going on behind the scenes. I'd recommend
<a href="https://github.com/dannycoates/node-inspector">node-inspector</a>, which allows you to debug
code with <tt>debugger</tt> statements like you would in the browser.
</p>
<p id="faq-tests">
<b class="header">How do I run the test suite?</b><br />
If you pass <tt>{debug: true}</tt> as one of the options in your initialize settings, you can see
all of the query calls being made. Sometimes you need to dive a bit further into
the various calls and see what all is going on behind the scenes. I'd recommend
<a href="https://github.com/dannycoates/node-inspector">node-inspector</a>, which allows you to debug
code with <tt>debugger</tt> statements like you would in the browser.
</p>
<p id="faq-nonode">
<b class="header">Can I use Knex outside of Node.js</b><br />
While there isn't a client adapter yet, it should be possible to run
it could be adapted to work with other javascript environments supporting a <tt>sqlite3</tt>
database, by providing a custom <a href="http://knexjs.org/#Adapters">Knex adapter</a>.
</p>
<h2 id="changelog">Change Log</h2>
<p>

21
knex.js
View File

@ -31,15 +31,19 @@
_debug: false,
debug: function(val) {
this._debug = val;
_promise: null,
debug: function() {
this._debug = true;
return this;
},
// For those who dislike promise interfaces.
// Multiple calls to `exec` will resolve with the same value
// if called more than once.
exec: function(callback) {
var run = this.runQuery();
return run.then(function(resp) {
this._promise || (this._promise = this.runQuery());
return this._promise.then(function(resp) {
callback(null, resp);
}, function(err) {
callback(err, null);
@ -48,8 +52,8 @@
// The promise interface for the query builder.
then: function(onFulfilled, onRejected) {
var run = this.runQuery();
return run.then(onFulfilled, onRejected);
this._promise || (this._promise = this.runQuery());
return this._promise.then(onFulfilled, onRejected);
},
// Specifies to resolve the statement with the `data` rather
@ -137,8 +141,6 @@
Knex.Grammar = {
dateFormat: 'Y-m-d H:i:s',
// Compiles the `select` statement, or nested sub-selects
// by calling each of the component compilers, trimming out
// the empties, and returning a generated query string.
@ -525,13 +527,12 @@
// The most basic is `where(key, value)`, which expands to
// where key = value.
where: function(column, operator, value, bool) {
var key;
bool || (bool = 'and');
if (_.isFunction(column)) {
return this._whereNested(column, bool);
}
if (_.isObject(column)) {
for (key in column) {
for (var key in column) {
value = column[key];
this[bool + 'Where'](key, '=', value);
}

View File

@ -14,7 +14,7 @@
"sqlite3": "~2.1.7"
},
"dependencies": {
"when": ">=2.0.1",
"when": ">=2.1.0",
"underscore": "~1.4.4",
"generic-pool": "~2.0.3"
},