Storing design documents and views on the filesystem
Couchdbkit allows you to manage you design docs and docs on the file system.
A system will be provided to manage view creation and other things. As some noticed, this system works like couchapp.
Create a design document
Let’s create a folder that contains the design doc, and then the folder for the view. On unix :
mkdir -p ~/Work/couchdbkit/example/_design/greeting/views/all
In this folder we edit a file `map.js`:
function(doc) { if (doc.doc_type == “Greeting”) emit(doc._id, doc); }
Synchronize design documents on the database
Then we use `FileSystemDocsLoader` object to send the design document to CouchDB:
from couchdbkit.loaders import FileSystemDocsLoader loader = FileSystemDocsLoader(’/path/to/example/_design’) loader.sync(db, verbose=True)
The design doc is now in the `greetings` database and you can get all greets :
greets = Greeting.view('greeting/all’)
You can automate this when you start your application. This what Friendpaste do by running python manage.py setup
on first bootstrap.