aboutsummaryrefslogtreecommitdiff
path: root/uploader/publications/models.py
diff options
context:
space:
mode:
Diffstat (limited to 'uploader/publications/models.py')
-rw-r--r--uploader/publications/models.py20
1 files changed, 4 insertions, 16 deletions
diff --git a/uploader/publications/models.py b/uploader/publications/models.py
index 7d2862d..b199991 100644
--- a/uploader/publications/models.py
+++ b/uploader/publications/models.py
@@ -1,6 +1,6 @@
"""Module to handle persistence and retrieval of publication to/from MariaDB"""
import logging
-from typing import Iterable
+from typing import Iterable, Optional
from MySQLdb.cursors import DictCursor
@@ -42,15 +42,10 @@ def create_new_publications(
"%(pubmed_id)s, %(abstract)s, %(authors)s, %(title)s, "
"%(journal)s, %(volume)s, %(pages)s, %(month)s, %(year)s"
") "
- "ON DUPLICATE KEY UPDATE "
- "Abstract=VALUES(Abstract), Authors=VALUES(Authors), "
- "Title=VALUES(Title), Journal=VALUES(Journal), "
- "Volume=VALUES(Volume), Pages=VALUES(pages), "
- "Month=VALUES(Month), Year=VALUES(Year) "
"RETURNING *"),
publications)
return tuple({
- **row, "PublicationId": row["Id"]
+ **row, "publication_id": row["Id"]
} for row in cursor.fetchall())
return tuple()
@@ -74,20 +69,13 @@ def update_publications(conn: Connection , publications: tuple[dict, ...]) -> tu
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)
-
-
def fetch_publication_by_id(conn: Connection, publication_id: int) -> dict:
"""Fetch a specific publication from the database."""
with conn.cursor(cursorclass=DictCursor) as cursor:
cursor.execute("SELECT * FROM Publication WHERE Id=%s",
(publication_id,))
- return dict(cursor.fetchone())
+ _res = cursor.fetchone()
+ return dict(_res) if _res else {}
def fetch_publication_phenotypes(