Skip to content

Commit

Permalink
Merge pull request #86 from ral-facilities/85_add_in_filter
Browse files Browse the repository at this point in the history
#85: Add in filter
  • Loading branch information
keiranjprice101 authored Oct 11, 2019
2 parents 71393af + f37081f commit 6ae5616
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 75 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
Loading

0 comments on commit 6ae5616

Please sign in to comment.