Is there a way to conditionally add filter arguments to a query in ORM SQL Alchemy?
For example, imagine I have the following:
q = session.query(X) if a: q.filter(Xy == 'a') elif b: q.filter(Xy == 'a', Xz == 'b') elif c: q.filter(Xy == 'a', Xp == 'd')
Is there any way to say just add
Xz == 'b' if b
without reading (Xy == 'a') in each filter.
It seems like I could do
q.filter(Xy == 'a').filter(Xy == 'b')
but this changes the running query.
source share