所以我想知道是否有人可以帮助我。
我目前有一些课程
class Sha1(ColumnClause):
pass
@compiles(Sha1)
def compile_sha1(element, compiler, **kw):
return 'PASSWORD("{}")'.format(element.name)
当我使用SQLAlchemy orm插入列时,我可以将该属性作为Sha1(值)传递,并让它做它的事情。但是出于测试目的,我们将模型加载到类似
的数据库中insert = model.__table__.insert(values)
session.execute(insert)
在sqlalchemy中,有没有办法覆盖特定模型的sql生成方式,以便它将改变生成的输出
insert into model (uuid, password) values (:uuid, :password)
使用我的Sha1类
insert into model (uuid, password) values (:uuid, PASSWORD(:password))
有什么想法吗?
答案 0 :(得分:0)
有一个更新的功能允许这个称为bind_expression()
。如果我理解正确,您可能想要更改Sha1
以接受任意元素,您不再需要显式调用Sha1
,在这种情况下,参数将始终为{{1 }}:
BindParam