Hi guys.
Is there any mechanism in SQLAlchemy which allows to redefine operator
compilation? I want to the same thing as already exists for functions.
An example for functions:
class IntDiv(GenericFunction):
type = Integer
package = 'adc_custom'
name = 'div'
identifier = 'div'
@compiles(IntDiv)
def visit_div_default(element, compiler, **kwargs):
params = [compiler.process(c.self_group()) for c in
element.clause_expr.element.get_children()]
return '%s / %s' % (params[0], params[1])
@compiles(IntDiv, 'clickhouse')
def visit_div_ch(element, compiler, **kwargs):
return 'intDiv(%s)' % compiler.process(element.clause_expr.element)
What I want to do:
class BitAdd(CustomOp):
pass
@compiles(BitAdd)
def visit_bit_add_default(element, compiler, **kwargs):
return '%s & %s' % (element.left, element.right)
@compiles(IntDiv, 'clickhouse')
def visit_bit_add_ch(element, compiler, **kwargs):
return 'bitAnd(%s, %s)' % (element.left, element.right)
Statement looks like that:
some_col.op('&')(some_int_flag)
I understand that I can define generic function and use it instead of
`.op('&')`, but at first I want to find another way.
--
SQLAlchemy -
The Python SQL Toolkit and Object Relational Mapper
http://www.sqlalchemy.org/
To post example code, please provide an MCVE: Minimal, Complete, and Verifiable
Example. See http://stackoverflow.com/help/mcve for a full description.
---
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.