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.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/uploader/publications/models.py b/uploader/publications/models.py
new file mode 100644
index 0000000..89da06c
--- /dev/null
+++ b/uploader/publications/models.py
@@ -0,0 +1,15 @@
+"""Module to handle persistence and retrieval of publication to/from MariaDB"""
+
+def fetch_phenotype_publications(
+ conn, ids: tuple[tuple[int, int], ...]) -> tuple[dict, ...]:
+ """Fetch publication from database by ID."""
+ paramstr = ",".join(["(%s, %s)"] * len(ids))
+ query = (
+ "SELECT "
+ "pxr.PhenotypeId, pxr.Id AS xref_id, pxr.PublicationId, pub.PubMed_ID "
+ "FROM PublishXRef AS pxr INNER JOIN Publication AS pub "
+ "ON pxr.PublicationId=pub.Id "
+ f"WHERE (pxr.PhenotypeId, pxr.Id) IN ({paramstr})")
+ with conn.cursor(cursorclass=DictCursor) as cursor:
+ cursor.execute(query, tuple(item for row in ids for item in row))
+ return tuple(dict(row) for row in cursor.fetchall())