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
|
||||
|
||||
Reference in New Issue
Block a user