diff options
author | drebs <drebs@leap.se> | 2012-12-10 12:05:31 -0200 |
---|---|---|
committer | drebs <drebs@leap.se> | 2012-12-10 12:05:31 -0200 |
commit | ddd41a0c4bbe70cfca3827b93ac7f35b28c49400 (patch) | |
tree | b06d3aae4ea943ecbb6ef5e4dce937b64bd9cc6c /backends/objectstore.py | |
parent | ded8b721def13751fe0b27e50ab1a3cb999fb292 (diff) |
Add CouchDB u1db backend.
Diffstat (limited to 'backends/objectstore.py')
-rw-r--r-- | backends/objectstore.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/backends/objectstore.py b/backends/objectstore.py index e36df72d..456892b3 100644 --- a/backends/objectstore.py +++ b/backends/objectstore.py @@ -1,11 +1,17 @@ from u1db.backends import CommonBackend +from soledad import SyncLog, TransactionLog class ObjectStore(CommonBackend): def __init__(self): + # This initialization method should be called after the connection + # with the database is established, so it can ensure that u1db data is + # configured and up-to-date. + self.set_document_factory(LeapDocument) self._sync_log = SyncLog() self._transaction_log = TransactionLog() + self._ensure_u1db_data() #------------------------------------------------------------------------- # implemented methods from Database @@ -29,6 +35,26 @@ class ObjectStore(CommonBackend): return None return doc + def _put_doc(self, doc) + raise NotImplementedError(self._put_doc) + + def put_doc(self, doc) + # consistency check + if doc.doc_id is None: + raise errors.InvalidDocId() + self._check_doc_id(doc.doc_id) + self._check_doc_size(doc) + # put the document + new_rev = self._allocate_doc_rev(doc.rev) + self._put_doc(doc, new_rev) + doc.rev = new_rev + # update u1db generation and logs + new_gen = self._get_generation() + 1 + trans_id = self._allocate_transaction_id() + self._transaction_log.append((new_gen, doc.doc_id, trans_id)) + self._set_u1db_data() + return new_rev + def delete_doc(self, doc): old_doc = self._get_doc(doc.doc_id, check_for_conflicts=True) if old_doc is None: |