From 53a77a4c713614d74ec40a8a6c357161aff02804 Mon Sep 17 00:00:00 2001 From: Goffi Date: Thu, 29 Jul 2021 22:51:01 +0200 Subject: [PATCH] core (memory/sqla): generic methods to add and delete ORM objects directly --- sat/memory/sqla.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/sat/memory/sqla.py b/sat/memory/sqla.py index 09e88e07..01ab2cf7 100644 --- a/sat/memory/sqla.py +++ b/sat/memory/sqla.py @@ -186,6 +186,23 @@ class Storage: self.initialized.callback(None) + ## Generic + + @aio + async def add(self, db_obj: DeclarativeMeta) -> None: + """Add an object to database""" + async with self.session() as session: + async with session.begin(): + session.add(db_obj) + + @aio + async def delete(self, db_obj: DeclarativeMeta) -> None: + """Delete an object from database""" + async with self.session() as session: + async with session.begin(): + await session.delete(db_obj) + await session.commit() + ## Profiles def getProfilesList(self) -> List[str]: