Am 08.07.2018 um 19:23 schrieb Justin Pryzby:
Memory use should be a nonissue for iterators, right?
Right, the switch to iterators makes it less necessary to have different
methods for different result types.
The question is then which type we should use as the row type for the
iterator. It should be possible to represent every kind of database row
and convert that type to a (named) tuple, and a dict.
The problem with named tuples is that they do not allow all column names
as attribute names (e.g. Python keywords or names with special
characters which are allowed in the database, but not in Python).
So we would need dicts, or actually ordered dicts, which can be
converted to tuples in proper order.
We could add attribute access, like so:
class Row(OrderedDict):
def __getattr__(self, key):
try:
return object.__getattribute__(self, key)
except AttributeError:
try:
return self[key]
except KeyError:
raise AttributeError(key)
One problem with the attribute access is that a few attribute names are
used by dicts, e.g. "items" or "popitem". So if a row has a column named
"items", you would not be able to retrieve that column as row.items. But
that is a rare case we must probably put up with.
We could also beef up that base class to support access using integer
indices or even slices. And we should probably make it immutable.
We would end up with something like the RowProxy type of SQLAlchemy.
Maybe we can copy some ideas from there.
-- Christoph
_______________________________________________
PyGreSQL mailing list
PyGreSQL@vex.net
https://mail.vex.net/mailman/listinfo.cgi/pygresql