primary_key=True) name = sa.Column(sa.String()) 在SQLAlchemy 1.4 / 2.0中,ORM的session.query成语与SQLAlchemy核心select函数*相统一,因此为了获取所有的Foo foos = session.execute(Foo).scalars().all() 而不是 foos = sessi
>>> from sqlalchemy.orm import selectin_polymorphic >>> loader_opt = selectin_polymorphic(Employee, [Manager, Engineer]) >>> stmt = select(Employee).order_by(Employee.id).options(loader_opt) >>> objects = session.scalars(stmt).all() BEGIN (implicit) SELECT employee.id, employee.name, em...
>>> from sqlalchemy import select >>> stmt = select(Manager).order_by(Manager.id) >>> managers = session.scalars(stmt).all() BEGIN (implicit) SELECT manager.id, employee.id AS id_1, employee.name, employee.type, employee.company_id, manager.manager_name FROM employee JOIN manager ON ...
(joinedload(User.addresses)).order_by(User.id)) .unique() .all() ) # select() has ORM-ish methods like from_statement() that only work # if the statement is against ORM entities users = ( session.execute(select(User).from_statement(text("select * from users"))) .scalars() .all(...