Skip to content

Commit

Permalink
#18: Update get_row_by_id
Browse files Browse the repository at this point in the history
  • Loading branch information
keiranjprice101 committed Aug 14, 2019
1 parent f7335c3 commit 171ad98
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions common/database_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def __init__(self, field, value, operation):

def apply_filter(self, query):
if self.operation == "eq":
query.base_query = query.base_query.filter(getattr(query.table, self.field) == self.value)
query.base_query = query.base_query.filter(getattr(query.table, self.field) == self.value)
elif self.operation == "like":
query.base_query = query.base_query.filter(getattr(query.table, self.field).like(f"%{self.value}%"))
else:
Expand Down Expand Up @@ -241,6 +241,7 @@ def apply_filters(self, query):
def insert_row_into_table(table, row):
"""
Insert the given row into its table
:param table: The table to be inserted to
:param row: The row to be inserted
"""
create_query = CreateQuery(table, row)
Expand Down Expand Up @@ -268,7 +269,7 @@ def get_row_by_id(table, id):
read_query = ReadQuery(table)
try:
log.info(f" Querying {table.__tablename__} for record with ID: {id}")
where_filter = WhereFilter("ID", id)
where_filter = WhereFilter("ID", id, "eq")
where_filter.apply_filter(read_query)
return read_query.get_single_result()
finally:
Expand Down

0 comments on commit 171ad98

Please sign in to comment.