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

32 lines
913 B
Python
Raw Normal View History

# pylint: disable=too-few-public-methods
import dictdatabase as DDB
2023-11-24 19:50:18 +00:00
from ..config import DatabaseSettings
class Database:
"""
This is a singleton that can be accessed using get_instance()
"""
2023-11-24 19:50:18 +00:00
class IsSingletonException(Exception):
pass
__instance = None
db = DDB
2023-11-24 19:50:18 +00:00
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:
2023-11-24 19:50:18 +00:00
raise self.IsSingletonException("This class is a singleton")
Database.__instance = self