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) {
5050}
5151
5252p . 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
5959var nativeCancel = p . cancel ;
Original file line number Diff line number Diff line change @@ -6,34 +6,19 @@ var utils = require(__dirname + '/../utils');
66var 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 ) {
You can’t perform that action at this time.
0 commit comments