user-defined compileable statements ?

Issue #958 resolved
Mike Bayer repo owner created an issue

this is kind of a silly idea:

class MyReplaceStatement(expression.CompileableStatement):
    def __init__(self, table):
        self.table = table

    def compile(self, compiler):
        keys = compiler.column_keys
        compiler.isinsert = True
        bindparams = [type_=self.table.c[key](bindparam(key,).type) for key in keys]
        return 'REPLACE INTO %s(%s) VALUES (%s)' %
        (
                self.table.name,
                ','.join(self.table.c[key](key).name for key in keys),
                ','.join(compiler.process(b) for b in bindparams))
        )

connection.execute(MyReplaceStatement(sometable), foo='bar')

Comments (3)

  1. Mike Bayer reporter
    • changed milestone to 0.6.0

    with the addition of DDL constructs to the compiler system, a public method of extending the compilation of new types of expression and schema constructs (such as AlterTable for migrate usage) should be added. I think it should be along the lines of people creating Compiler-like classes of their own which can somehow be registered along with the built in compilers. Multiple compilers without awareness of each other also would need to be supported, so that plugins from multiple libraries can coexist.

  2. Log in to comment