Skip to content

Commit 5a91dd0

Browse files
grncdrbrianc
authored andcommitted
Use normalizeQueryConfig with native driver
1 parent 5dae2b2 commit 5a91dd0

File tree

2 files changed

+13
-28
lines changed

2 files changed

+13
-28
lines changed

lib/native/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ p.connect = function(cb) {
5050
}
5151

5252
p.query = function(config, values, callback) {
53-
var q = new NativeQuery(config, values, callback);
54-
this._queryQueue.push(q);
53+
var query = (config instanceof NativeQuery) ? config : new NativeQuery(config, values, callback);
54+
this._queryQueue.push(query);
5555
this._pulseQueryQueue();
56-
return q;
56+
return query;
5757
}
5858

5959
var nativeCancel = p.cancel;

lib/native/query.js

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,34 +6,19 @@ var utils = require(__dirname + '/../utils');
66
var Result = require(__dirname + '/../result');
77

88
//event emitter proxy
9-
var NativeQuery = function(text, values, callback) {
9+
var NativeQuery = function(config, values, callback) {
10+
// use of "new" optional
11+
if (!(this instanceof NativeQuery)) return new NativeQuery(config, values, callback);
12+
1013
EventEmitter.call(this);
1114

12-
this.text = null;
13-
this.values = null;
14-
this.callback = null;
15-
this.name = null;
15+
config = utils.normalizeQueryConfig(config, values, callback);
16+
17+
this.name = config.name;
18+
this.text = config.text;
19+
this.values = config.values;
20+
this.callback = config.callback;
1621

17-
//allow 'config object' as first parameter
18-
if(typeof text == 'object') {
19-
this.text = text.text;
20-
this.values = text.values;
21-
this.name = text.name;
22-
if(typeof values === 'function') {
23-
this.callback = values;
24-
} else if(values) {
25-
this.values = values;
26-
this.callback = callback;
27-
}
28-
} else {
29-
this.text = text;
30-
this.values = values;
31-
this.callback = callback;
32-
if(typeof values == 'function') {
33-
this.values = null;
34-
this.callback = values;
35-
}
36-
}
3722
this._result = new Result();
3823
//normalize values
3924
if(this.values) {

0 commit comments

Comments
 (0)