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 "Actions" by PaulDavis
Date Wed, 17 Dec 2008 06:47:00 GMT
Dear Wiki user,

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

The following page has been changed by PaulDavis:
http://wiki.apache.org/couchdb/Actions

New page:
Actions are a default included functionality that is made available by the new ExternalProcess
feature. ''_design/'' docs can now specify an ''actions'' member that is an object of ''key''/''function''
pairs.

Action functions are specified in JavaScript and have access to a CouchDB object that can
make requests to the database.

== Example ''_design/'' Document ==

{{{
{
    "_id": "_design/an_action",
    "actions": {
        "times_two": "function(req, db) {return {code:200, json: {val: req.query.q * 2}};}"
    }
}
}}}

By default, this action is available at the URL:

{{{
http://127.0.0.1:5984/db_name/_external/action/times_two?q=2
}}}

== Example Using the Database ==

The ''db'' argument is a CouchDB instance. This class is defined in ''couch.js'' at:

{{{
http://127.0.0.1:5984/_utils/script/couch.js
}}}

For now the best references on the API are couch.js itself, and couch_tests.js that exercises
it and most of CouchDB.

{{{
{
    _id: "_design/with_db",
    actions: {
        "get" : "function(req, db) { var doc = db.open(req.query.docid); return {json:doc}
}",
    }
}
}}}

Accessed via:

{{{
http://127.0.0.1:5984/db_name/with_db/get?docid="_design/with_db"
}}}


== Caveats ==

The actions functionality is still a bit rough around the edges and there are efficiency questions
on the implementation. Also, the error reporting is sub-par (to say the least...).

That said, it helps serve as a reference (and testable) example of _external.

Mime
View raw message