add thread_safe - required for sqlite

This commit is contained in:
hay-kot 2021-04-27 16:09:41 -08:00 committed by Antoine Bertin
commit f65f718333
No known key found for this signature in database
GPG key ID: 09851B52754E2327

View file

@ -1,16 +1,16 @@
from pathlib import Path
import sqlalchemy as sa
from mealie.db.models.model_base import SqlAlchemyBase
from sqlalchemy.orm import sessionmaker
def sql_global_init(db_url: str):
thread_safe = True
if "sqlite" in db_url:
thread_safe = False
engine = sa.create_engine(
db_url,
echo=False,
connect_args={"check_same_thread": thread_safe},
)
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
return SessionLocal
return sessionmaker(autocommit=False, autoflush=False, bind=engine)