diff options
-rw-r--r-- | uploader/publications/models.py | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/uploader/publications/models.py b/uploader/publications/models.py index 3fc9542..6034c9e 100644 --- a/uploader/publications/models.py +++ b/uploader/publications/models.py @@ -1,5 +1,6 @@ """Module to handle persistence and retrieval of publication to/from MariaDB""" import logging +from typing import Iterable from MySQLdb.cursors import DictCursor @@ -71,3 +72,11 @@ def update_publications(conn: Connection , publications: tuple[dict, ...]) -> tu return publications return tuple() return tuple() + + +def fetch_publications(conn: Connection) -> Iterable[dict]: + """Fetch publications from the database.""" + with conn.cursor(cursorclass=DictCursor) as cursor: + cursor.execute("SELECT * FROM Publication") + for row in cursor.fetchall(): + yield dict(row) |