SQLAlchemy ORM - SQLAlchemy Object Lifecycle (2)

One way that a flush occurs is when you call query. Calling query on a model flushes the pending changes and adds them to the session so that when you call a .all() or .first(), those pending changes get translated into SQL statements.

请添加图片描述
请添加图片描述

  • A flush takes pending changes, and translates them into commands ready to be committed. It occurs.
  • when you call Query. Or on db.session.commit()

A commit leads to persisted changes on the database + lets the db.session start with a new transaction.

When a statement has been flushed already, SQLAlchemy knows not to do the work again of translating actions to SQL statements.

猜你喜欢

转载自blog.csdn.net/BSCHN123/article/details/121313483