python - Can you extend SQLAlchemy Query class and use different ones in the same session? -
i using sql alchemy orm , have classes/tables each of may have custom queries. let's say, want add table fruit
filtering possibility called with_seed
giving me fruits seeds, , table cutlery
filtering method is_sharp
giving me sharp cutlery. want define these filters extensions query
object, , want use them in same transaction:
def delete_sharp_cutlery_and_seedy_fruits(session_factory): session = session_factory() session.query(fruit).with_seed().delete(synchronize_session='fetch') session.query(cutlery).is_sharp().delete(synchronize_session='fetch') session.commit()
is possible?
this related question here. solution there requires different sessions created different query classes.
you can pass session query constructor
customquery(entities=[fruit], session=session).with_seed().delete(synchronize_session='fetch')
Comments
Post a Comment