support-organizer/backend/src/database/database.py

27 lines
683 B
Python
Raw Normal View History

# pylint: disable=too-few-public-methods
import dictdatabase as DDB
from config.db_settings import DatabaseSettings
class IsSingletonException(Exception):
pass
class Database:
"""
This is a singleton that can be accessed using get_instance()
"""
__instance = None
db = DDB
db.config.storage_directory = DatabaseSettings.DATABASE_DIRECTORY
@staticmethod
def get_instance():
if Database.__instance is None:
Database()
return Database.__instance
def __init__(self):
if Database.__instance is not None:
raise IsSingletonException("This class is a singleton")
Database.__instance = self