diff --git a/index.html b/index.html index 5ed7856ff..91cafaee6 100644 --- a/index.html +++ b/index.html @@ -219,6 +219,7 @@
+ increment.increment(column, value)
+
+ Increments a column's value by the specified amount.
+
+ truncate.truncate()
+
+ Truncates the current table.
+
+ debug.debug()
+
+ Turns on debugging for the current query chain.
+
@@ -868,10 +887,32 @@ Knex.createTable('accounts', function() {
- Once some questions show up, I'll put them here. +
+ How do I debug?
+ If you pass {debug: true} 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
+ node-inspector, which allows you to debug
+ code with debugger statements like you would in the browser.
+ How do I run the test suite?
+ If you pass {debug: true} 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
+ node-inspector, which allows you to debug
+ code with debugger statements like you would in the browser.
+
+ Can I use Knex outside of Node.js
+ 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 sqlite3
+ database, by providing a custom Knex adapter.
+
diff --git a/knex.js b/knex.js index c95b9ddaf..377ed73da 100644 --- a/knex.js +++ b/knex.js @@ -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); } diff --git a/package.json b/package.json index da276bd7a..86919a13e 100644 --- a/package.json +++ b/package.json @@ -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" },