I want to execute the same SQL query from different processes by SQLAlchemy. As I understand I must create new Session in every process. So for each new session I must recreate query:
session.query(...).filter(...)
etc.
It seems logical to save fully formed query separately from session. And then only apply this query to each session:
new_session.query(old_saved_query)
Is it possible? Or there is some other way?
You can use with_session
:
query = session.query(...).filter(...)
query.with_session(new_session)
It is also possible to create a query without a bound session:
from sqlalchemy.orm import Query
query = Query(...).filter(...)
query.with_session(session)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With