2023-10-01 17:47:35 +00:00
|
|
|
# pylint: disable=too-few-public-methods
|
|
|
|
|
2023-10-01 19:47:33 +00:00
|
|
|
import os
|
2023-10-01 17:47:35 +00:00
|
|
|
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)
|
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
|