Skip to content

Commit

Permalink
commit branch for design doc resource. this is ready for merge to trunk.
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.apache.org/repos/asf/couchdb/branches/design_resources@751791 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
jchris committed Mar 9, 2009
1 parent 94766f9 commit 0bd9e53
Show file tree
Hide file tree
Showing 11 changed files with 148 additions and 118 deletions.
9 changes: 6 additions & 3 deletions etc/couchdb/default.ini.tpl.in
Expand Up @@ -52,13 +52,16 @@ _restart = {couch_httpd_misc_handlers, handle_restart_req}
_stats = {couch_httpd_stats_handlers, handle_stats_req}

[httpd_db_handlers]
_view = {couch_httpd_view, handle_view_req}
_design = {couch_httpd_db, handle_design_req}
_temp_view = {couch_httpd_view, handle_temp_view_req}
_show = {couch_httpd_show, handle_doc_show_req}
_list = {couch_httpd_show, handle_view_list_req}

; The external module takes an optional argument allowing you to narrow it to a
; single script. Otherwise the script name is inferred from the first path section
; after _external's own path.
; _mypath = {couch_httpd_external, handle_external_req, <<"mykey">>}
; _external = {couch_httpd_external, handle_external_req}

[httpd_design_handlers]
_view = {couch_httpd_view, handle_view_req}
_show = {couch_httpd_show, handle_doc_show_req}
_list = {couch_httpd_show, handle_view_list_req}
9 changes: 5 additions & 4 deletions share/www/script/couch.js
Expand Up @@ -142,12 +142,13 @@ function CouchDB(name, httpHeaders) {
}

