summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--THANKS1
-rw-r--r--share/www/script/couch.js14
-rw-r--r--share/www/script/couch_tests.js91
-rw-r--r--src/couchdb/couch_httpd_view.erl11
4 files changed, 94 insertions, 23 deletions
diff --git a/THANKS b/THANKS
index 2b8b5011..4a3b66f3 100644
--- a/THANKS
+++ b/THANKS
@@ -8,6 +8,7 @@ Some of these people are:
* Mark Baran <mebaran@gmail.com>
* William Beh <willbeh@gmail.com>
+ * Antony Blakey <antony.blakey@gmail.com>
* Yoan Blanc <yoan.blanc@gmail.com>
* Benoit Chesneau <bchesneau@gmail.com>
* Paul Joseph Davis <paul.joseph.davis@gmail.com>
diff --git a/share/www/script/couch.js b/share/www/script/couch.js
index cc50ad2e..cae0abc9 100644
--- a/share/www/script/couch.js
+++ b/share/www/script/couch.js
@@ -162,6 +162,20 @@ function CouchDB(name, options) {
return JSON.parse(req.responseText);
}
+ this.allDocsBySeq = function(options,keys) {
+ var req = null;
+ if(!keys) {
+ req = request("GET", this.uri + "_all_docs_by_seq" + encodeOptions(options));
+ } else {
+ req = request("POST", this.uri + "_all_docs_by_seq" + encodeOptions(options), {
+ headers: {"Content-Type": "application/json"},
+ body: JSON.stringify({keys:keys})
+ });
+ }
+ maybeThrowError(req);
+ return JSON.parse(req.responseText);
+ }
+
this.compact = function() {
var req = request("POST", this.uri + "_compact");
maybeThrowError(req);
diff --git a/share/www/script/couch_tests.js b/share/www/script/couch_tests.js
index bc1e83da..8575da6f 100644
--- a/share/www/script/couch_tests.js
+++ b/share/www/script/couch_tests.js
@@ -67,24 +67,6 @@ var tests = {
// Check the database doc count
T(db.info().doc_count == 4);
- // Check the all docs
- var results = db.allDocs();
- var rows = results.rows;
-
- T(results.total_rows == results.rows.length);
-
- for(var i=0; i < rows.length; i++) {
- T(rows[i].id >= "0" && rows[i].id <= "4");
- }
-
- // Check _all_docs with descending=true
- var desc = db.allDocs({descending:true});
- T(desc.total_rows == desc.rows.length);
-
- // Check _all_docs offset
- var all = db.allDocs({startkey:"2"});
- T(all.offset == 2);
-
// Test a simple map functions
// create a map function that selects all documents whose "a" member
@@ -150,7 +132,80 @@ var tests = {
// make sure restart works
T(restartServer().ok);
},
+ all_docs: function(debug) {
+ var db = new CouchDB("test_suite_db");
+ db.deleteDb();
+ db.createDb();
+ if (debug) debugger;
+
+ // Create some more documents.
+ // Notice the use of the ok member on the return result.
+ T(db.save({_id:"0",a:1,b:1}).ok);
+ T(db.save({_id:"3",a:4,b:16}).ok);
+ T(db.save({_id:"1",a:2,b:4}).ok);
+ T(db.save({_id:"2",a:3,b:9}).ok);
+ // Check the all docs
+ var results = db.allDocs();
+ var rows = results.rows;
+
+ T(results.total_rows == results.rows.length);
+
+ for(var i=0; i < rows.length; i++) {
+ T(rows[i].id >= "0" && rows[i].id <= "4");
+ }
+
+ // Check _all_docs with descending=true
+ var desc = db.allDocs({descending:true});
+ T(desc.total_rows == desc.rows.length);
+
+ // Check _all_docs offset
+ var all = db.allDocs({startkey:"2"});
+ T(all.offset == 2);
+
+ // check that the docs show up in the seq view in the order they were created
+ var all_seq = db.allDocsBySeq();
+ var ids = ["0","3","1","2"];
+ for (var i=0; i < all_seq.rows.length; i++) {
+ var row = all_seq.rows[i];
+ T(row.id == ids[i]);
+ };
+
+ // check that deletions also show up right
+ var doc1 = db.open("1");
+ var deleted = db.deleteDoc(doc1);
+ T(deleted.ok);
+ all_seq = db.allDocsBySeq();
+
+ // the deletion should make doc id 1 have the last seq num
+ T(all_seq.rows.length == 4);
+ T(all_seq.rows[3].id == "1");
+ T(all_seq.rows[3].value.deleted);
+
+ // is this a bug?
+ // T(all_seq.rows.length == all_seq.total_rows);
+
+ // do an update
+ var doc2 = db.open("3");
+ doc2.updated = "totally";
+ db.save(doc2);
+ all_seq = db.allDocsBySeq();
+
+ // the update should make doc id 3 have the last seq num
+ T(all_seq.rows.length == 4);
+ T(all_seq.rows[3].id == "3");
+
+ // ok now lets see what happens with include docs
+ all_seq = db.allDocsBySeq({include_docs: true});
+ T(all_seq.rows.length == 4);
+ T(all_seq.rows[3].id == "3");
+ T(all_seq.rows[3].doc.updated == "totally");
+
+ // and on the deleted one, no doc
+ T(all_seq.rows[2].value.deleted);
+ T(!all_seq.rows[2].doc);
+ },
+
// Do some edit conflict detection tests
conflicts: function(debug) {
var db = new CouchDB("test_suite_db");
diff --git a/src/couchdb/couch_httpd_view.erl b/src/couchdb/couch_httpd_view.erl
index c3ac07e3..5b19af5d 100644
--- a/src/couchdb/couch_httpd_view.erl
+++ b/src/couchdb/couch_httpd_view.erl
@@ -426,12 +426,13 @@ view_row_obj(Db, {{Key, DocId}, Value}, IncludeDocs) ->
[]
end,
?LOG_DEBUG("Include Doc: ~p ~p", [DocId, Rev]),
- case (catch couch_httpd_db:couch_doc_open(Db, DocId,
- Rev, [])) of
- {{not_found, missing}, _} ->
+ case (catch couch_httpd_db:couch_doc_open(Db, DocId, Rev, [])) of
+ {{not_found, missing}, _} ->
{[{id, DocId}, {key, Key}, {value, Value}, {error, missing}]};
- Doc ->
- JsonDoc = couch_doc:to_json_obj(Doc, []),
+ {not_found, deleted} ->
+ {[{id, DocId}, {key, Key}, {value, Value}]};
+ Doc ->
+ JsonDoc = couch_doc:to_json_obj(Doc, []),
{[{id, DocId}, {key, Key}, {value, Value}, {doc, JsonDoc}]}
end;
_ ->