Skip to content

Commit 8cfcf2e

Browse files
committed
Add deep path support on orderBy
1 parent 2c152ae commit 8cfcf2e

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

pyrebase/pyrebase.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,9 +282,19 @@ def get(self, token=None, json_kwargs={}):
282282
elif build_query["orderBy"] == "$value":
283283
sorted_response = sorted(request_dict.items(), key=lambda item: item[1])
284284
else:
285-
sorted_response = sorted(request_dict.items(), key=lambda item: item[1][build_query["orderBy"]])
285+
path = build_query["orderBy"].split("/")
286+
sorted_response = sorted(request_dict.items(), key=lambda item: self._walk(item[1], path))
286287
return PyreResponse(convert_to_pyre(sorted_response), query_key)
287288

289+
def _walk(self, obj, path):
290+
if path[0] in obj:
291+
if len(path) == 1:
292+
return obj[path[0]]
293+
else:
294+
return self._walk(obj[path[0]], path[1:])
295+
else:
296+
raise Exception("Keys '{}' not found in {}".format(path[0], obj))
297+
288298
def push(self, data, token=None, json_kwargs={}):
289299
request_ref = self.check_token(self.database_url, self.path, token)
290300
self.path = ""

0 commit comments

Comments
 (0)