Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sql Alchemy before-select event

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

like image 772
Gabriel Filipiak Avatar asked Sep 10 '26 13:09

Gabriel Filipiak


1 Answers

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.

like image 83
Gabriel Filipiak Avatar answered Sep 13 '26 07:09

Gabriel Filipiak