mirror of
ssh://git.janware.com/srv/git/janware/proj/jw-python
synced 2026-01-15 09:53:32 +01:00
db.Session: Add
Add database session API to db. This is a breaking change, because from this commit on, a session object has to be passed to every query. This commit also removes any reference to Cmds / App objects. An instantiated database object can be worked with outside of an App. Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
parent
841b5a3391
commit
495cebd769
5 changed files with 56 additions and 31 deletions
|
|
@ -8,6 +8,7 @@ from jwutils.log import *
|
|||
from jwutils.misc import load_classes
|
||||
from jwutils.Cmds import Cmds
|
||||
from jwutils.db.DataBase import DataBase
|
||||
from jwutils.db.Session import Session
|
||||
from jwutils.db.query.QueryResult import QueryResult
|
||||
#from jwutils.db.query.Queries import Queries
|
||||
|
||||
|
|
@ -19,7 +20,7 @@ class Query(abc.ABC): # export
|
|||
# -- pure virtuals
|
||||
|
||||
@abc.abstractmethod
|
||||
def _run(self, *args, **kwargs) -> QueryResult:
|
||||
def _run(self, session: Session, *args, **kwargs) -> QueryResult:
|
||||
raise Exception('Called pure virtual _run()')
|
||||
|
||||
@abc.abstractmethod
|
||||
|
|
@ -40,8 +41,8 @@ class Query(abc.ABC): # export
|
|||
def _add(self, query_name: str, location: str, func: Any):
|
||||
return self.__parent.add(self, query_name, location, func)
|
||||
|
||||
def run(self, *args, **kwargs) -> QueryResult:
|
||||
return self._run(*args, **kwargs)
|
||||
def run(self, session: Session, *args, **kwargs) -> QueryResult:
|
||||
return self._run(session, *args, **kwargs)
|
||||
|
||||
@property
|
||||
def parent(self):
|
||||
|
|
@ -55,10 +56,6 @@ class Query(abc.ABC): # export
|
|||
def schema(self):
|
||||
return self.__parent.db.schema
|
||||
|
||||
@property
|
||||
def app(self) -> Cmds:
|
||||
return self.__parent.app
|
||||
|
||||
@property
|
||||
def column_names(self) -> list[str]:
|
||||
return self._column_names()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue