You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
classDatabasedefquery(
self, sql: str, params: Optional[Union[Iterable, dict]] =None
) ->Generator[dict, None, None]:
""" Execute ``sql`` and return an iterable of dictionaries representing each row. :param sql: SQL query to execute :param params: Parameters to use in that query - an iterable for ``where id = ?`` parameters, or a dictionary for ``where id = :id`` """cursor=self.execute(sql, tuple(paramsortuple()))
try: columns= [c[0] forcincursor.description]
exceptapsw.ExecutionCompleteError: return []
forrowincursor:
yielddict(zip(columns, row))
to:
classDatabase:
defquery(
self, sql: str, params: Optional[Union[Iterable, dict]] =None
) ->Generator[dict, None, None]:
cursor=self.execute(sql, tuple(paramsortuple()))
# Row results will be dataclassescursor.row_trace=apsw.ext.DataClassRowFactory(
dataclass_kwargs={"frozen": True}
)
# Yield attrdict so rows can be accessed as row.id or row['id']forrowincursor: yieldAttrDict(row.__dict__)
# Cleanup the row_tracecursor.row_trace=None
The text was updated successfully, but these errors were encountered:
https://rogerbinns.github.io/apsw/example.html#accessing-results-by-column-name
Right now we return a generator of dictionaries, we want to change to using
AttrDict
to improve the UI. In essence allowing this behavior:Code implementation
As determined from discovery in #7, convert this:
to:
The text was updated successfully, but these errors were encountered: