Package couchdbkit :: Package schema :: Module base :: Class DocumentBase
[hide private]
[frames] | no frames]

Class DocumentBase

source code

    object --+    
             |    
DocumentSchema --+
                 |
                DocumentBase
Known Subclasses:

Base Document object that map a CouchDB Document.
It allow you to statically map a document by
providing fields like you do with any ORM or
dynamically. Ie unknown fields are loaded as
object property that you can edit, datetime in
iso3339 format are automatically translated in
python types (date, time & datetime) and decimal too.

Example of documentass

.. code-block:: python

    from couchdbkit.schema import *
    class MyDocument(Document):
        mystring = StringProperty()
        myotherstring = unicode() # just use python types


Document fields can be accessed as property or
key of dict. These are similar : ``value = instance.key or value = instance['key'].``

To delete a property simply do ``del instance[key'] or delattr(instance, key)``

Nested Classes [hide private]

Inherited from DocumentSchema: __metaclass__

Instance Methods [hide private]
 
__init__(self, _d=None, **kwargs)
x.__init__(...) initializes x; see help(type(x)) for signature
source code
 
save(self, **params)
Save document in database.
source code
 
store(self, **params)
Save document in database.
source code
 
delete(self)
Delete document from the database.
source code

Inherited from DocumentSchema: __contains__, __delattr__, __delitem__, __getattr__, __getitem__, __getstate__, __iter__, __len__, __setattr__, __setitem__, all_properties, clone, dynamic_properties, items, iteritems, to_json, validate

Inherited from object: __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __sizeof__, __str__, __subclasshook__

Class Methods [hide private]
 
set_db(cls, db)
Set document db
source code
 
get_db(cls)
get document db
source code
 
save_docs(cls, docs, use_uuids=True, all_or_nothing=False)
Save multiple documents in database.
source code
 
bulk_save(cls, docs, use_uuids=True, all_or_nothing=False)
Save multiple documents in database.
source code
 
get(cls, docid, rev=None, db=None, dynamic_properties=True)
get document with `docid`
source code
 
get_or_create(cls, docid=None, db=None, dynamic_properties=True, **params)
get or create document with `docid`
source code

Inherited from DocumentSchema: build, from_json, properties, wrap

Class Variables [hide private]
  _db = None
hash(x)
  _doc_type = 'DocumentBase'
Properties [hide private]
  new_document

Inherited from object: __class__

Method Details [hide private]

__init__(self, _d=None, **kwargs)
(Constructor)

source code 

x.__init__(...) initializes x; see help(type(x)) for signature

Overrides: object.__init__
(inherited documentation)

save_docs(cls, docs, use_uuids=True, all_or_nothing=False)
Class Method

source code 

Save multiple documents in database.

Parameters:
  • use_uuids - add _id in doc who don't have it already set.
  • all_or_nothing - In the case of a power failure, when the database restarts either all the changes will have been saved or none of them. However, it does not do conflict checking, so the documents will be committed even if this creates conflicts.

bulk_save(cls, docs, use_uuids=True, all_or_nothing=False)
Class Method

source code 

Save multiple documents in database.

Parameters:
  • use_uuids - add _id in doc who don't have it already set.
  • all_or_nothing - In the case of a power failure, when the database restarts either all the changes will have been saved or none of them. However, it does not do conflict checking, so the documents will be committed even if this creates conflicts.

Property Details [hide private]

new_document

Get Method:
unreachable(self)