Skip to content

Commit

Permalink
fix: multi-statement output
Browse files Browse the repository at this point in the history
  • Loading branch information
dvictorjhg authored and CarlosCarmona committed Jul 13, 2022
1 parent f05a3eb commit ff9a522
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,26 @@ class postgresExecutor extends Executor {
async executeQuery(client, query) {
try {
const results = await client.query(query);
this.prepareEndOptions(results.rows[0], results.rowCount, results.rows);
var rows = [];
var rowCount = 0;
if (Array.isArray(results)) {
results.forEach(result => {
if (result.rows.length) {
rows.push(...result.rows);
} else {
rows.push(result);
}
rowCount += result.rowCount || 0;
})
} else {
if (results.rows.length) {
rows.push(...results.rows);
} else {
rows.push(results);
}
rowCount = results.rowCount;
}
this.prepareEndOptions(rows[0], rowCount, rows);
this._end(this.endOptions);
client.release();
} catch (err) {
Expand Down

0 comments on commit ff9a522

Please sign in to comment.