PATCH: Fixed jsonifying the SQL output
This commit is contained in:
@@ -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
|
||||
Reference in New Issue
Block a user