From e1eb68e226ddfd0653a4feafef580cbabf45817e Mon Sep 17 00:00:00 2001 From: Ruud Date: Mon, 6 Oct 2014 23:00:50 +0200 Subject: [PATCH] CodernityDB updates --- libs/CodernityDB3/database.py | 9 +++++++-- libs/CodernityDB3/tree_index.py | 19 +++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/libs/CodernityDB3/database.py b/libs/CodernityDB3/database.py index 8de12d54..874408f7 100644 --- a/libs/CodernityDB3/database.py +++ b/libs/CodernityDB3/database.py @@ -952,8 +952,8 @@ you should check index code.""" % (index.name, ex), RuntimeWarning) storage = ind.storage data = storage.get(start, size, status) else: - data = {} + if with_doc and index_name != 'id': storage = ind.storage doc = self.get('id', l_key, False) @@ -966,6 +966,7 @@ you should check index code.""" % (index.name, ex), RuntimeWarning) data['_rev'] = _unk else: data['key'] = _unk + return data def get_many(self, index_name, key=None, limit=-1, offset=0, with_doc=False, with_storage=True, start=None, end=None, **kwargs): @@ -1010,6 +1011,8 @@ you should check index code.""" % (index.name, ex), RuntimeWarning) else: data = {} doc_id = ind_data[0] + doc_id = doc_id.decode() + if with_doc: doc = self.get('id', doc_id, False) if data: @@ -1045,13 +1048,15 @@ you should check index code.""" % (index.name, ex), RuntimeWarning) except StopIteration: break else: + doc_id = doc_id.decode() + if index_name == 'id': if with_storage and size: data = storage.get(start, size, status) else: data = {} data['_id'] = doc_id - data['_rev'] = unk + data['_rev'] = unk.decode() else: data = {} if with_storage and size: diff --git a/libs/CodernityDB3/tree_index.py b/libs/CodernityDB3/tree_index.py index 1e116bdd..0d39aecb 100644 --- a/libs/CodernityDB3/tree_index.py +++ b/libs/CodernityDB3/tree_index.py @@ -632,6 +632,10 @@ class IU_TreeBasedIndex(Index): return buffer_start, (buffer_start + tree_buffer_size) def _find_first_key_occurence_in_node(self, node_start, key, nr_of_elements): + + if isinstance(key, str): + key = key.encode() + if nr_of_elements == 1: return self._find_key_in_node_with_one_element(key, node_start, mode=MODE_FIRST) else: @@ -1914,14 +1918,29 @@ class IU_TreeBasedIndex(Index): def get(self, key): ## print("------", type(key)) # TODO ## print(self) # TODO + + # Fix types + if isinstance(key, str): + key = key.encode() + k = self.make_key(key) ## print("K:" * 10, k) # TODO return self._find_key(k) def get_many(self, key, limit=1, offset=0): + # Fix types + if isinstance(key, str): + key = key.encode() return self._find_key_many(self.make_key(key), limit, offset) def get_between(self, start, end, limit=1, offset=0, inclusive_start=True, inclusive_end=True): + + # Fix types + if isinstance(start, str): + start = start.encode() + if isinstance(end, str): + end = end.encode() + if start is None: end = self.make_key(end) if inclusive_end: