File tree Expand file tree Collapse file tree 3 files changed +20
-16
lines changed Expand file tree Collapse file tree 3 files changed +20
-16
lines changed Original file line number Diff line number Diff line change @@ -185,23 +185,12 @@ p._pulseQueryQueue = function() {
185
185
} ;
186
186
187
187
p . query = function ( config , values , callback ) {
188
- //can take in strings or config objects
189
- config = ( typeof ( config ) == 'string' ) ? { text : config } : config ;
190
- if ( this . binary && ! ( ' binary' in config ) ) {
191
- config . binary = true ;
188
+ //can take in strings, config object or query object
189
+ var query = ( config instanceof Query ) ? config : new Query ( config , values , callback ) ;
190
+ if ( this . binary && ! query . binary ) {
191
+ query . binary = true ;
192
192
}
193
193
194
- if ( values ) {
195
- if ( typeof values === 'function' ) {
196
- callback = values ;
197
- } else {
198
- config . values = values ;
199
- }
200
- }
201
-
202
- config . callback = callback ;
203
-
204
- var query = new Query ( config ) ;
205
194
this . queryQueue . push ( query ) ;
206
195
this . _pulseQueryQueue ( ) ;
207
196
return query ;
Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ var PG = function(clientConstructor) {
13
13
EventEmitter . call ( this ) ;
14
14
this . Client = clientConstructor ;
15
15
this . Connection = require ( __dirname + '/connection' ) ;
16
+ this . Query = require ( __dirname + '/query' ) ;
16
17
this . defaults = defaults ;
17
18
} ;
18
19
Original file line number Diff line number Diff line change @@ -5,7 +5,21 @@ var Result = require(__dirname + '/result');
5
5
var Types = require ( __dirname + '/types' ) ;
6
6
var utils = require ( __dirname + '/utils' ) ;
7
7
8
- var Query = function ( config ) {
8
+ var Query = function ( config , values , callback ) {
9
+ // use of "new" optional
10
+ if ( ! ( this instanceof Query ) ) return new Query ( config , values , callback ) ;
11
+
12
+ //can take in strings or config objects
13
+ config = ( typeof ( config ) == 'string' ) ? { text : config } : config ;
14
+ if ( values ) {
15
+ if ( typeof values === 'function' ) {
16
+ callback = values ;
17
+ } else {
18
+ config . values = values ;
19
+ }
20
+ }
21
+ config . callback = callback ;
22
+
9
23
this . text = config . text ;
10
24
this . values = config . values ;
11
25
this . rows = config . rows ;
You can’t perform that action at this time.
0 commit comments