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

33 lines
944 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
2023-10-02 13:55:13 +00:00
if not DatabaseSettings.DATABASE_DIRECTORY.is_dir():
DatabaseSettings.DATABASE_DIRECTORY.mkdir()
db.config.storage_directory = DatabaseSettings.DATABASE_DIRECTORY
if not db.at("requests").exists():
db.at("requests").create({})
if not db.at("profiles").exists():
db.at("profiles").create({})
@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