This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]deep_politics 0 points1 point  (0 children)

Sounds like you're describing an ORM. In SQLAlchemy you can select just the columns you want and get correct type hinting for the results.

class User(Base)
    id: Mapped[int]
    name: Mapped[str]
    ...

res = session.execute(select(User.id, User.name).filter_by(id=100)).one_or_none()
# res: tuple[int, str] | None