[英]Flask App using SQLAlcehmy: How to detect external changes committed to the database?
I have PhpMyAdmin to view and edit a database and a Flask + SQLAlchemy app that uses a table from this database. 我有PhpMyAdmin来查看和编辑数据库,以及使用此数据库中的表的Flask + SQLAlchemy应用程序。 Everything is working fine and I can read/write to the database from the flask app. 一切正常,我可以从flask应用程序读取/写入数据库。 However, If I make a change through phpmyadmin, this change is not detected by SQLAlchmey. 但是,如果我通过phpmyadmin进行更改,则SQLAlchmey无法检测到此更改。 The only to get those changes is by manually refreshing SQLAlchmey connection 唯一获得这些更改的方法是通过手动刷新SQLAlchmey连接
My Question is how to tell SQLAlchemy to reload/refresh its Database connection? 我的问题是如何告诉SQLAlchemy重新加载/刷新其数据库连接?
To make sure that the SQLAlchemy engine reads the committed changes to the database, you have to set the isolation level : 为了确保SQLAlchemy引擎读取对数据库提交的更改,您必须设置隔离级别:
engine = create_engine(
"mysql://scott:tiger@localhost/test",
isolation_level="READ UNCOMMITTED"
)
You can read more about isolation levels here and here is the official guide for SQLAlchemy docs (See fist Item) 您可以在此处阅读有关隔离级别的更多信息,这是SQLAlchemy文档的官方指南(请参见第一项)
I suggest you to look at Server Sent Events(SSE). 我建议您查看服务器发送事件(SSE)。 I am looking for code of SSE for postgres,mysql,etc. 我正在寻找Postgres,mysql等的SSE代码。 It is available for reddis. 它可用于reddis。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.