comparison sat/memory/sqla.py @ 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 9e1a993ad1bf
comparison
equal deleted inserted replaced
3595:7510648e8e3a 3596:2d97c695af05
184 for c in result.scalars(): 184 for c in result.scalars():
185 self.components[c.profile_id] = c.entry_point 185 self.components[c.profile_id] = c.entry_point
186 186
187 self.initialized.callback(None) 187 self.initialized.callback(None)
188 188
189 ## Generic
190
191 @aio
192 async def add(self, db_obj: DeclarativeMeta) -> None:
193 """Add an object to database"""
194 async with self.session() as session:
195 async with session.begin():
196 session.add(db_obj)
197
198 @aio
199 async def delete(self, db_obj: DeclarativeMeta) -> None:
200 """Delete an object from database"""
201 async with self.session() as session:
202 async with session.begin():
203 await session.delete(db_obj)
204 await session.commit()
205
189 ## Profiles 206 ## Profiles
190 207
191 def getProfilesList(self) -> List[str]: 208 def getProfilesList(self) -> List[str]:
192 """"Return list of all registered profiles""" 209 """"Return list of all registered profiles"""
193 return list(self.profiles.keys()) 210 return list(self.profiles.keys())