Skip to content

Instantly share code, notes, and snippets.

@tnrn9b
Forked from Bigous/query-all.js
Created June 10, 2017 22:00
Show Gist options
  • Save tnrn9b/afc592a2f8dd40235c960432f503c780 to your computer and use it in GitHub Desktop.
Save tnrn9b/afc592a2f8dd40235c960432f503c780 to your computer and use it in GitHub Desktop.
"use strict";
exports.queryAll = function(conn, sql, args, cb) {
var allRows = [];
conn.execute(sql, args, {
resultSet: true
}, function(err, result) {
if (err) return cb(err);
function fetch() {
var max = 50;
result.resultSet.getRows(max, function(err, rows) {
if (err) return cb(err);
allRows.push(rows);
if (rows.length === max) {
fetch();
} else {
result.resultSet.close(function(err) {
if (err) return cb(err);
cb(null, Array.prototype.concat.apply([], allRows));
});
}
});
}
fetch();
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment