Skip to content

Add start_at/end_at filter for both value and key #504

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions firebase_admin/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -542,15 +542,15 @@ def limit_to_last(self, limit):
self._params['limitToLast'] = limit
return self

def start_at(self, start):
def start_at(self, start, key=None):
"""Sets the lower bound for a range query.

The Query will only return child nodes with a value greater than or equal to the specified
value.

Args:
start: JSON-serializable value to start at, inclusive.

key: JSON-serializable object key to start at.
Returns:
Query: The updated Query instance.

Expand All @@ -559,18 +559,22 @@ def start_at(self, start):
"""
if start is None:
raise ValueError('Start value must not be None.')
self._params['startAt'] = json.dumps(start)

if key != None:
self._params['startAt'] = json.dumps(start) + ',"' + key + '"'
else:
self._params['startAt'] = json.dumps(start)
return self

def end_at(self, end):
def end_at(self, end, key=None):
"""Sets the upper bound for a range query.

The Query will only return child nodes with a value less than or equal to the specified
value.

Args:
end: JSON-serializable value to end at, inclusive.

key: JSON-serializable object key to end at.
Returns:
Query: The updated Query instance.

Expand All @@ -579,7 +583,10 @@ def end_at(self, end):
"""
if end is None:
raise ValueError('End value must not be None.')
self._params['endAt'] = json.dumps(end)
if key != None:
self._params['endAt'] = json.dumps(start) + ',"' + key + '"'
else:
self._params['endAt'] = json.dumps(start)
return self

def equal_to(self, value):
Expand Down