couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Apache Wiki <wikidi...@apache.org>
Subject [Couchdb Wiki] Update of "Document_Update_Handlers" by gert
Date Tue, 20 Sep 2011 02:18:00 GMT
Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Couchdb Wiki" for change notification.

The "Document_Update_Handlers" page has been changed by gert:
http://wiki.apache.org/couchdb/Document_Update_Handlers?action=diff&rev1=18&rev2=19

Comment:
The functions should be double-quoted JSON strings

  {
    updates: {
  
-     "hello" : function(doc, req) {
+     "hello" : "function(doc, req) {
        if (!doc) {
          if (req.id) {
            return [{
@@ -33, +33 @@

        doc.world = "hello";
        doc.edited_by = req.userCtx;
        return [doc, "hello doc"];
-     },
+     }",
  
-     "in-place" : function(doc, req) {
+     "in-place" : "function(doc, req) {
        var field = req.form.field;
        var value = req.form.value;
        var message = "set "+field+" to "+value;
        doc[field] = value;
        return [doc, message];
-     },
+     }",
  
-     "bump-counter" : function(doc, req) {
+     "bump-counter" : "function(doc, req) {
        if (!doc.counter) doc.counter = 0;
        doc.counter += 1;
        var message = "<h1>bumped it!</h1>";
        return [doc, message];
-     },
+     }",
  
-     "error" : function(doc, req) {
+     "error" : "function(doc, req) {
        superFail.badCrash;
-     },
+     }",
  
-     "xml" : function(doc, req) {
+     "xml" : "function(doc, req) {
        var xml = new XML('<xml></xml>');
        xml.title = doc.title;
        var posted_xml = new XML(req.body);
@@ -67, +67 @@

        };
  
         return [doc, resp];
-      }
+      }"
    }
  }
  }}}
- NOTE: '''The functions should be double-quoted JSON strings'''.
  
  The handler function takes the most recent version of the document from the database and
the http request environment as parameters. It returns a two-element array: the first element
is the (updated or new) document, which is committed to the database. If the first element
is null no document will be committed to the database. If you are updating an existing, it
should already have an `_id` set, and if you are creating a new document, make sure to set
its `_id` to something, either generated based on the input or the `req.uuid` provided. The
second element is the response that will be sent back to the caller.
  

Mime
View raw message