简体   繁体   中英

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. Everything is working fine and I can read/write to the database from the flask app. However, If I make a change through phpmyadmin, this change is not detected by SQLAlchmey. The only to get those changes is by manually refreshing SQLAlchmey connection

My Question is how to tell SQLAlchemy to reload/refresh its Database connection?

To make sure that the SQLAlchemy engine reads the committed changes to the database, you have to set the isolation level :

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)

I suggest you to look at Server Sent Events(SSE). I am looking for code of SSE for postgres,mysql,etc. It is available for reddis.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM