summaryrefslogtreecommitdiff
path: root/src/db.py
diff options
context:
space:
mode:
authorKristofer Hallin <kristofer@sunet.se>2021-10-07 21:20:54 +0200
committerKristofer Hallin <kristofer@sunet.se>2021-10-07 21:20:54 +0200
commit3dc9e661527c17c348eb0000a72440953cf7994c (patch)
tree4f8be52aa0c6f3c99a55510f4d592e66d070ead0 /src/db.py
parent4feea77ccc20565e677e3833656275a6514ebdcb (diff)
Support bulk transactions.
Diffstat (limited to 'src/db.py')
-rwxr-xr-xsrc/db.py13
1 files changed, 5 insertions, 8 deletions
diff --git a/src/db.py b/src/db.py
index c4244e1..f9d0da1 100755
--- a/src/db.py
+++ b/src/db.py
@@ -27,7 +27,6 @@ class DictDB():
except couch.exceptions.NotFound:
print("Creating database and indexes.")
self.couchdb = self.server.create(database)
- self.server.create('_users')
for i in index.indexes:
self.couchdb.index(i)
@@ -41,7 +40,7 @@ class DictDB():
"""
ts = time.time()
- while ts == self._ts:
+ while round(ts * 1000) == self._ts:
ts = time.time()
self._ts = round(ts * 1000)
@@ -52,17 +51,15 @@ class DictDB():
Store a document in CouchDB.
"""
- key = str(self.unique_key())
if type(data) is list:
for item in data:
- item['_id'] = key
-
- self.couchdb.save(item)
+ item['_id'] = str(self.unique_key())
+ self.couchdb.save_bulk(data)
else:
- data['_id'] = key
+ data['_id'] = str(self.unique_key())
self.couchdb.save(data)
- return key
+ return True
def get(self, key):
"""