Skip to content

Commit

Permalink
Merge branch 'master' into 70_add_db_creation_script
Browse files Browse the repository at this point in the history
  • Loading branch information
keiranjprice101 committed Oct 11, 2019
2 parents c9b41ec + 6ae5616 commit 77a2c6f
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 78 deletions.
4 changes: 3 additions & 1 deletion common/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
class Config(object):

def __init__(self):
with open(Path("config.json")) as target:
config_path = Path(__file__).parent.parent / "config.json"
with open(config_path) as target:

self.config = json.load(target)
target.close()

Expand Down
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
2 changes: 1 addition & 1 deletion common/logger_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from common.config import config

log_level = "DEBUG"
LOG_FILE_NAME = Path("logs.log")
LOG_FILE_NAME = Path(__file__).parent.parent / "logs.log"
logger_config = {
"version": 1,
"formatters": {"default": {
Expand Down
Loading

0 comments on commit 77a2c6f

Please sign in to comment.