Skip to content

Commit

Permalink
Remove duplicated queries
Browse files Browse the repository at this point in the history
  • Loading branch information
keiranjprice101 committed Aug 1, 2019
1 parent b6897fb commit b246805
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions common/database_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def get_count(self):
self.execute_query()
return self.base_query.count()


class ReadQuery(Query):

def __init__(self, table):
Expand All @@ -57,14 +58,16 @@ def execute_query(self):

def get_single_result(self):
self.execute_query()
if self.base_query.first() is not None:
return self.base_query.first()
result = self.base_query.first()
if result is not None:
return result
raise MissingRecordError(" No result found")

def get_all_results(self):
self.execute_query()
if self.base_query.all() is not None:
return self.base_query.all()
results = self.base_query.all()
if results is not None:
return results
raise MissingRecordError(" No results found")


Expand Down

0 comments on commit b246805

Please sign in to comment.