How can I query model objects with async Sqlalchemy?

Viewed 137

I'm trying the new asyncio features Sqlalchemy offers. I'm finding it quite frustrating. Before I could use

session.query(
  objects.User,
).filter(...)

to query a user objects with all of its fields populated.

With asyncio I have to do

result await db.execute(
  sqlalchemy.select(objects.User).filter(...)
)
result.all()

result.all() returns Row objects which appear to be just a list of lists with all the values of the model in no particular order. I can get at the data using protected attributes like list(row)[0]._mapping['country_id']. The whole thing just feels very cumbersome and not as clean as when I got model objects back. Is there any way to get models in asyncio land?

I don't want to submit a code review where I'm doing object._mapping['field_name'] everywhere and I'll have a hard time selling this to my team.

0 Answers
Related