Skip to content

Commit

Permalink
#154: Make DB backend entity_type non-backend specific
Browse files Browse the repository at this point in the history
- Instead of parsing an instance of something like `common.database.models.USER`, the field name is parsed into the DB backend function instead, and an instance of that entity is created in the DB backend functions, to make that data parsing non-backend specific
  • Loading branch information
MRichards99 committed Oct 22, 2020
1 parent f0ff0a1 commit 06522be
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions common/database/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
requires_session_id,
)
from common.helpers import queries_records
from common.database.models import SESSION
from common.database.models import EntityHelper, SESSION
import uuid
from common.exceptions import AuthenticationError
import datetime
Expand Down Expand Up @@ -61,42 +61,50 @@ def logout(self, session_id):

@requires_session_id
@queries_records
def get_with_filters(self, session_id, table, filters):
def get_with_filters(self, session_id, entity_type, filters):
table = EntityHelper.get_entity_object_from_name(entity_type)
return get_rows_by_filter(table, filters)

@requires_session_id
@queries_records
def create(self, session_id, table, data):
def create(self, session_id, entity_type, data):
table = EntityHelper.get_entity_object_from_name(entity_type)
return create_rows_from_json(table, data)

@requires_session_id
@queries_records
def update(self, session_id, table, data):
def update(self, session_id, entity_type, data):
table = EntityHelper.get_entity_object_from_name(entity_type)
return patch_entities(table, data)

@requires_session_id
@queries_records
def get_one_with_filters(self, session_id, table, filters):
def get_one_with_filters(self, session_id, entity_type, filters):
table = EntityHelper.get_entity_object_from_name(entity_type)
return get_first_filtered_row(table, filters)

@requires_session_id
@queries_records
def count_with_filters(self, session_id, table, filters):
def count_with_filters(self, session_id, entity_type, filters):
table = EntityHelper.get_entity_object_from_name(entity_type)
return get_filtered_row_count(table, filters)

@requires_session_id
@queries_records
def get_with_id(self, session_id, table, id_):
def get_with_id(self, session_id, entity_type, id_):
table = EntityHelper.get_entity_object_from_name(entity_type)
return get_row_by_id(table, id_).to_dict()

@requires_session_id
@queries_records
def delete_with_id(self, session_id, table, id_):
def delete_with_id(self, session_id, entity_type, id_):
table = EntityHelper.get_entity_object_from_name(entity_type)
return delete_row_by_id(table, id_)

@requires_session_id
@queries_records
def update_with_id(self, session_id, table, id_, data):
def update_with_id(self, session_id, entity_type, id_, data):
table = EntityHelper.get_entity_object_from_name(entity_type)
return update_row_from_id(table, id_, data)

@requires_session_id
Expand Down

0 comments on commit 06522be

Please sign in to comment.