From 2b8fd63af18e70b4c8c20a34a6dfa041e8a832b9 Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Fri, 2 Feb 2024 05:17:50 +0300 Subject: Bug: Specify DictCursor class to return dict-like result Without specifying the `cursorclass`, the result is a tuple of the form: ((query_col01_val, query_col02_val, ...), ...) where the ellipsis specify the possibility of more than one of the previous form. We specify the DictCursor class instead so that the form changes to: ({query_col01_name: query_col01_val, ...}, ...) which allows us to pick the value we want with a string index. --- qc_app/db/populations.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'qc_app/db') diff --git a/qc_app/db/populations.py b/qc_app/db/populations.py index 0bcbe5d..06ae773 100644 --- a/qc_app/db/populations.py +++ b/qc_app/db/populations.py @@ -28,7 +28,7 @@ def populations_by_species(conn: mdb.Connection, speciesid) -> tuple: def save_population(conn: mdb.Connection, population_details: dict) -> dict: """Save the population details to the db.""" - with conn.cursor() as cursor: + with conn.cursor(cursorclass=DictCursor) as cursor: cursor.execute("SELECT MAX(Id) AS last_id FROM InbredSet") new_id = cursor.fetchone()["last_id"] + 1 cursor.execute( -- cgit v1.2.3