2023-10-01 17:47:35 +00:00
|
|
|
# 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()
|
2023-10-01 17:47:35 +00:00
|
|
|
db.config.storage_directory = DatabaseSettings.DATABASE_DIRECTORY
|
2023-10-01 19:40:06 +00:00
|
|
|
if not db.at("requests").exists():
|
|
|
|
db.at("requests").create({})
|
|
|
|
if not db.at("profiles").exists():
|
|
|
|
db.at("profiles").create({})
|
2023-10-01 17:47:35 +00:00
|
|
|
|
|
|
|
@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
|