Mercurial > libervia-backend
comparison libervia/backend/memory/sqla.py @ 4270:0d7bb4df2343
Reformatted code base using black.
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 19 Jun 2024 18:44:57 +0200 |
parents | 5f2d496c633f |
children | 1ef32316a55e |
comparison
equal
deleted
inserted
replaced
4269:64a85ce8be70 | 4270:0d7bb4df2343 |
---|---|
213 | 213 |
214 db_config = sqla_config.get_db_config() | 214 db_config = sqla_config.get_db_config() |
215 engine = create_async_engine( | 215 engine = create_async_engine( |
216 db_config["url"], | 216 db_config["url"], |
217 future=True, | 217 future=True, |
218 json_serializer=lambda obj: json.dumps(obj, ensure_ascii=False) | 218 json_serializer=lambda obj: json.dumps(obj, ensure_ascii=False), |
219 ) | 219 ) |
220 | 220 |
221 new_base = not db_config["path"].exists() | 221 new_base = not db_config["path"].exists() |
222 if new_base: | 222 if new_base: |
223 log.info(_("The database is new, creating the tables")) | 223 log.info(_("The database is new, creating the tables")) |
1776 self, | 1776 self, |
1777 client: SatXMPPEntity, | 1777 client: SatXMPPEntity, |
1778 type_: Optional[NotificationType] = None, | 1778 type_: Optional[NotificationType] = None, |
1779 status: Optional[NotificationStatus] = None, | 1779 status: Optional[NotificationStatus] = None, |
1780 requires_action: Optional[bool] = None, | 1780 requires_action: Optional[bool] = None, |
1781 min_priority: Optional[int] = None | 1781 min_priority: Optional[int] = None, |
1782 ) -> List[Notification]: | 1782 ) -> List[Notification]: |
1783 """Retrieve all notifications for a given profile with optional filters. | 1783 """Retrieve all notifications for a given profile with optional filters. |
1784 | 1784 |
1785 @param client: client associated with the notifications. | 1785 @param client: client associated with the notifications. |
1786 @param type_: filter by type of the notification. | 1786 @param type_: filter by type of the notification. |
1788 @param requires_action: filter by notifications that require user action. | 1788 @param requires_action: filter by notifications that require user action. |
1789 @param min_priority: filter by minimum priority value. | 1789 @param min_priority: filter by minimum priority value. |
1790 @return: list of matching Notification instances. | 1790 @return: list of matching Notification instances. |
1791 """ | 1791 """ |
1792 profile_id = self.profiles[client.profile] | 1792 profile_id = self.profiles[client.profile] |
1793 filters = [or_(Notification.profile_id == profile_id, Notification.profile_id.is_(None))] | 1793 filters = [ |
1794 or_(Notification.profile_id == profile_id, Notification.profile_id.is_(None)) | |
1795 ] | |
1794 | 1796 |
1795 if type_: | 1797 if type_: |
1796 filters.append(Notification.type == type_) | 1798 filters.append(Notification.type == type_) |
1797 if status: | 1799 if status: |
1798 filters.append(Notification.status == status) | 1800 filters.append(Notification.status == status) |
1801 if min_priority: | 1803 if min_priority: |
1802 filters.append(Notification.priority >= min_priority) | 1804 filters.append(Notification.priority >= min_priority) |
1803 | 1805 |
1804 async with self.session() as session: | 1806 async with self.session() as session: |
1805 result = await session.execute( | 1807 result = await session.execute( |
1806 select(Notification) | 1808 select(Notification).where(and_(*filters)).order_by(Notification.id) |
1807 .where(and_(*filters)) | |
1808 .order_by(Notification.id) | |
1809 ) | 1809 ) |
1810 return result.scalars().all() | 1810 return result.scalars().all() |
1811 | 1811 |
1812 @aio | 1812 @aio |
1813 async def delete_notification( | 1813 async def delete_notification( |