Black Lives Matter. Please consider donating to Black Girls Code today.

How to update database cursor as a global variable?

I have a database connection set up with psycopg2 which is used in a couple different app pages. I can import the cursor and do SQL queries without problems, but sometimes the connection cuts off, so I need a button to create a new connection. However, to my understanding, callback functions can’t change the global variable value across other pages.

What is the best solution to this? With dataframes I can simply convert it to a json as a hidden div, but I can’t do the same with SQL cursors.