support-organizer/backend/fgo-request-manager/database/database.py
2023-11-24 20:50:18 +01:00

32 lines
913 B
Python

# pylint: disable=too-few-public-methods
import dictdatabase as DDB
from ..config import DatabaseSettings
class Database:
"""
This is a singleton that can be accessed using get_instance()
"""
class IsSingletonException(Exception):
pass
__instance = None
db = DDB
DatabaseSettings.DATABASE_DIRECTORY.mkdir(exist_ok=True, parents=True)
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 self.IsSingletonException("This class is a singleton")
Database.__instance = self