I'm working on an application which uses Flask, SQLAlchemy and PostgreSQL. I've to write a transaction that executes multiple queries on the database.
def exec_query_1():
with db.engine.connect() as connection:
connection.execute(#some-query)
def exec_query_2():
with db.engine.connect() as connection:
connection.execute(#some-query)
def exec_query_3():
with db.engine.connect() as connection:
connection.execute(#some-query)
def execute_transaction():
with db.engine.connect() as connection:
with connection.begin() as transaction:
exec_query_1()
exec_query_2()
exec_query_3()
Given that the application is multithreaded, will this code work as expected? If yes, how? If no, what would be the right approach to make it work?