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:
Jan Lindemann 2025-03-10 18:44:39 +01:00
commit 495cebd769
5 changed files with 56 additions and 31 deletions

View file

@ -24,8 +24,8 @@ class Queries(abc.ABC): # export
# -- implement API
def _run(self, *args, **kwargs) -> QueryResult:
return self.__func(*args, **kwargs)
def _run(self, session, *args, **kwargs) -> QueryResult:
return self.__func(session, *args, **kwargs)
def _register(self):
raise Exception('Can\'t call register on this object')
@ -57,10 +57,6 @@ class Queries(abc.ABC): # export
def db(self) -> DataBase:
return self.__db
@property
def app(self) -> Cmds:
return self.__db.app
def load(self, modules: list[str], cls=QueryBase):
for path in modules:
slog(INFO, f'Loading modules from {path}')