summaryrefslogtreecommitdiff
path: root/src/db.py
diff options
context:
space:
mode:
authorKristofer Hallin <kristofer@sunet.se>2021-10-14 09:48:17 +0200
committerKristofer Hallin <kristofer@sunet.se>2021-10-14 09:48:17 +0200
commit583542443adb2d66208dacb71581bc2936c59201 (patch)
tree30d6cd714e1ae5058303c46fef901054d8d5334a /src/db.py
parentc3330191348b19be264eabf5e0acd5fb97f0568d (diff)
Find, now with pagination! Use limit and skip to get the results you want.
Diffstat (limited to 'src/db.py')
-rwxr-xr-xsrc/db.py19
1 files changed, 15 insertions, 4 deletions
diff --git a/src/db.py b/src/db.py
index f9d0da1..8ab98e7 100755
--- a/src/db.py
+++ b/src/db.py
@@ -76,24 +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].isnumeric():
kwargs[key] = int(kwargs[key])
selector['selector'][key] = {'$eq': kwargs[key]}
- for doc in self.couchdb.find(selector):
+ for doc in self.couchdb.find(selector, wrapper=None, limit=5):
data.append(doc)
return data