Improved database module structure
This commit is contained in:
@@ -1,3 +1 @@
|
||||
# imports:
|
||||
|
||||
from .database_connection import DatabaseConnection
|
||||
|
3
src/sh_edraft/database/connection/__init__.py
Normal file
3
src/sh_edraft/database/connection/__init__.py
Normal file
@@ -0,0 +1,3 @@
|
||||
# imports:
|
||||
|
||||
from .database_connection import DatabaseConnection
|
@@ -8,3 +8,6 @@ class DatabaseConnectionBase(ServiceBase):
|
||||
@abstractmethod
|
||||
def __init__(self):
|
||||
ServiceBase.__init__(self)
|
||||
|
||||
@abstractmethod
|
||||
def use_mysql(self, connection_string: str): pass
|
@@ -3,7 +3,7 @@ from typing import Optional
|
||||
from sqlalchemy import engine, create_engine
|
||||
from sqlalchemy.orm import session, sessionmaker
|
||||
|
||||
from sh_edraft.database.base.database_connection_base import DatabaseConnectionBase
|
||||
from sh_edraft.database.connection.base.database_connection_base import DatabaseConnectionBase
|
||||
from sh_edraft.database.model.database_settings import DatabaseSettings
|
||||
from sh_edraft.utils.console import Console
|
||||
|
||||
@@ -19,9 +19,13 @@ class DatabaseConnection(DatabaseConnectionBase):
|
||||
self._session: Optional[session] = None
|
||||
self._credentials: Optional[str] = None
|
||||
|
||||
def create(self):
|
||||
self.create()
|
||||
|
||||
def create(self): pass
|
||||
|
||||
def use_mysql(self, connection_string: str):
|
||||
try:
|
||||
self._engine = create_engine(self._db_settings.decrypted_connection_string)
|
||||
self._engine = create_engine(connection_string)
|
||||
|
||||
if self._db_settings.encoding is not None:
|
||||
self._engine.encoding = self._db_settings.encoding
|
@@ -0,0 +1,4 @@
|
||||
# imports:
|
||||
|
||||
from .database_settings import DatabaseSettings
|
||||
from .database_settings_name import DatabaseSettingsName
|
||||
|
@@ -3,7 +3,6 @@ from typing import Optional
|
||||
|
||||
from sh_edraft.configuration.base.configuration_model_base import ConfigurationModelBase
|
||||
from sh_edraft.database.model.database_settings_name import DatabaseSettingsName
|
||||
from sh_edraft.utils.credential_manager import CredentialManager
|
||||
from sh_edraft.utils.console import Console
|
||||
|
||||
|
||||
@@ -26,10 +25,6 @@ class DatabaseSettings(ConfigurationModelBase):
|
||||
def connection_string(self, connection_string: str):
|
||||
self._connection_string = connection_string
|
||||
|
||||
@property
|
||||
def decrypted_connection_string(self) -> str:
|
||||
return CredentialManager.build_string(self._connection_string, self._credentials)
|
||||
|
||||
@property
|
||||
def credentials(self) -> str:
|
||||
return self._credentials
|
||||
|
@@ -5,18 +5,25 @@ from sh_edraft.configuration.base.configuration_base import ConfigurationBase
|
||||
from sh_edraft.hosting.base.application_runtime_base import ApplicationRuntimeBase
|
||||
from sh_edraft.hosting.application_runtime import ApplicationRuntime
|
||||
from sh_edraft.hosting.base.application_host_base import ApplicationHostBase
|
||||
from sh_edraft.service.service_provider import ServiceProvider
|
||||
from sh_edraft.service.base.service_provider_base import ServiceProviderBase
|
||||
from sh_edraft.service.providing.service_provider import ServiceProvider
|
||||
from sh_edraft.service.providing.base.service_provider_base import ServiceProviderBase
|
||||
|
||||
|
||||
class ApplicationHost(ApplicationHostBase):
|
||||
|
||||
def __init__(self):
|
||||
ApplicationHostBase.__init__(self)
|
||||
|
||||
# Init
|
||||
self._config = Configuration()
|
||||
self._app_runtime = ApplicationRuntime(self._config)
|
||||
self._services = ServiceProvider(self._app_runtime)
|
||||
|
||||
# Create
|
||||
self._config.create()
|
||||
self._services.create()
|
||||
|
||||
# Set vars
|
||||
self._start_time: datetime = datetime.now()
|
||||
self._end_time: datetime = datetime.now()
|
||||
|
||||
|
@@ -2,7 +2,7 @@ from abc import ABC, abstractmethod
|
||||
|
||||
from sh_edraft.configuration.base.configuration_base import ConfigurationBase
|
||||
from sh_edraft.hosting.base.application_runtime_base import ApplicationRuntimeBase
|
||||
from sh_edraft.service.base.service_provider_base import ServiceProviderBase
|
||||
from sh_edraft.service.providing.base.service_provider_base import ServiceProviderBase
|
||||
|
||||
|
||||
class ApplicationHostBase(ABC):
|
||||
|
@@ -28,6 +28,8 @@ class Logger(LoggerBase):
|
||||
self._level = self._log_settings.level
|
||||
self._console = self._log_settings.console
|
||||
|
||||
self.create()
|
||||
|
||||
def _get_datetime_now(self) -> str:
|
||||
try:
|
||||
return datetime.datetime.now().strftime(self._time_format_settings.date_time_format)
|
||||
|
@@ -20,7 +20,6 @@ __version__ = '2020.12.5'
|
||||
from collections import namedtuple
|
||||
|
||||
# imports:
|
||||
from .service_provider import ServiceProvider
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major=2020, minor=12, micro=5)
|
||||
|
@@ -21,7 +21,6 @@ from collections import namedtuple
|
||||
|
||||
# imports:
|
||||
from .service_base import ServiceBase
|
||||
from .service_provider_base import ServiceProviderBase
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major=2020, minor=12, micro=5)
|
||||
|
@@ -1,3 +1,4 @@
|
||||
# imports:
|
||||
from .service_provider import ServiceProvider
|
||||
|
||||
from .service_provider import ServiceProviderBase
|
||||
|
Reference in New Issue
Block a user