‘
I’ve been trying to understand couchapps and how to write them. The documentation is not entirely clear for someone like me who needs the big picture before getting into details.
So, we have an application, the couchapp, which is a single .json document called _design/[name]. That’s potentially quite a large document and writing it directly would be a chore. Enter couchapp helper applications (couchapp.org). These basically do one thing: they take all the various javascript, HTML and css files, build the _design/[name].json document and push it onto the couchdb.
I hadn’t quite got this at first. I was looking at existing couchapp document trees trying to find the _design/[name] file. The point is, there isn’t one, as such. Now, it can be confusing to think of the application on the couchdb as a couchapp and the applications that create the _design/[name] document as couchapps too!
Even worse, there are a few couchapp helper applications and they don’t talk to each other. Neither do they use the same directory structure of javascript, HTML and CSS files. I’m not sure whether it is possible to install more than one on a device at one time, since they all use the word couchapp to run a command.
There is a couchapp helper application written in python (couchapp.py). All of the Couchdb: Definitive Guide refers to that tool. The sofa application referred to in the book is one that has to be pushed to the couchdb using couchapp.py.
There is also a couchapp helper application written in javascript (node.couchapp.js). That is the one I’m using because it looks simpler, and I like simple.
The _design/[name] file structure is like this:
{ "_id" : "_design/myapp",
"_rev": "revision number created by couchdb"
"_attachments": { "images/logo.png": { "content_type": "image/png","revpos":1,
"digest":"md5-GDPL+eLwE7kzEDWY7X4KdQ==","length":886,"stub":true } },
"lists": { "xml": "function..." },
"rewrites": "function...",
"shows": { "preview": "function...", "xml": "function..." },
"updates": { "in-place": "function..." },
"views": { "foobar": { "map": "function...", "reduce": "function..." } },
"validate_doc_update": "function...", }
I think this is the same structure whichever couchapp helper application is used, but documentation isn’t a strong point of couchdb projects.
The file tree structure for couchapp.py and node.couchapp.js are quite different. I haven’t installed couchapp.py, so I’m not sure exactly what the boiler-plate framework looks like. For node.couchapp.js this is what you get:
myapp/
attachments/
app.js