Commit cefca6fe authored by Tristan Cavelier's avatar Tristan Cavelier

add limit option management

parent e6a50e62
......@@ -384,10 +384,33 @@
index_req = index.openCursor();
date = Date.now();
index_req.onsuccess = function () {
var cursor = index_req.result, now;
index_req.onsuccess = function (event) {
var cursor = event.target.result, now;
if (cursor) {
// Called for each matching record.
if (Array.isArray(option.limit)) {
if (option.limit.length > 1) {
if (option.limit[0] > 0) {
option.limit[0] -= 1;
cursor.continue();
return;
}
if (option.limit[1] <= 0) {
// end
index_req.onsuccess({"target": {}});
return;
}
option.limit[1] -= 1;
} else {
if (option.limit[0] <= 0) {
// end
index_req.onsuccess({"target": {}});
return;
}
option.limit[0] -= 1;
}
}
if (option.include_docs) {
rows.push({
"id": cursor.value._id,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment