Update _session to session

This commit is contained in:
Matthias
2023-02-16 08:51:32 +00:00
parent 47b66f3220
commit e59eaf33e0
3 changed files with 9 additions and 7 deletions

View File

@@ -54,10 +54,12 @@ def init_db(db_url: str) -> None:
# https://docs.sqlalchemy.org/en/13/orm/contextual.html#thread-local-scope
# Scoped sessions proxy requests to the appropriate thread-local session.
# We should use the scoped_session object - not a seperately initialized version
Trade._session = scoped_session(sessionmaker(bind=engine, autoflush=False))
Trade.query = Trade._session.query_property()
Order.query = Trade._session.query_property()
PairLock.query = Trade._session.query_property()
Trade.session = scoped_session(sessionmaker(bind=engine, autoflush=False))
Order.session = Trade.session
PairLock.session = Trade.session
Trade.query = Trade.session.query_property()
Order.query = Trade.session.query_property()
PairLock.query = Trade.session.query_property()
previous_tables = inspect(engine).get_table_names()
ModelBase.metadata.create_all(engine)