我正在查看一些代码,它有条件地创建一个查询对象,然后查看查询结果。例如:
query = self.session.query(Person).filter(Person.last_name == "Jones") #line 1
#some other logic
query = query.filter(Person.title == "VP Sales") #line 3
#some other logic
query.first() #line 5
查询语句何时实际命中数据库?理想情况下,只有在需要使用查询结果时(例如第5行)才运行查询。
我尝试查看SQLAlchemy文档(https://docs.sqlalchemy.org/en/13/orm/query.html),但未能找到此信息。