Use normalizeQueryConfig with native driver

This commit is contained in:
Stephen Sugden 2012-12-10 22:34:55 -08:00 committed by bmc
parent 5dae2b267f
commit 5a91dd0c35
2 changed files with 13 additions and 28 deletions

View File

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

View File

@ -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) {