From 5a91dd0c355a4c6244275d873f202dcbad38fd3d Mon Sep 17 00:00:00 2001 From: Stephen Sugden Date: Mon, 10 Dec 2012 22:34:55 -0800 Subject: [PATCH] Use normalizeQueryConfig with native driver --- lib/native/index.js | 6 +++--- lib/native/query.js | 35 ++++++++++------------------------- 2 files changed, 13 insertions(+), 28 deletions(-) diff --git a/lib/native/index.js b/lib/native/index.js index 8522cd23..ae7fd0ad 100644 --- a/lib/native/index.js +++ b/lib/native/index.js @@ -50,10 +50,10 @@ p.connect = function(cb) { } p.query = function(config, values, callback) { - var q = new NativeQuery(config, values, callback); - this._queryQueue.push(q); + var query = (config instanceof NativeQuery) ? config : new NativeQuery(config, values, callback); + this._queryQueue.push(query); this._pulseQueryQueue(); - return q; + return query; } var nativeCancel = p.cancel; diff --git a/lib/native/query.js b/lib/native/query.js index fd31edf2..16827f9f 100644 --- a/lib/native/query.js +++ b/lib/native/query.js @@ -6,34 +6,19 @@ var utils = require(__dirname + '/../utils'); var Result = require(__dirname + '/../result'); //event emitter proxy -var NativeQuery = function(text, values, callback) { +var NativeQuery = function(config, values, callback) { + // use of "new" optional + if (!(this instanceof NativeQuery)) return new NativeQuery(config, values, callback); + EventEmitter.call(this); - this.text = null; - this.values = null; - this.callback = null; - this.name = null; + config = utils.normalizeQueryConfig(config, values, callback); + + this.name = config.name; + this.text = config.text; + this.values = config.values; + this.callback = config.callback; - //allow 'config object' as first parameter - if(typeof text == 'object') { - this.text = text.text; - this.values = text.values; - this.name = text.name; - if(typeof values === 'function') { - this.callback = values; - } else if(values) { - this.values = values; - this.callback = callback; - } - } else { - this.text = text; - this.values = values; - this.callback = callback; - if(typeof values == 'function') { - this.values = null; - this.callback = values; - } - } this._result = new Result(); //normalize values if(this.values) {