When you’re doing a native SQL query, you’re going to return a list with a tuple inside it and most people would choose to subscript the data in it and that’s not very elegant
results = db.execute("SELECT * FROM book limit 1")
Copy the code
The result is a list of tuples that look like tuples, This is an AbstractKeyedTuple object that has a keys() method, We can take all the keys and we can use this method to turn the query result into a dictionary
data = [dict(zip(result.keys(), result)) for result in results]
Copy the code