diff options
author | Kristofer Hallin <kristofer@sunet.se> | 2021-10-18 15:17:10 +0200 |
---|---|---|
committer | Kristofer Hallin <kristofer@sunet.se> | 2021-10-18 15:17:10 +0200 |
commit | 24fb5eb57531f20d1f394d145833cc31016e86ee (patch) | |
tree | 52ec028ff720000c480b1000c3db53021ff3fb60 /src/db.py | |
parent | 99f02077ed897b73fb9f452926e8f3f1fed72358 (diff) | |
parent | 34a353a539f71b6a87413b58ea483b36f94e3516 (diff) |
Fixed merge conflicts.
Diffstat (limited to 'src/db.py')
-rwxr-xr-x | src/db.py | 33 |
1 files changed, 21 insertions, 12 deletions
@@ -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 |