Ejemplo n.º 1
0
def use_simple_names():
    get_col_name = lambda el, *args, **kwargs: str(el.element.name)
    try:
        yield compiles(sql.compiler._CompileLabel)(get_col_name)
    except:
        pass
    finally:
        deregister(sql.compiler._CompileLabel)
Ejemplo n.º 2
0
    def bulk_save_objects_with_replace(self, objects):
        '''
        Like Session.bulk_save_objects, but replaces any whose primary key is
        already present. Only works on SQLite.
        '''

        # https://stackoverflow.com/questions/2218304/sqlalchemy-insert-ignore
        # This is a bit hacky, because the deregister call will remove *all*
        # visitors, not the one we just registered. But I don't see a better
        # way right now.
        def _prefix_insert_with_replace(insert, compiler, **kw):
            return compiler.visit_insert(insert.prefix_with('OR REPLACE'),
                                         **kw)

        compiles(Insert)(_prefix_insert_with_replace)
        try:
            self.bulk_save_objects(objects)
        finally:
            deregister(Insert)
Ejemplo n.º 3
0
 def teardown(self):
     for cls in (Select, BindParameter):
         deregister(cls)