if you can make just a single "ascii()" stored procedure, then you can
say:
query(Client).filter(func.ascii("foo") == "bar")
or you can combine those
def ascii(arg):
return func.to_ascii(func.convert_to(arg, "latin2"))
otherwise you can use ext.compiler:
from sqlalchemy.sql.expression import Function
from sqlalchemy.ext.compiler import compiles
class ascii_op(Function):
def __init__(self, val, enc='latin2'):
self.val = val
self.enc = enc
@compiles(ascii_op)
def compile_ascii_op(element, compiler, **kw):
return "to_ascii(convert_to(%(val)s,'%(enc)s'), '%(enc)s')" %
element.__dict__