SQLAlchemyで動的にテーブルを作る2
うーん、いいのかなぁー。もっとリファレンス読まないと。。。
Create
engine = sqlalchemy.create_engine(engine_str, echo=True) def create_test_table(table_name): test_info = TestInfo.__table__ test_info.name = table_name test_info.create(engine) tablename = 'test001' create_test_table(tablename)
Insert
TestInfo.__table__.name = 'test001'
info = TestInfo(info_name, description)
db_session.add(info)
db_session.commit()
Query
TestInfo.__table__.name = 'test001' for row in db_session.query(TestInfo).all(): print row