diff options
author | Frederick Muriuki Muriithi | 2025-04-28 02:08:57 -0500 |
---|---|---|
committer | Frederick Muriuki Muriithi | 2025-04-28 02:08:57 -0500 |
commit | 77f18b73276d2bf57b52703b48e3b44b3c89c516 (patch) | |
tree | 78a25eaa3f04a6503d7f3a114770e86aa9c82e83 /uploader/publications/models.py | |
parent | a962991759349c152cfc03293f5ce413be9be9d2 (diff) | |
download | gn-uploader-77f18b73276d2bf57b52703b48e3b44b3c89c516.tar.gz |
Fetch *ALL* publications from the database.
Diffstat (limited to 'uploader/publications/models.py')
-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) |