support-organizer/backend/fgo_request_manager/database/database.py
Firq 03901e1d12
All checks were successful
/ build:package (push) Successful in 11s
/ backend-pylint (push) Successful in 21s
updated package to conform to pylint
2023-12-21 17:11:47 +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