Skip to content

Commit

Permalink
feat: add class to represent nested conditions #259
Browse files Browse the repository at this point in the history
  • Loading branch information
MRichards99 committed Nov 30, 2021
1 parent 1d24021 commit 583cbf2
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions datagateway_api/src/search_api/nested_where_filters.py
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})"

0 comments on commit 583cbf2

Please sign in to comment.