results.dicts() method, closes #2414

This commit is contained in:
Simon Willison 2024-09-01 17:20:41 -07:00
commit 92c4d41ca6
6 changed files with 28 additions and 17 deletions

View file

@ -677,6 +677,9 @@ class Results:
else:
raise MultipleValues
def dicts(self):
return [dict(row) for row in self.rows]
def __iter__(self):
return iter(self.rows)

View file

@ -277,8 +277,7 @@ class RowUpdateView(BaseView):
results = await resolved.db.execute(
resolved.sql, resolved.params, truncate=True
)
rows = list(results.rows)
result["row"] = dict(rows[0])
result["row"] = results.dicts()[0]
await self.ds.track_event(
UpdateRowEvent(

View file

@ -558,7 +558,7 @@ class TableInsertView(BaseView):
),
args,
)
result["rows"] = [dict(r) for r in fetched_rows.rows]
result["rows"] = fetched_rows.dicts()
else:
result["rows"] = rows
# We track the number of rows requested, but do not attempt to show which were actually