apsw
apsw copied to clipboard
Implement C equivalent of sqlite3.Row
From rogerbinns on December 21, 2012 10:48:09
Basically produce a named tuple that can be used as a Row tracer.
Original issue: http://code.google.com/p/apsw/issues/detail?id=137
I know this is an old issue but is there a recommended way to get named column access to results?
There is an example in the tips, making the result be a dictionary:
https://rogerbinns.github.io/apsw/tips.html#customizing-cursors
Do you have a preferred type for return other than a dictionary? I am thinking of updating the doc to show returning named tuple or dataclass
I'm currently creating dataclasses by doing MyClass(*result)
so that would be my preference.
(I'm actually using aiosql to call my queries, so I will have to see whether I can drill down to the cursor for that - but that's not important for this issue.)
The way I am going to proceed is adding an apsw.ext module that has row tracers that can produce dicts, namedtuple, and dataclass. I did a quick proof of concept and found that the hard part is processing the column names to deal with duplicates and renaming (eg keywords like continue
have to be changed to something else). Hopefully in the next release.
Shipped