首页 > 数据库技术 > 详细

dynamically creating a set of SQLAlchemy table

时间:2015-08-14 19:46:15      阅读:190      评论:0      收藏:0      [点我收藏+]

if you want to create multiple table objects, you could create a function to generate and return a new class. Maybe something like this:


Base = declarative_base()

def TableCreator(tablename):
    class MyTable(Base):
        __tablename__ = tablename
        row_id = Column(INT, primary_key=True)
        another_column = Column(CHAR(10))
    return MyTable



Then you could call it with mytable1 = TableCreator("mytable1").

dynamically creating a set of SQLAlchemy table

原文:http://my.oschina.net/u/2007546/blog/492513

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!