I've created an application using the declarative extension to the ORM and I'm trying to auto-generate parts of my documentation. Using the stdlib's inspect.getsource() I can recover the class definitions and using sqlalchemy.schema.CreateTable() I can get most of my DB schema.
My application has triggers which are generated by an "after_create" event.listen. I'm not sure how to get at these using SQLAlchemy reflection. Is this doable or is the event only ever fired once (and any thing I'd try would be too late)? I've read that SQLAlchemy reflection doesn't handle triggers in the general case, but I'm hoping it may be doable in this case since the trigger is created within DDL(). Thanks, Michael SQAlchemy 0.8.1; Python 2.7.3 Minimal example: #### Setup from sqlalchemy import Column, event, DDL, Integer, String, create_engine from sqlalchemy.ext.declarative import declarative_base Base = declarative_base() class SomeClass(Base): __tablename__ = 'my_table' id = Column(Integer, primary_key = True) name = Column(String, nullable = False) loud_name = Column(String, nullable = True) event.listen( SomeClass.__table__, "after_create", DDL(""" CREATE TRIGGER ensure_loud_name AFTER INSERT ON %(table)s BEGIN UPDATE %(table)s SET loud_name = upper(name) WHERE loud_name IS NULL; END; """ )) engine = create_engine('sqlite:///:memory:', echo = True) Base.metadata.create_all(engine) #### Reflection ## Class definition import inspect print inspect.getsource(SomeClass) ## DB Table from sqlalchemy.schema import CreateTable print CreateTable(SomeClass.__table__).compile(engine) ## How to get the trigger? -- 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 sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at http://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.