search

Home  >  Q&A  >  body text

python - SQLAlchemy 中的使用 flush() 和 commit() 有什么区别

commit()flush() 实现的功能都一样,为什么两个要写两种,有什么特殊的区别呢?

PHP中文网PHP中文网2804 days ago875

reply all(2)I'll reply

  • 伊谢尔伦

    伊谢尔伦2017-04-17 13:42:32

    Who said these two things have the same function?
    In SQLAlchemy, a Session (can be regarded as) is a transaction. Each operation (basically) corresponds to one or more SQL statements. These SQL statements need to be sent to the database server to be actually executed, and the entire transaction needs to be committed to really take effect. , if not submitted, once your program hangs, all uncommitted transactions will be rolled back to the state before the transaction started.
    Flush is to send the SQL statements that the client has not sent to the database server, and commit is to tell the database server to commit the transaction.
    Simply put, you can see the effect in this Session after flushing, and you can see the effect in other Sessions after committing.

    reply
    0
  • PHP中文网

    PHP中文网2017-04-17 13:42:32

    The functions are different.
    Simply put:
    Flush pre-commit is equal to being submitted to the database memory and has not yet been written to the database file;
    Commit means writing the contents in the memory directly, and you can provide queries;

    reply
    0
  • Cancelreply