Closed PGijsbers closed 9 months ago
Through infamiliarity with SQLAlchemy we now fetch column names of a table and then construct dictionaries with the returned row values. SQLAlchemy will already return the column name meta data and correctly map them; use the .mappings method of the CursorResult object. See also https://docs.sqlalchemy.org/en/20/changelog/migration_14.html#rationale-to-behave-more-like-a-named-tuple-rather-than-a-mapping.
SQLAlchemy
.mappings
CursorResult
Alternatively, I could embrace the named tuples returned by rows, but I don't feel it works that well since the drawbacks are mostly identical (except immutability, but we are building up objects here so I don't know if that's desired).
Also, use .fetch_one() when we expect only a single result.
.fetch_one()
Through infamiliarity with
SQLAlchemy
we now fetch column names of a table and then construct dictionaries with the returned row values.SQLAlchemy
will already return the column name meta data and correctly map them; use the.mappings
method of theCursorResult
object. See also https://docs.sqlalchemy.org/en/20/changelog/migration_14.html#rationale-to-behave-more-like-a-named-tuple-rather-than-a-mapping.Alternatively, I could embrace the named tuples returned by rows, but I don't feel it works that well since the drawbacks are mostly identical (except immutability, but we are building up objects here so I don't know if that's desired).