Using sessionmaker to avoid thread issues
This commit is contained in:
parent
d0918ae953
commit
226c7be5a2
2 changed files with 9 additions and 3 deletions
|
|
@ -97,7 +97,7 @@ def get_plays(session: Session) -> list[play_classes.Play]:
|
|||
|
||||
assert len(list(filter(lambda x: x == None, played_boardgame_ids))) == 0, plays_from_db
|
||||
|
||||
get_multiple_boardgames(get_db_session(), played_boardgame_ids + played_expansion_ids)
|
||||
get_multiple_boardgames(session, played_boardgame_ids + played_expansion_ids)
|
||||
|
||||
return plays_from_db
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
from sqlmodel import create_engine, SQLModel, Session, select
|
||||
from src.config import definitions
|
||||
from typing import Union
|
||||
from sqlalchemy.orm import sessionmaker, scoped_session
|
||||
|
||||
from src.classes import boardgame_classes, play_classes
|
||||
|
||||
|
|
@ -8,10 +9,15 @@ sqlite_url = definitions.SQLITE_URL
|
|||
|
||||
|
||||
connect_args = {"check_same_thread": False}
|
||||
engine = create_engine(sqlite_url, echo=True, connect_args=connect_args)
|
||||
engine = create_engine(sqlite_url, echo=False, connect_args=connect_args)
|
||||
|
||||
db_session = scoped_session(sessionmaker(autocommit=False,
|
||||
autoflush=True,
|
||||
bind=engine,
|
||||
class_=Session))
|
||||
|
||||
def get_session():
|
||||
with Session(engine) as session:
|
||||
with db_session() as session:
|
||||
return session
|
||||
|
||||
def add_boardgame(session: Session, boardgame: Union[
|
||||
|
|
|
|||
Loading…
Reference in a new issue