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

34 lines
962 B
Python
Raw Normal View History

# pylint: disable=too-few-public-methods
2023-10-01 19:47:33 +00:00
import os
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-01 19:47:33 +00:00
if not os.path.isdir(DatabaseSettings.DATABASE_DIRECTORY):
os.mkdir(DatabaseSettings.DATABASE_DIRECTORY)
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