Database class

Module to manage access to databases in couchdb.

class simplecouchdb.core.Database(server, dbname)

Object that abstract access to a CouchDB database A Database object could act as a Dict object.

Properties

server
Server instance. See Server class.
dbname
Str, name of database.

Methods

info()

Get infos of database

Returns:dict
doc_exist(docid)

Test if document exist in database

Parameters:
  • docid – str, document id
Returns:

boolean, True if document exist

get(docid, rev=None, wrapper=None)

Get document from database

Args: :param docid: str, document id to retrieve :param rev: if specified, allow you to retrieve a specifiec revision of document :param wrapper: callable. function that take a dict as param. Used to wrap an object.

Returns:dict, representation of CouchDB document as a dict.
revisions(docid, with_doc=True)

retrieve revisions of a doc

Parameters:
  • docid – str, id of document
  • with_doc – bool, if True return document

dict with revisions as member, if false return only revisions

Returns:dict: ‘_rev_infos’ member if you have set with_doc

to True :

{
    "_revs_info": [
        {"rev": "123456", "status": "disk"},
            {"rev": "234567", "status": "missing"},
            {"rev": "345678", "status": "deleted"},
    ]
}

If False, return current revision of the document, but with an additional field, _revs, the value being a list of the available revision IDs.

save(doc_or_docs)

Save one documents or multiple documents.

Parameters:
  • doc – dict or list/tuple of dict.
Returns:

dict or list of dict: dict or list are updated

with doc ‘_id’ and ‘_rev’ properties returned by CouchDB server.

delete(doc_or_docs)

delete a document or a list of document

Parameters:
  • doc_or_docs – list or str: doment id or list

of documents or list with _id and _rev, optionnaly _deleted member set to true. See _bulk_docs document on couchdb wiki.

Returns:list of doc or dict like:
{"ok":true,"rev":"2839830636"}
delete_attachment(doc, name)

delete attachement of documen

Parameters:
  • doc – dict, document object in python
  • name – name of attachement
Returns:

dict, withm member ok setto True if delete was ok.

__len__()
__contains__(docid)
__getitem__(id)
__setitem__(docid, doc)
__delitem__(docid)
__iter__()
__nonzero__()

See also

References Server class, Views classes

Previous topic

Server class

Next topic

Views classes

This Page

Quick search