File tree Expand file tree Collapse file tree 2 files changed +13
-28
lines changed Expand file tree Collapse file tree 2 files changed +13
-28
lines changed Original file line number Diff line number Diff line change @@ -50,10 +50,10 @@ p.connect = function(cb) {
50
50
}
51
51
52
52
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 ) ;
55
55
this . _pulseQueryQueue ( ) ;
56
- return q ;
56
+ return query ;
57
57
}
58
58
59
59
var nativeCancel = p . cancel ;
Original file line number Diff line number Diff line change @@ -6,34 +6,19 @@ var utils = require(__dirname + '/../utils');
6
6
var Result = require ( __dirname + '/../result' ) ;
7
7
8
8
//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
+
10
13
EventEmitter . call ( this ) ;
11
14
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 ;
16
21
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
- }
37
22
this . _result = new Result ( ) ;
38
23
//normalize values
39
24
if ( this . values ) {
You can’t perform that action at this time.
0 commit comments