diff options
author | Frederick Muriuki Muriithi | 2023-07-21 08:37:13 +0300 |
---|---|---|
committer | Frederick Muriuki Muriithi | 2023-07-21 08:47:04 +0300 |
commit | 8222b37c9510a21ff40d2837d823b1cb50f70734 (patch) | |
tree | b32b4c7774cfcfa0c5f38778343664f58ba71244 | |
parent | 8ab276d489c121c9f53bf9b55e20188acb744ea3 (diff) | |
download | genenetwork3-8222b37c9510a21ff40d2837d823b1cb50f70734.tar.gz |
Update a Publication in the database.
-rw-r--r-- | gn3/db/phenotypes.py | 10 |
1 files changed, 10 insertions, 0 deletions
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 |