changeset 3596:2d97c695af05

core (memory/sqla): generic methods to add and delete ORM objects directly
author Goffi <goffi@goffi.org>
date Thu, 29 Jul 2021 22:51:01 +0200
parents 7510648e8e3a
children 5d108ce026d7
files sat/memory/sqla.py
diffstat 1 files changed, 17 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/sat/memory/sqla.py	Thu Jul 29 22:51:01 2021 +0200
+++ b/sat/memory/sqla.py	Thu Jul 29 22:51:01 2021 +0200
@@ -186,6 +186,23 @@
 
         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]: