This really boils down to questions like Can I assign values in RowProxy using the sqlalchemy? and their recommendation of just casting results to dict
.
I want to assign values on the result rows and I am mostly using SQLAlchemy, with raw sql, for its brilliant multi-RDBMS support (with some use of introspection too).
Basically, a lot of my selects look like
results = connection.execute("select foo from bar where zoom = ?", binds)
results = [dict(row) for row in results]
But it would be even better if I could just specify a different result class, like plain old dict
, either when initiating the connection, or on execute. Probably faster too, as well as more convenient.
I took a look at https://docs.sqlalchemy.org/en/latest/core/engines.html and at the source of sqlalchemy.engine.result and it looks like _process_row
on the ResultProxy
classes is where RowProxy
gets registered. But I saw no way to modify that through the API.
I realize this an edge case compared to ORM use, but I really can't use ORM in my case. It's perfectly fine if it's not possible, just don't want to overlook something already included.