summaryrefslogtreecommitdiff
path: root/share/server
diff options
context:
space:
mode:
authorJohn Christopher Anderson <jchris@apache.org>2009-08-11 18:50:08 +0000
committerJohn Christopher Anderson <jchris@apache.org>2009-08-11 18:50:08 +0000
commit36bbc72b6b0992639a0ba7a2077d75ec9f7cf03d (patch)
tree3e4e0d1e46a7fe04a9b185455a025e8ff5fa3e62 /share/server
parentea95901fe52df11338134bd86f9bc8f028c5444b (diff)
Initial commit of _update handler. Thanks to Paul Davis, Jason Davies for code and others for discussion.
The _update handler accepts POSTs to paths like: /db/_design/foo/_update/bar and PUTs which include docids, like: /db/_design/foo/_update/bar/docid The function signature: function(doc, req) { doc.a_new_field = req.query.something; return [doc, "<h1>added something to your doc</h1>"]; } The tests in update_documents.js are fairly complete and include examples of bumping a counter, changing only a single field, parsing from (and returning) XML, and creating new documents. git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@803245 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'share/server')
-rw-r--r--share/server/loop.js1
-rw-r--r--share/server/render.js20
2 files changed, 21 insertions, 0 deletions
diff --git a/share/server/loop.js b/share/server/loop.js
index 34354769..ff241eed 100644
--- a/share/server/loop.js
+++ b/share/server/loop.js
@@ -41,6 +41,7 @@ var dispatch = {
"rereduce" : Views.rereduce,
"validate" : Validate.validate,
"show" : Render.show,
+ "update" : Render.update,
"list" : Render.list,
"filter" : Filter.filter
};
diff --git a/share/server/render.js b/share/server/render.js
index 1a9fc5a5..82ceb3ab 100644
--- a/share/server/render.js
+++ b/share/server/render.js
@@ -166,11 +166,16 @@ function runProvides(req) {
////
////
////
+
var Render = {
show : function(funSrc, doc, req) {
var showFun = compileFunction(funSrc);
runShow(showFun, doc, req, funSrc);
},
+ update : function(funSrc, doc, req) {
+ var upFun = compileFunction(funSrc);
+ runUpdate(upFun, doc, req, funSrc);
+ },
list : function(head, req) {
runList(funs[0], head, req, funsrc[0]);
}
@@ -212,6 +217,21 @@ function runShow(showFun, doc, req, funSrc) {
}
};
+function runUpdate(renderFun, doc, req, funSrc) {
+ try {
+ var result = renderFun.apply(null, [doc, req]);
+ var doc = result[0];
+ var resp = result[1];
+ if (resp) {
+ respond(["up", doc, maybeWrapResponse(resp)]);
+ } else {
+ renderError("undefined response from update function");
+ }
+ } catch(e) {
+ respondError(e, funSrc, true);
+ }
+};
+
function resetList() {
gotRow = false;
lastRow = false;