31 lines
913 B
Python
31 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
|