Changed DatabaseConnection
This commit is contained in:
		@@ -1 +1 @@
 | 
			
		||||
 | 
			
		||||
# imports:
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,8 @@
 | 
			
		||||
from abc import abstractmethod
 | 
			
		||||
 | 
			
		||||
from sqlalchemy import engine
 | 
			
		||||
from sqlalchemy.orm import session
 | 
			
		||||
 | 
			
		||||
from sh_edraft.service.base.service_base import ServiceBase
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@@ -9,5 +12,13 @@ class DatabaseConnectionBase(ServiceBase):
 | 
			
		||||
    def __init__(self):
 | 
			
		||||
        ServiceBase.__init__(self)
 | 
			
		||||
 | 
			
		||||
    @property
 | 
			
		||||
    @abstractmethod
 | 
			
		||||
    def use_mysql(self, connection_string: str): pass
 | 
			
		||||
    def engine(self) -> engine: pass
 | 
			
		||||
 | 
			
		||||
    @property
 | 
			
		||||
    @abstractmethod
 | 
			
		||||
    def session(self) -> session: pass
 | 
			
		||||
 | 
			
		||||
    @abstractmethod
 | 
			
		||||
    def connect(self, connection_string: str): pass
 | 
			
		||||
 
 | 
			
		||||
@@ -21,9 +21,17 @@ class DatabaseConnection(DatabaseConnectionBase):
 | 
			
		||||
 | 
			
		||||
        self.create()
 | 
			
		||||
 | 
			
		||||
    @property
 | 
			
		||||
    def engine(self) -> engine:
 | 
			
		||||
        return self._engine
 | 
			
		||||
 | 
			
		||||
    @property
 | 
			
		||||
    def session(self) -> session:
 | 
			
		||||
        return self._session
 | 
			
		||||
 | 
			
		||||
    def create(self): pass
 | 
			
		||||
 | 
			
		||||
    def use_mysql(self, connection_string: str):
 | 
			
		||||
    def connect(self, connection_string: str):
 | 
			
		||||
        try:
 | 
			
		||||
            self._engine = create_engine(connection_string)
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -40,7 +40,7 @@ class Program(ApplicationBase):
 | 
			
		||||
        db_settings: DatabaseSettings = self._configuration.get_configuration(DatabaseSettings)
 | 
			
		||||
        self._services.add_singleton(DatabaseConnectionBase, DatabaseConnection)
 | 
			
		||||
        db: DatabaseConnectionBase = self._services.get_service(DatabaseConnectionBase)
 | 
			
		||||
        db.use_mysql(CredentialManager.build_string(db_settings.connection_string, db_settings.credentials))
 | 
			
		||||
        db.connect(CredentialManager.build_string(db_settings.connection_string, db_settings.credentials))
 | 
			
		||||
 | 
			
		||||
        # Add and create logger
 | 
			
		||||
        self._services.add_singleton(LoggerBase, Logger)
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user