Use normalizeQueryConfig with native driver
This commit is contained in:
parent
5dae2b267f
commit
5a91dd0c35
@ -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;
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user