From d65523fd0713cebc1aefcbf87df931bd64eb7cb5 Mon Sep 17 00:00:00 2001 From: Bartlomiej Hirsz Date: Sun, 5 Nov 2023 18:37:16 +0100 Subject: [PATCH] Refactor returnAsDict query mode --- src/DatabaseLibrary/query.py | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/src/DatabaseLibrary/query.py b/src/DatabaseLibrary/query.py index 927031d..e4e4ccf 100644 --- a/src/DatabaseLibrary/query.py +++ b/src/DatabaseLibrary/query.py @@ -63,18 +63,9 @@ def query(self, selectStatement, sansTran=False, returnAsDict=False): logger.info("Executing : Query | %s " % selectStatement) self.__execute_sql(cur, selectStatement) allRows = cur.fetchall() - if returnAsDict: - mappedRows = [] col_names = [c[0] for c in cur.description] - - for rowIdx in range(len(allRows)): - d = {} - for colIdx in range(len(allRows[rowIdx])): - d[col_names[colIdx]] = allRows[rowIdx][colIdx] - mappedRows.append(d) - return mappedRows - + return [dict(zip(col_names, row)) for row in allRows] return allRows finally: if cur: