Improved session reference
This commit is contained in:
parent
03ba1d1847
commit
9662584560
@ -1,7 +1,7 @@
|
|||||||
from abc import abstractmethod, ABC
|
from abc import abstractmethod, ABC
|
||||||
|
|
||||||
from sqlalchemy import engine
|
from sqlalchemy import engine
|
||||||
from sqlalchemy.orm import session
|
from sqlalchemy.orm import Session
|
||||||
|
|
||||||
|
|
||||||
class DatabaseConnectionBase(ABC):
|
class DatabaseConnectionBase(ABC):
|
||||||
@ -15,7 +15,7 @@ class DatabaseConnectionBase(ABC):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def session(self) -> session: pass
|
def session(self) -> Session: pass
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def connect(self, connection_string: str): pass
|
def connect(self, connection_string: str): pass
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
from sqlalchemy import engine, create_engine
|
from sqlalchemy import engine, create_engine
|
||||||
from sqlalchemy.orm import session, sessionmaker
|
from sqlalchemy.orm import Session, sessionmaker
|
||||||
|
|
||||||
from sh_edraft.database.connection.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.database.model.database_settings import DatabaseSettings
|
||||||
@ -16,7 +16,7 @@ class DatabaseConnection(DatabaseConnectionBase):
|
|||||||
self._db_settings = database_settings
|
self._db_settings = database_settings
|
||||||
|
|
||||||
self._engine: Optional[engine] = None
|
self._engine: Optional[engine] = None
|
||||||
self._session: Optional[session] = None
|
self._session: Optional[Session] = None
|
||||||
self._credentials: Optional[str] = None
|
self._credentials: Optional[str] = None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@ -24,7 +24,7 @@ class DatabaseConnection(DatabaseConnectionBase):
|
|||||||
return self._engine
|
return self._engine
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def session(self) -> session:
|
def session(self) -> Session:
|
||||||
return self._session
|
return self._session
|
||||||
|
|
||||||
def connect(self, connection_string: str):
|
def connect(self, connection_string: str):
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
from abc import abstractmethod
|
from abc import abstractmethod
|
||||||
|
|
||||||
from sqlalchemy import engine
|
from sqlalchemy import engine
|
||||||
from sqlalchemy.orm import session
|
from sqlalchemy.orm import Session
|
||||||
|
|
||||||
from sh_edraft.service.base.service_base import ServiceBase
|
from sh_edraft.service.base.service_base import ServiceBase
|
||||||
|
|
||||||
@ -18,7 +18,7 @@ class DatabaseContextBase(ServiceBase):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def session(self) -> session: pass
|
def session(self) -> Session: pass
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def connect(self, connection_string: str): pass
|
def connect(self, connection_string: str): pass
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
from sqlalchemy import engine, Table
|
from sqlalchemy import engine, Table
|
||||||
from sqlalchemy.orm import session
|
from sqlalchemy.orm import Session
|
||||||
|
|
||||||
from sh_edraft.database.connection.database_connection import DatabaseConnection
|
from sh_edraft.database.connection.database_connection import DatabaseConnection
|
||||||
from sh_edraft.database.connection.base.database_connection_base import DatabaseConnectionBase
|
from sh_edraft.database.connection.base.database_connection_base import DatabaseConnectionBase
|
||||||
@ -22,7 +22,7 @@ class DatabaseContext(DatabaseContextBase):
|
|||||||
return self._db.engine
|
return self._db.engine
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def session(self) -> session:
|
def session(self) -> Session:
|
||||||
return self._db.session
|
return self._db.session
|
||||||
|
|
||||||
def create(self):
|
def create(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user