Skip to content

Commit 916d206

Browse files
committed
Allow passing extant Query object to Client.query
This only adds this behaviour for the pure-js driver
1 parent 8b9e97f commit 916d206

File tree

2 files changed

+21
-10
lines changed

2 files changed

+21
-10
lines changed

lib/client.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,12 @@ p.query = function(config, values, callback) {
201201

202202
config.callback = callback;
203203

204-
var query = new Query(config);
204+
if(config.query_object) {
205+
config.query_object._init(config)
206+
var query = config.query_object;
207+
} else {
208+
var query = new Query(config);
209+
}
205210
this.queryQueue.push(query);
206211
this._pulseQueryQueue();
207212
return query;

lib/query.js

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,9 @@ var Types = require(__dirname + '/types');
66
var utils = require(__dirname + '/utils');
77

88
var Query = function(config) {
9-
this.text = config.text;
10-
this.values = config.values;
11-
this.rows = config.rows;
12-
this.types = config.types;
13-
this.name = config.name;
14-
this.binary = config.binary;
15-
//use unique portal name each time
16-
this.portal = config.portal || ""
17-
this.callback = config.callback;
9+
if(config) {
10+
this._init(config);
11+
}
1812
this._fieldNames = [];
1913
this._fieldConverters = [];
2014
this._result = new Result();
@@ -25,6 +19,18 @@ var Query = function(config) {
2519
util.inherits(Query, EventEmitter);
2620
var p = Query.prototype;
2721

22+
p._init = function (config) {
23+
this.text = config.text;
24+
this.values = config.values;
25+
this.rows = config.rows;
26+
this.types = config.types;
27+
this.name = config.name;
28+
this.binary = config.binary;
29+
//use unique portal name each time
30+
this.portal = config.portal || ""
31+
this.callback = config.callback;
32+
}
33+
2834
p.requiresPreparation = function() {
2935
return (this.values || 0).length > 0 || this.name || this.rows || this.binary;
3036
};

0 commit comments

Comments
 (0)