From 99b824ed5d4b61a4e5cc35e8fe0367366773cfaf Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Mon, 14 Apr 2025 09:37:45 -0500 Subject: Return created objects with their IDs --- uploader/publications/models.py | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/uploader/publications/models.py b/uploader/publications/models.py index f36c800..37c1df6 100644 --- a/uploader/publications/models.py +++ b/uploader/publications/models.py @@ -1,7 +1,9 @@ """Module to handle persistence and retrieval of publication to/from MariaDB""" +from MySQLdb.cursors import DictCursor from gn_libs.mysqldb import Connection + def fetch_phenotype_publications( conn: Connection, ids: tuple[tuple[int, int], ...] @@ -40,15 +42,9 @@ def create_new_publications( "Title=VALUES(Title), Journal=VALUES(Journal), " "Volume=VALUES(Volume), Pages=VALUES(pages), " "Month=VALUES(Month), Year=VALUES(Year) " - "RETURNING "), + "RETURNING *"), publications) - - paramstr = ", ".join(["%s"] * len(pubmed_ids)) - cursor.execute( - ("SELECT Id, PubMed_ID FROM Publication " - f"WHERE PubMed_ID IN ({paramstr})"), - pubmed_ids) - return { - row["PubMed_ID"]: row["Id"] for row in cursor.fetchall() - } - return {} + return tuple({ + **row, "PublicationId": row["Id"] + } for row in cursor.fetchall()) + return tuple() -- cgit v1.2.3