-
Notifications
You must be signed in to change notification settings - Fork 0
feat: Support Or and nested queries #13
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| import warnings | ||
| from typing import Any, List, Optional, Iterable, Dict, Tuple, Sequence, Union | ||
| from google.cloud.firestore_v1.base_query import FieldFilter | ||
| from google.cloud.firestore_v1.base_query import FieldFilter, And, Or | ||
|
|
||
| from mockfirestore import AlreadyExists | ||
| from mockfirestore._helpers import ( | ||
|
|
@@ -60,15 +60,15 @@ def where( | |
| field: Optional[str] = None, | ||
| op: Optional[str] = None, | ||
| value: Optional[Any] = None, | ||
| filter: Optional[FieldFilter] = None, | ||
| filter: Union[FieldFilter, And, Or, None] = None, | ||
| ) -> Query: | ||
| if filter is not None: | ||
| field, op, value = filter.field_path, filter.op_string, filter.value | ||
| if field is None or op is None or value is None: | ||
| if filter is None and (field is None or op is None or value is None): | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes as we cannot rely on the truthiness of |
||
| raise ValueError( | ||
| "field, op, and value must be provided (or a FieldFilter instance)" | ||
| ) | ||
| query = Query(self, field_filters=[(field, op, value)]) | ||
| if filter is None: | ||
| filter = FieldFilter(field, op, value) | ||
| query = Query(self, field_filter=filter) | ||
| return query | ||
|
|
||
| def order_by(self, key: str, direction: Optional[str] = None) -> Query: | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not critical
May we use OptionalUnion[FieldFilter, And, Or] ?
As None is not a type. and using Union[type, None] is outdated
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Optional is just shorthand for Union[x, None].
In this case it wouldn't make things much shorter as you end up with Optional[Union[x]].
It's not deprecated either to use Union
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It wouldn't
Thats why it isnt critical.
But even python's creators decided that it is bad design :)