简体   繁体   English

使用SQLAlcehmy的Flask App:如何检测提交给数据库的外部更改?

[英]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.

相关问题 如何使用 sqlalchemy 在 flask 应用程序的现有数据库中添加新表? - How to add new table in existing database of flask app using sqlalchemy? Flask测试期间如何回滚数据库更改 - How to rollback database changes during Flask testing 如何让Flask检测静态文件中的更改? - How do you get Flask to detect changes in static files? 使用Flask应用程序中的Flask-SQLAlchemy使用Alembic检测对models.py的更改 - Detect changes to models.py using Alembic with Flask-SQLAlchemy in Flask Application 如何使用flask运行Connextion / Flask应用程序? - How to run a Connextion/Flask app using flask? 在Flask应用中使用测试peewee数据库实例 - Using a test peewee database instance in a Flask app 使用uwsgi在服务器上的Flask应用程序上进行更改后没有任何反应 - Nothing happen after made changes on Flask app in server using uwsgi 如何使用 SQLAlchemy 在 Flask 应用程序中初始化 Postgresql 数据库 - How to initialize a Postgresql database in a Flask app with SQLAlchemy 如何有效地提交 Flask 或 Bottle 应用程序中的数据库更改? - How to commit DB changes in a Flask or Bottle app efficiently? 如何拥有一个跟踪数据库更改的外部脚本? - How can I have an external script that tracks changes in database?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM