如何为Web应用程序使用多SQLAlchemy会话?

时间:2016-06-02 12:41:15

标签: python mysql sqlalchemy

我正在为Web应用程序使用多个mysql数据库。对于每个数据库,我想使用单独的SQLAlchemy会话。

这就是我的所作所为:

engine1 = create_engine(DB_URL_1)
db_session1 = scoped_session(sessionmaker(autocommit=False,
                                         autoflush=False,
                                         bind=engine1))
engine2 = create_engine(DB_URL_2)
db_session2 = scoped_session(sessionmaker(autocommit=False,
                                         autoflush=False,
                                         bind=engine2))

是不是?是否有更好的方法来制作它?

normal sessionscoped session之间有什么不同?

0 个答案:

没有答案