SQLAlchemy introspect column type with inheritance

前端 未结 3 502
自闭症患者
自闭症患者 2021-02-12 15:06

Considering this code (and using SQLAlchemy 0.7.7):

class Document(Base):
    __tablename__ = \'document\'
    __table_args__ = {
        \'schema\': \'app\'
            


        
3条回答
  •  我在风中等你
    2021-02-12 15:52

    The ORM has allowed you to define classes in an inheritance pattern that corresponds to a JOIN of two tables. This structure is full service, and can also be used to find out basic things like the types of attributes on columns, pretty much directly:

    type = Arrete.date.property.columns[0].type
    

    note that this is basically the same thing as the approach of trudging through __bases__, except you let Python's normal class mechanics do the work.

提交回复
热议问题