Continuing to add correct documentation to components within the application
This commit is contained in:
@ -5,6 +5,10 @@ import os
|
||||
|
||||
|
||||
class DatabaseController(ABC):
|
||||
""" Abstract Base Class to handle database access for each component
|
||||
in the web app
|
||||
"""
|
||||
|
||||
__data_dir = "./data/"
|
||||
__db_name = "wmgzon.db"
|
||||
|
||||
@ -15,6 +19,9 @@ class DatabaseController(ABC):
|
||||
__sqlitefile = __data_dir + __db_name
|
||||
|
||||
def __init__(self):
|
||||
""" Initialises the object and creates a connection to the local
|
||||
DB on the server
|
||||
"""
|
||||
self._conn = None
|
||||
try:
|
||||
# Creates a connection and specifies a flag to parse all types
|
||||
@ -28,13 +35,14 @@ class DatabaseController(ABC):
|
||||
print(e)
|
||||
|
||||
def __del__(self):
|
||||
""" Object Destructor which kills the connection to the database """
|
||||
if self._conn is not None:
|
||||
self._conn.close()
|
||||
|
||||
""" Takes a dictionary of fields and returns the object
|
||||
with those fields populated """
|
||||
|
||||
def new_instance(self, of: type, with_fields: Mapping[str, Any]):
|
||||
""" Takes a dictionary of fields and returns the object
|
||||
with those fields populated
|
||||
"""
|
||||
obj = of.__new__(of)
|
||||
for attr, value in with_fields.items():
|
||||
setattr(obj, attr, value)
|
||||
@ -46,16 +54,28 @@ class DatabaseController(ABC):
|
||||
|
||||
@abstractmethod
|
||||
def create(self):
|
||||
""" Abstract method used to create a new record of a given
|
||||
type within the database
|
||||
"""
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def read(self):
|
||||
""" Abstract method used to read a record of a given
|
||||
type from the database
|
||||
"""
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def update(self):
|
||||
""" Abstract method used to update a record of a given
|
||||
type within the database
|
||||
"""
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def delete(self):
|
||||
""" Abstract method used to delete record of a given
|
||||
type from the database
|
||||
"""
|
||||
pass
|
||||
|
Reference in New Issue
Block a user