From 8222b37c9510a21ff40d2837d823b1cb50f70734 Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Fri, 21 Jul 2023 08:37:13 +0300 Subject: Update a Publication in the database. --- gn3/db/phenotypes.py | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'gn3/db/phenotypes.py') diff --git a/gn3/db/phenotypes.py b/gn3/db/phenotypes.py index 009dc1a..b42118a 100644 --- a/gn3/db/phenotypes.py +++ b/gn3/db/phenotypes.py @@ -151,3 +151,13 @@ def fetch_publication_by_pubmed_id(conn: DBConnection, pubmed_id: int) -> dict: "WHERE PubMed_Id=%(pubmed_id)s"), {"pubmed_id": pubmed_id}) return cursor.fetchone() + +def update_publication(conn, data=dict) -> int: + """Update the publication with the given data.""" + updatable_cols = ", ".join(f"{publication_mapping[col]}=%({col})s" + for col in data + if col not in ("id_", "id")) + with conn.cursor(cursorclass=DictCursor) as cursor: + cursor.execute( + f"UPDATE Publication SET {updatable_cols} WHERE Id=%(id_)s", data) + return cursor.rowcount -- cgit v1.2.3