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() {
185185} ;
186186
187187p . 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 ;
192192 }
193193
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 ) ;
205194 this . queryQueue . push ( query ) ;
206195 this . _pulseQueryQueue ( ) ;
207196 return query ;
Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ var PG = function(clientConstructor) {
1313 EventEmitter . call ( this ) ;
1414 this . Client = clientConstructor ;
1515 this . Connection = require ( __dirname + '/connection' ) ;
16+ this . Query = require ( __dirname + '/query' ) ;
1617 this . defaults = defaults ;
1718} ;
1819
Original file line number Diff line number Diff line change @@ -5,7 +5,21 @@ var Result = require(__dirname + '/result');
55var Types = require ( __dirname + '/types' ) ;
66var utils = require ( __dirname + '/utils' ) ;
77
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+
923 this . text = config . text ;
1024 this . values = config . values ;
1125 this . rows = config . rows ;
You can’t perform that action at this time.
0 commit comments