Commit cefca6fe authored by Tristan Cavelier's avatar Tristan Cavelier

add limit option management

parent e6a50e62
...@@ -384,10 +384,33 @@ ...@@ -384,10 +384,33 @@
index_req = index.openCursor(); index_req = index.openCursor();
date = Date.now(); date = Date.now();
index_req.onsuccess = function () { index_req.onsuccess = function (event) {
var cursor = index_req.result, now; var cursor = event.target.result, now;
if (cursor) { if (cursor) {
// Called for each matching record. // 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) { if (option.include_docs) {
rows.push({ rows.push({
"id": cursor.value._id, "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