I am playing around with SQL Alchemy and I need to do some work before SQLA executes select statement. So I figured out that the best way would be to use SQLA Event, but I cant find a suitable before-select event. Is it there but I am poor at finding.
If its not there, can somebody tell me how to write my custom event?
Thx for any suggestions. Best Regards Gabe
So sorry for not writing for a while but some while ago I did what I wanted to do. I don`t no if it is an elegant way but it works.
So what I did is writing my own Session class:
class MySession(Session):
def execute(self, clause, params=None, mapper=None, **kw):
# Your magic with clause here
return Session.execute(self, clause, params, mapper)
Then you need to create your session like this:
Session = sessionmaker(engine, class_ = MySession)
Hope that it will help someone who struggled with similar issue :)
Regards
P.s. Thanks everybody who contributed in this question.
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