Skip to content

Commit

Permalink
(pouchdb#527) - Include total_rows in view queries.
Browse files Browse the repository at this point in the history
  • Loading branch information
nick-thompson authored and daleharvey committed Apr 1, 2013
1 parent 0e19c76 commit 175c1d9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/plugins/pouchdb.mapreduce.js
Expand Up @@ -82,7 +82,10 @@ var MapReduce = function(db) {
results.reverse();
}
if (options.reduce === false) {
return options.complete(null, {rows: results});
return options.complete(null, {
rows: results,
total_rows: results.length
});
}

var groups = [];
Expand All @@ -99,7 +102,7 @@ var MapReduce = function(db) {
e.value = fun.reduce(e.key, e.value) || null;
e.key = e.key[0][0];
});
options.complete(null, {rows: groups});
options.complete(null, {rows: groups, total_rows: groups.length});
}
}

Expand Down
1 change: 1 addition & 0 deletions tests/test.views.js
Expand Up @@ -42,6 +42,7 @@ adapters.map(function(adapter) {
db.remove(doc, function(_, resp) {
db.query(queryFun, {include_docs: true, reduce: false}, function(_, res) {
equal(res.rows.length, 1, 'Dont include deleted documents');
equal(res.total_rows, 1, 'Include total_rows property.');
res.rows.forEach(function(x, i) {
ok(x.id, 'emitted row has id');
ok(x.key, 'emitted row has key');
Expand Down

0 comments on commit 175c1d9

Please sign in to comment.