From 5eddcada30e8d6bbc4631103ae3fd96bdc6b134b Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Fri, 11 Apr 2025 14:59:49 -0500 Subject: Move code to fetch phenotype publications from DB to publications package. --- uploader/publications/models.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 uploader/publications/models.py (limited to 'uploader/publications/models.py') 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()) -- cgit v1.2.3