Skip to content

Commit 804f49d

Browse files
lukemurraydwelle
authored andcommitted
feat(757) support returning an array of results if multiResult: true passed in options.
1 parent 522d622 commit 804f49d

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

lib/query.js

+11-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ var Query = function(config, values, callback) {
1818

1919
config = utils.normalizeQueryConfig(config, values, callback);
2020

21+
this.multiResult = config.multiResult;
2122
this.text = config.text;
2223
this.values = config.values;
2324
this.rows = config.rows;
@@ -31,7 +32,10 @@ var Query = function(config, values, callback) {
3132
if(process.domain && config.callback) {
3233
this.callback = process.domain.bind(config.callback);
3334
}
34-
this._result = new Result(config.rowMode, config.types);
35+
this.rowMode = config.rowMode;
36+
// the active result in muti result mode
37+
this._result = new Result(this.rowMode);
38+
this._resultsArray = [];
3539
this.isPreparedStatement = false;
3640
this._canceledDueToError = false;
3741
this._promise = null;
@@ -95,6 +99,11 @@ Query.prototype.handleCommandComplete = function(msg, con) {
9599
if(this.isPreparedStatement) {
96100
con.sync();
97101
}
102+
// new result for next query
103+
if(this.multiResult) {
104+
this._resultsArray.push(this._result);
105+
this._result = new Result(this.rowMode);
106+
}
98107
};
99108

100109
//if a named prepared statement is created with empty query text
@@ -111,7 +120,7 @@ Query.prototype.handleReadyForQuery = function() {
111120
return this.handleError(this._canceledDueToError);
112121
}
113122
if(this.callback) {
114-
this.callback(null, this._result);
123+
this.callback(null, this.multiResult ? this._resultsArray : this._result);
115124
}
116125
this.emit('end', this._result);
117126
};

0 commit comments

Comments
 (0)