Skip to content

Commit

Permalink
#34: Refactor get rows_by_filter
Browse files Browse the repository at this point in the history
  • Loading branch information
keiranjprice101 committed Aug 29, 2019
1 parent bf29c0b commit 452ce6d
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions common/database_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,15 +318,14 @@ def update_row_from_id(table, id, new_values):
update_query.execute_query()


def get_rows_by_filter(table, filters):
def get_filtered_read_query_results(filter_handler, filters, query):
"""
Given a list of filters supplied in json format, returns entities that match the filters from the given table
:param table: The table to checked
:param filters: The list of filters to be applied
:return: A list of the rows returned in dictionary form
Given a filter handler, list of filters and a query. Apply the filters and execute the query
:param filter_handler: The filter handler to apply the filters
:param filters: The filters to be applied
:param query: The query for the filters to be applied to
:return: The results of the query
"""
query = ReadQuery(table)
filter_handler = FilterOrderHandler()
try:
for query_filter in filters:
if len(query_filter) == 0:
Expand All @@ -340,10 +339,23 @@ def get_rows_by_filter(table, filters):
if list(query_filter)[0].lower() == "include":
return list(map(lambda x: x.to_nested_dict(query_filter["include"]), results))
return list(map(lambda x: x.to_dict(), results))

finally:
query.session.close()


def get_rows_by_filter(table, filters):
"""
Given a list of filters supplied in json format, returns entities that match the filters from the given table
:param table: The table to checked
:param filters: The list of filters to be applied
:return: A list of the rows returned in dictionary form
"""
query = ReadQuery(table)
filter_handler = FilterOrderHandler()
return get_filtered_read_query_results(filter_handler, filters, query)


def get_first_filtered_row(table, filters):
"""
returns the first row that matches a given filter, in a given table
Expand Down

0 comments on commit 452ce6d

Please sign in to comment.