summaryrefslogtreecommitdiff
path: root/src/db.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/db.py')
-rwxr-xr-xsrc/db.py33
1 files changed, 21 insertions, 12 deletions
diff --git a/src/db.py b/src/db.py
index f4f9bc1..2308e8c 100755
--- a/src/db.py
+++ b/src/db.py
@@ -1,7 +1,7 @@
-# A database storing dictionaries, keyed on a timestamp.
-# value = A dict which will be stored as a JSON object encoded in
-# UTF-8. Note that dict keys of type integer or float will become
-# strings while values will keep their type.
+# A database storing dictionaries, keyed on a timestamp. value = A
+# dict which will be stored as a JSON object encoded in UTF-8. Note
+# that dict keys of type integer or float will become strings while
+# values will keep their type.
# Note that there's a (slim) chance that you'd stomp on the previous
# value if you're too quick with generating the timestamps, ie
@@ -76,26 +76,35 @@ class DictDB():
def slice(self, key_from=None, key_to=None):
pass
- def search(self, **kwargs):
+ def search(self, limit=25, skip=0, **kwargs):
"""
- Execute a Mango query, ideally we should have an index matching the,
+ Execute a Mango query, ideally we should have an index matching
the query otherwise things will be slow.
"""
data = list()
selector = dict()
+ try:
+ limit = int(limit)
+ skip = int(skip)
+ except ValueError:
+ limit = 25
+ skip = 0
+
if kwargs:
- selector = {"selector": {}}
+ selector = {
+ "limit": limit,
+ "skip": skip,
+ "selector": {}
+ }
for key in kwargs:
- if kwargs[key] is None:
- continue
- if kwargs[key].isnumeric():
+ if kwargs[key] and kwargs[key].isnumeric():
kwargs[key] = int(kwargs[key])
selector['selector'][key] = {'$eq': kwargs[key]}
- print(selector)
- for doc in self.couchdb.find(selector):
+
+ for doc in self.couchdb.find(selector, wrapper=None, limit=5):
data.append(doc)
return data