Skip to content

Commit

Permalink
#85: Add in filter
Browse files Browse the repository at this point in the history
  • Loading branch information
keiranjprice101 committed Oct 11, 2019
1 parent 71393af commit 5caed7f
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions common/database_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ def execute_query(self):
self.session.refresh(record)
self.inserted_row = record


class UpdateQuery(Query):

def __init__(self, table, row, new_values):
Expand Down Expand Up @@ -159,6 +160,8 @@ def apply_filter(self, query):
query.base_query = query.base_query.filter(getattr(query.table, self.field) <= self.value)
elif self.operation == "gte":
query.base_query = query.base_query.filter(getattr(query.table, self.field) >= self.value)
elif self.operation == "in":
query.base_query = query.base_query.filter(getattr(query.table, self.field).in_(self.value))
else:
raise BadFilterError(f" Bad operation given to where filter. operation: {self.operation}")

Expand Down Expand Up @@ -308,6 +311,7 @@ def create_row_from_json(table, data):
create_query.execute_query()
return create_query.inserted_row.to_dict()


def create_rows_from_json(table, data):
"""
Given a List containing dictionary representations of entities, or a dictionary representation of an entity, insert
Expand All @@ -320,6 +324,7 @@ def create_rows_from_json(table, data):
return [create_row_from_json(table, entity) for entity in data]
return create_row_from_json(table, data)


def get_row_by_id(table, id):
"""
Gets the row matching the given ID from the given table, raises MissingRecordError if it can not be found
Expand Down

0 comments on commit 5caed7f

Please sign in to comment.