diff options
author | Frederick Muriuki Muriithi | 2025-04-11 14:59:49 -0500 |
---|---|---|
committer | Frederick Muriuki Muriithi | 2025-04-11 15:18:53 -0500 |
commit | 5eddcada30e8d6bbc4631103ae3fd96bdc6b134b (patch) | |
tree | 07e9c5a91de11dd37f7787bb1793a8277bb98aff /uploader/publications/models.py | |
parent | 70ecf94d8629d75dfa6ef295ddd18c0f4aa622f8 (diff) | |
download | gn-uploader-5eddcada30e8d6bbc4631103ae3fd96bdc6b134b.tar.gz |
Move code to fetch phenotype publications from DB to publications package.
Diffstat (limited to 'uploader/publications/models.py')
-rw-r--r-- | uploader/publications/models.py | 15 |
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()) |