Is possible to mapping view with class using mapper in SqlAlchemy?

前端 未结 2 699
感情败类
感情败类 2020-12-05 06:18

As Mentioned here I created View.

Is following possible to create view class for using with session?

v = Table(\'viewname\', metadata, autoload=True)         


        
2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-05 06:45

    Finally I found it.

    We can create class for sql view's. Here is simple example.

    class ViewName(Base):
        __table__ = Table('viewname', Base.metadata,
            Column('id', Integer, primary_key=True),
            Column('foreign_key', Integer, ForeignKey('sometablename.id'),
                autoload=True, autoload_with=engine
            )
    

    That's it. We can access "viewname" table using ViewName class.

    Thank you for all who are respond me.

提交回复
热议问题