In SQLAlchemy, how do I define an event to fire DDL using declarative syntax?

前端 未结 2 1928
自闭症患者
自闭症患者 2020-12-16 05:45

This example shows how to use it with \"non-declarative\" - http://docs.sqlalchemy.org/en/latest/core/ddl.html#sqlalchemy.schema.DDL

How can I use it with the ORM

2条回答
  •  不知归路
    2020-12-16 06:34

    It should be the same with "non-declarative" and "declarative".

    You register your event by specifying (with your class and the doc's event & function) :

    event.listen(TableXYZ, 'before_create', DDL('DROP TRIGGER users_trigger'))
    

    Syntax is something like:

    event.listen(Class, 'name_of_event', function)
    

提交回复
热议问题