diff options
author | John Christopher Anderson <jchris@apache.org> | 2008-11-14 03:47:21 +0000 |
---|---|---|
committer | John Christopher Anderson <jchris@apache.org> | 2008-11-14 03:47:21 +0000 |
commit | d32d8acff4bac6f51b87ddef7091c04ff7245d40 (patch) | |
tree | ab7cb32ee8e54c971d8eb28dc6881fad18aae678 | |
parent | 41e60ecc969649e9c1deee5d293f2451e8238ac6 (diff) |
fix for _all_docs_by_seq with include_docs
git-svn-id: https://svn.apache.org/repos/asf/incubator/couchdb/trunk@713914 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | THANKS | 1 | ||||
-rw-r--r-- | share/www/script/couch.js | 14 | ||||
-rw-r--r-- | share/www/script/couch_tests.js | 91 | ||||
-rw-r--r-- | src/couchdb/couch_httpd_view.erl | 11 |
4 files changed, 94 insertions, 23 deletions
@@ -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; _ -> |