SQL炼金术之前选择事件 [英] Sql Alchemy before-select event

查看:49
本文介绍了SQL炼金术之前选择事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究SQL Alchemy,在SQLA执行select语句之前,我需要做一些工作.因此,我发现最好的方法是使用SQLA事件,但是我找不到合适的事前选择事件.在那儿,但是我很难找到.

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?

感谢任何建议.此致加布(Gabe)

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.

所以我要做的是编写自己的Session类:

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 :)

致谢

P.s.感谢所有对此问题做出贡献的人.

P.s. Thanks everybody who contributed in this question.

这篇关于SQL炼金术之前选择事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