from models.DatabaseType import DatabaseType from dataclasses import dataclass @dataclass class DatabaseConfig: _host: str _database_type: DatabaseType | None _database_name: str _database_ssid: str _database_port: str def __init__(self, config: dict): self._host = config["HOST"] type = config["DATABASE_TYPE"] match type: case 'PSQL': self._database_type = DatabaseType.PSQL case 'ORCL': self._database_type = DatabaseType.ORCL case 'SQLITE': self._database_type = DatabaseType.SQLITE case _: self._database_type = None self._database_name = config["DATABASE_NAME"] self._database_ssid = config["DATABASE_SSID"] self._database_port = config["DATABASE_PORT"] @classmethod def create(cls, database_name: str, database_type: DatabaseType, database_ssid: str, database_port: str, host: str): config = { "HOST": host, "DATABASE_TYPE": database_type, "DATABASE_NAME": database_name, "DATABASE_SSID": database_ssid, "DATABASE_PORT": database_port, } obj = cls.__new__(cls) cls.__init__(obj, config) return obj @property def host(self) -> str: return self._host @property def type(self) -> DatabaseType: return self._database_type @property def name(self) -> str: return self._database_name @property def ssid(self) -> str: return self._database_ssid @property def port(self) -> str: return self._database_port