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 | b3090f710e3777bad2a9f996444e5099883c9f03 (patch) | |
tree | b129323e5277ac2fc854f8f58a408dc092e6c128 /src/leap/soledad/backends/objectstore.py | |
parent | f89f2e0fe490899ecc4baf3395f3441111da328f (diff) |
Add CouchDB u1db backend.
Diffstat (limited to 'src/leap/soledad/backends/objectstore.py')
-rw-r--r-- | src/leap/soledad/backends/objectstore.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/leap/soledad/backends/objectstore.py b/src/leap/soledad/backends/objectstore.py index e36df72d..456892b3 100644 --- a/src/leap/soledad/backends/objectstore.py +++ b/src/leap/soledad/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: |