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

2024-04-20 14:35:38 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在为一个web应用程序使用multi-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之间有什么不同呢?你知道吗


Tags: 数据库falseurldbbindsessioncreateengine