Package: wallaby-backend-couchdb
Wallaby backend for CouchDB===========================This package provides an asynchronous python interface to CouchDB (using twisted).For more information on wallaby visit http://wlby.freshx.deInstallation============You can install the couchdb backend with pip```bashpip install wallaby-backend-couchdb```How to use==========The library is based on twisted's asynchronous pattern. To use the library in an asynchronous fassion youfirst need to create an reactor based application:```pythonfrom twisted.internet import defer@defer.inlineCallbacksdef run():# wait 1 secondd = defer.Deferred()reactor.callLater(1.0, d.callback)yield d# stop the reactor and quit the applicationreactor.stop()from twisted.internet import reactorreactor.callWhenRunning(run)reactor.run()```Now we can connect to an existing CouchDB database:```python@defer.inlineCallbacksdef run():# Create database client objectfrom wallaby.backends.couchdb import Databasedb = Database("<name of database>",username="<username>",password="<password>",url="http://localhost:5984")# Query database info in an async mannerinfo = yield db.info()# Output the info dictprint info# <----- More example Code paste here# stop the reactor and quit the applicationreactor.stop()```Create and delete database--------------------------With the required permissions you could easily create and destroy databases```pythonnewdb = Database("<name of new database>",username="<username>",password="<password>",url="http://localhost:5984")# Create the new databaseres = yield newdb.create()# Destroy the new databaseres = yield newdb.destroy()```Read and write document-----------------------```python# Get a document by iddoc = yield db.get('docid')# add a new value to the documentdoc['test'] = 'Hello World'# save the documentres = yield db.save(doc)```Creating and deleting documents-------------------------------```python# Create a new docdoc = {'_id': 'newdocid'}res = yield db.save(doc)# the result contains the response from the CouchDB serverif not 'error' in res:# the document was saved successfully. The new revision was updated in the "_rev" field of doc.print doc['_rev']# delete the documentres = yield db.delete(doc)```Attachment handling-------------------```python# First we a load a file to attach. In real life you should do this in an async mannercontent = open('test.png').read()# Now we can attach this file to an existing documentres = yield db.put_attachment(doc, 'newimage.png', content, content-type='image/png')# And load from database againcontent = yield db.get_attachment(doc, 'newimage.png')# and finally delete itres = yield db.delete_attachment(doc, 'newimage.png')```Views-----```python# get all rows of viewrows = yield db.view('_design/designname/_view/viewname')# pass view argumentsrows = yield db.view('_design/designname/_view/viewname', count=100)```Changes-------```pythondef callback(changes, viewID=None):# all changes are passed to this callback as an array. the viewID help to identify# view-based changespass# register callback function for filtered changesdb.changes(cb=callback, since=12345, filter="couchappdoc/all")# register callback function for view changes (only works in CouchDB 1.2)db.changes(cb=callback, since=12345, filter="_view", view="couchappdoc/viewname")# unregister first callbackdb.unchanges(since=12345, filter="couchappdoc/all")# unregister second callbackdb.changes(since=12345, filter="_view", view="couchappdoc/viewname")```