this.view = function(viewname, options, keys) {
var viewParts = viewname.split('/');
var viewPath = this.uri + "_design/" + viewParts[0] + "/_view/"
+ viewParts[1] + encodeOptions(options);
if(!keys) {
this.last_req = this.request("GET", this.uri + "_view/" +
viewname + encodeOptions(options));
this.last_req = this.request("GET", viewPath);
} else {
this.last_req = this.request("POST", this.uri + "_view/" +
viewname + encodeOptions(options), {
this.last_req = this.request("POST", viewPath, {
headers: {"Content-Type": "application/json"},
body: JSON.stringify({keys:keys})
});
Expand Down
7 changes: 4 additions & 3 deletions share/www/script/jquery.couch.js
Expand Up @@ -191,9 +191,9 @@
appName = appName.join('/');
index = ddoc.couchapp && ddoc.couchapp.index;
if (index) {
appPath = ['', name, index[0], appName, index[1]].join('/');
appPath = ['', name, ddoc._id, index].join('/');
} else if (ddoc._attachments && ddoc._attachments["index.html"]) {
appPath = ['', name, '_design', appName, "index.html"].join('/');
appPath = ['', name, ddoc._id, "index.html"].join('/');
}
if (appPath) options.eachApp(appName, appPath, ddoc);
}
Expand Down Expand Up @@ -298,8 +298,9 @@
},
view: function(name, options) {
options = options || {};
name = name.split('/');
$.ajax({
type: "GET", url: this.uri + "_view/" + name + encodeOptions(options),
type: "GET", url: this.uri + "_design/" + name[0] + "/_view/" + name[1] + encodeOptions(options),
dataType: "json",
complete: function(req) {
var resp = $.httpData(req, "json");
Expand Down
8 changes: 4 additions & 4 deletions share/www/script/test/etags_views.js
Expand Up @@ -46,20 +46,20 @@ couchTests.etags_views = function(debug) {
T(saveResult.ok);

// verify get w/Etag on map view
xhr = CouchDB.request("GET", "/test_suite_db/_view/etags/basicView");
xhr = CouchDB.request("GET", "/test_suite_db/_design/etags/_view/basicView");
T(xhr.status == 200);
var etag = xhr.getResponseHeader("etag");
xhr = CouchDB.request("GET", "/test_suite_db/_view/etags/basicView", {
xhr = CouchDB.request("GET", "/test_suite_db/_design/etags/_view/basicView", {
headers: {"if-none-match": etag}
});
T(xhr.status == 304);
// TODO GET with keys (when that is available)

// reduce view
xhr = CouchDB.request("GET", "/test_suite_db/_view/etags/withReduce");
xhr = CouchDB.request("GET", "/test_suite_db/_design/etags/_view/withReduce");
T(xhr.status == 200);
var etag = xhr.getResponseHeader("etag");
xhr = CouchDB.request("GET", "/test_suite_db/_view/etags/withReduce", {
xhr = CouchDB.request("GET", "/test_suite_db/_design/etags/_view/withReduce", {
headers: {"if-none-match": etag}
});
T(xhr.status == 304);
Expand Down
67 changes: 29 additions & 38 deletions share/www/script/test/list_views.js
Expand Up @@ -144,8 +144,8 @@ couchTests.list_views = function(debug) {
T(view.total_rows == 10);

// standard get
var xhr = CouchDB.request("GET", "/test_suite_db/_list/lists/simpleForm/basicView");
T(xhr.status == 200);
var xhr = CouchDB.request("GET", "/test_suite_db/_design/lists/_list/simpleForm/basicView");
T(xhr.status == 200, "standard get should be 200");
T(/Total Rows/.test(xhr.responseText));
T(/Key: 1/.test(xhr.responseText));
T(/LineNo: 0/.test(xhr.responseText));
Expand All @@ -159,48 +159,48 @@ couchTests.list_views = function(debug) {

// test that etags are available
var etag = xhr.getResponseHeader("etag");
xhr = CouchDB.request("GET", "/test_suite_db/_list/lists/simpleForm/basicView", {
xhr = CouchDB.request("GET", "/test_suite_db/_design/lists/_list/simpleForm/basicView", {
headers: {"if-none-match": etag}
});
T(xhr.status == 304);

// get with query params
var xhr = CouchDB.request("GET", "/test_suite_db/_list/lists/simpleForm/basicView?startkey=3");
T(xhr.status == 200);
var xhr = CouchDB.request("GET", "/test_suite_db/_design/lists/_list/simpleForm/basicView?startkey=3");
T(xhr.status == 200, "with query params");
T(/Total Rows/.test(xhr.responseText));
T(!(/Key: 1/.test(xhr.responseText)));
T(/FirstKey: 3/.test(xhr.responseText));
T(/LastKey: 9/.test(xhr.responseText));


// with 0 rows
var xhr = CouchDB.request("GET", "/test_suite_db/_list/lists/simpleForm/basicView?startkey=30");
T(xhr.status == 200);
var xhr = CouchDB.request("GET", "/test_suite_db/_design/lists/_list/simpleForm/basicView?startkey=30");
T(xhr.status == 200, "0 rows");
T(/Total Rows/.test(xhr.responseText));
T(/Offset: null/.test(xhr.responseText));

// reduce with 0 rows
var xhr = CouchDB.request("GET", "/test_suite_db/_list/lists/simpleForm/withReduce?startkey=30");
T(xhr.status == 200);
var xhr = CouchDB.request("GET", "/test_suite_db/_design/lists/_list/simpleForm/withReduce?startkey=30");
T(xhr.status == 200, "reduce 0 rows");
T(/Total Rows/.test(xhr.responseText));
T(/Offset: undefined/.test(xhr.responseText));


// when there is a reduce present, but not used
var xhr = CouchDB.request("GET", "/test_suite_db/_list/lists/simpleForm/withReduce?reduce=false");
T(xhr.status == 200);
var xhr = CouchDB.request("GET", "/test_suite_db/_design/lists/_list/simpleForm/withReduce?reduce=false");
T(xhr.status == 200, "reduce false");
T(/Total Rows/.test(xhr.responseText));
T(/Key: 1/.test(xhr.responseText));

// when there is a reduce present, and used
xhr = CouchDB.request("GET", "/test_suite_db/_list/lists/simpleForm/withReduce?group=true");
T(xhr.status == 200);
xhr = CouchDB.request("GET", "/test_suite_db/_design/lists/_list/simpleForm/withReduce?group=true");
T(xhr.status == 200, "group reduce");
T(/Key: 1/.test(xhr.responseText));

// there should be etags on reduce as well
var etag = xhr.getResponseHeader("etag");
T(etag, "Etags should be served with reduce lists");
xhr = CouchDB.request("GET", "/test_suite_db/_list/lists/simpleForm/withReduce?group=true", {
xhr = CouchDB.request("GET", "/test_suite_db/_design/lists/_list/simpleForm/withReduce?group=true", {
headers: {"if-none-match": etag}
});
T(xhr.status == 304);
Expand All @@ -210,13 +210,13 @@ couchTests.list_views = function(debug) {
var saveResult = db.bulkSave(docs);
T(saveResult.ok);

xhr = CouchDB.request("GET", "/test_suite_db/_list/lists/simpleForm/withReduce?group=true", {
xhr = CouchDB.request("GET", "/test_suite_db/_design/lists/_list/simpleForm/withReduce?group=true", {
headers: {"if-none-match": etag}
});
T(xhr.status == 200);
T(xhr.status == 200, "reduce etag");

// with accept headers for HTML
xhr = CouchDB.request("GET", "/test_suite_db/_list/lists/acceptSwitch/basicView", {
xhr = CouchDB.request("GET", "/test_suite_db/_design/lists/_list/acceptSwitch/basicView", {
headers: {
"Accept": 'text/html'
}
Expand All @@ -226,7 +226,7 @@ couchTests.list_views = function(debug) {
T(xhr.responseText.match(/Value/));

// now with xml
xhr = CouchDB.request("GET", "/test_suite_db/_list/lists/acceptSwitch/basicView", {
xhr = CouchDB.request("GET", "/test_suite_db/_design/lists/_list/acceptSwitch/basicView", {
headers: {
"Accept": 'application/xml'
}
Expand All @@ -236,49 +236,40 @@ couchTests.list_views = function(debug) {
T(xhr.responseText.match(/entry/));

// now with extra qs params
var xhr = CouchDB.request("GET", "/test_suite_db/_list/lists/qsParams/basicView?foo=blam");
var xhr = CouchDB.request("GET", "/test_suite_db/_design/lists/_list/qsParams/basicView?foo=blam");
T(xhr.responseText.match(/blam/));

// aborting iteration
var xhr = CouchDB.request("GET", "/test_suite_db/_list/lists/stopIter/basicView");
var xhr = CouchDB.request("GET", "/test_suite_db/_design/lists/_list/stopIter/basicView");
T(xhr.responseText.match(/^head 0 1 2 tail$/));
xhr = CouchDB.request("GET", "/test_suite_db/_list/lists/stopIter2/basicView");
xhr = CouchDB.request("GET", "/test_suite_db/_design/lists/_list/stopIter2/basicView");
T(xhr.responseText.match(/^head 0 1 2 tail$/));

// aborting iteration with reduce
var xhr = CouchDB.request("GET", "/test_suite_db/_list/lists/stopIter/withReduce?group=true");
var xhr = CouchDB.request("GET", "/test_suite_db/_design/lists/_list/stopIter/withReduce?group=true");
T(xhr.responseText.match(/^head 0 1 2 tail$/));
xhr = CouchDB.request("GET", "/test_suite_db/_list/lists/stopIter2/withReduce?group=true");
xhr = CouchDB.request("GET", "/test_suite_db/_design/lists/_list/stopIter2/withReduce?group=true");
T(xhr.responseText.match(/^head 0 1 2 tail$/));

// empty list
var xhr = CouchDB.request("GET", "/test_suite_db/_list/lists/emptyList/basicView");
var xhr = CouchDB.request("GET", "/test_suite_db/_design/lists/_list/emptyList/basicView");
T(xhr.responseText.match(/^$/));
xhr = CouchDB.request("GET", "/test_suite_db/_list/lists/emptyList/withReduce?group=true");
xhr = CouchDB.request("GET", "/test_suite_db/_design/lists/_list/emptyList/withReduce?group=true");
T(xhr.responseText.match(/^$/));

// multi-key fetch
var xhr = CouchDB.request("POST", "/test_suite_db/_list/lists/simpleForm/basicView", {
var xhr = CouchDB.request("POST", "/test_suite_db/_design/lists/_list/simpleForm/basicView", {
body: '{"keys":[2,4,5,7]}'
});
T(xhr.status == 200);
T(xhr.status == 200, "multi key");
T(/Total Rows/.test(xhr.responseText));
T(!(/Key: 1/.test(xhr.responseText)));
T(/Key: 2/.test(xhr.responseText));
T(/FirstKey: 2/.test(xhr.responseText));
T(/LastKey: 7/.test(xhr.responseText));
xhr = CouchDB.request("POST", "/test_suite_db/_list/lists/simpleForm/withReduce?group=true", {
body: '{"keys":[2,4,5,7]}'
});
T(xhr.status == 200);
T(/Total Rows/.test(xhr.responseText));
T(!(/Key: 1/.test(xhr.responseText)));
T(/Key: 2/.test(xhr.responseText));
T(/FirstKey: 2/.test(xhr.responseText));
T(/LastKey: 7/.test(xhr.responseText));


// no multi-key fetch allowed when group=false
xhr = CouchDB.request("POST", "/test_suite_db/_list/lists/simpleForm/withReduce?group=false", {
xhr = CouchDB.request("POST", "/test_suite_db/_design/lists/_list/simpleForm/withReduce?group=false", {
body: '{"keys":[2,4,5,7]}'
});
T(xhr.status == 400);
Expand Down

0 comments on commit 0bd9e53

Please sign in to comment.