3 ms·
Not only are the ORM objects typed, the query results are typed too. Last time I checked on 2.0 progress there wasn't a feasible way to implement this, so I'm
by luhn 4y ago
Not only are the ORM objects typed, the query results are typed too. Last time I checked on 2.0 progress there wasn't a feasible way to implement this, so I'm thrilled to see that it made the release.
# (variable) stmt: Select[Tuple[int, str]]
stmt = select(User.id, User.name)
with Session(e) as sess:
for row in sess.execute(stmt):
# (variable) row: Row[Tuple[int, str]]
print(row)
# (variable) users: Sequence[User]
users = sess.scalars(select(User)).all()
# (variable) users_legacy: List[User]
users_legacy = sess.query(User).all()
https://docs.sqlalchemy.org/en/20/changelog/whatsnew_20.html#typing-is-supported-from-step-3-onwards https://docs.sqlalchemy.org/en/20/changelog/whatsnew_20.html...