PATCH: Fixed jsonifying the SQL output

This commit is contained in:
2025-01-28 19:02:36 +00:00
parent 12c576de2f
commit cbef531b3e
4 changed files with 45 additions and 20 deletions

View File

@@ -19,4 +19,17 @@ class Database:
print(e)
def close_connection(self) -> None:
self._conn.close()
self._conn.close()
def fetch_data_as_list(cursor, query, params=None):
# Execute the query with parameters (if any)
cursor.execute(query, params or [])
# Get the column names from the cursor
columns = [description[0] for description in cursor.description]
# Convert rows to dictionaries
rows = cursor.fetchall()
result = [dict(zip(columns, row)) for row in rows]
return result