openml / server-api

Python-based server
https://openml.github.io/server-api/
BSD 3-Clause "New" or "Revised" License
1 stars 1 forks source link

Get mapping objects directly through `rows.mappings()` #106

Closed PGijsbers closed 9 months ago

PGijsbers commented 11 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.

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).

PGijsbers commented 10 months ago

Also, use .fetch_one() when we expect only a single result.