-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add class to represent nested conditions #259
- Loading branch information
1 parent
1d24021
commit 583cbf2
Showing
1 changed file
with
30 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
class NestedWhereFilters: | ||
def __init__(self, lhs, rhs, joining_operator): | ||
""" | ||
Class to represent nested conditions that use different boolean operators e.g. | ||
`(A OR B) AND (C OR D)`. This works by joining the two conditions with a boolean | ||
operator | ||
:param lhs: Left hand side of the condition - either a string condition, WHERE | ||
filter or instance of this class | ||
:type lhs: Any class that has `__str__()` implemented, but use cases will be for | ||
:class:`str` or :class:`SearchAPIWhereFilter` or :class:`NestedWhereFilters` | ||
:param rhs: Right hand side of the condition - either a string condition, WHERE | ||
filter or instance of this class | ||
:type rhs: Any class that has `__str__()` implemented, but use cases will be for | ||
:class:`str` or :class:`SearchAPIWhereFilter` or :class:`NestedWhereFilters` | ||
:param joining_operator: Boolean operator used to join the conditions of `lhs` | ||
`rhs` (e.g. `AND` or `OR`) | ||
:type joining_operator: :class:`str` | ||
""" | ||
|
||
self.lhs = str(lhs) | ||
self.rhs = str(rhs) | ||
self.joining_operator = joining_operator | ||
|
||
def __str__(self): | ||
""" | ||
Join the condition on the left with the one on the right with the boolean | ||
operator | ||
""" | ||
return f"({self.lhs} {self.joining_operator} {self.rhs})" |