From e3e097af4b92173e2bcb4771ccd1360fbe0e8cf6 Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Mon, 2 Jun 2025 12:24:33 -0500 Subject: Parametrize the "DataId" column for different tables. --- uploader/phenotypes/models.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'uploader/phenotypes/models.py') diff --git a/uploader/phenotypes/models.py b/uploader/phenotypes/models.py index 3e749c0..eb926d8 100644 --- a/uploader/phenotypes/models.py +++ b/uploader/phenotypes/models.py @@ -327,9 +327,12 @@ def save_phenotypes_data( ) -> tuple[dict, ...]: """Save new phenotypes data into the database.""" _table_details = { - "PublishData": {"table": "PublishData", "valueCol": "value"}, - "PublishSE": {"table": "PublishSE", "valueCol": "error"}, - "NStrain": {"table": "PublishData", "valueCol": "count"} + "PublishData": { + "table": "PublishData", "valueCol": "value", "DataIdCol": "Id"}, + "PublishSE": { + "table": "PublishSE", "valueCol": "error", "DataIdCol": "DataId"}, + "NStrain": { + "table": "PublishData", "valueCol": "count", "DataIdCol": "DataId"} }[table] saved_data = tuple() with conn.cursor(cursorclass=DictCursor) as cursor: @@ -341,7 +344,7 @@ def save_phenotypes_data( cursor.executemany( (f"INSERT INTO {_table_details['table']}" - f"(Id, StrainId, {_table_details['valueCol']}) " + f"({_table_details['DataIdCol']}, StrainId, {_table_details['valueCol']}) " "VALUES " f"(%(data_id)s, %(sample_id)s, %({_table_details['valueCol']})s) " "RETURNING *"), -- cgit v1.2.3