Spaces:
Runtime error
Runtime error
Update app/database.py
Browse files- app/database.py +7 -1
app/database.py
CHANGED
|
@@ -3,11 +3,17 @@ from sqlalchemy.orm import sessionmaker, DeclarativeBase
|
|
| 3 |
from .config import Settings, build_database_url
|
| 4 |
|
| 5 |
settings = Settings()
|
|
|
|
| 6 |
|
| 7 |
class Base(DeclarativeBase):
|
| 8 |
pass
|
| 9 |
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
SessionLocal = sessionmaker(bind=engine, autoflush=False, autocommit=False)
|
| 12 |
|
| 13 |
def get_db():
|
|
|
|
| 3 |
from .config import Settings, build_database_url
|
| 4 |
|
| 5 |
settings = Settings()
|
| 6 |
+
db_url = build_database_url(settings)
|
| 7 |
|
| 8 |
class Base(DeclarativeBase):
|
| 9 |
pass
|
| 10 |
|
| 11 |
+
engine_kwargs = {"echo": False, "pool_pre_ping": True}
|
| 12 |
+
if db_url.startswith("sqlite"):
|
| 13 |
+
# Uvicorn / FastAPI でスレッド跨ぎが起きても問題ないように
|
| 14 |
+
engine_kwargs["connect_args"] = {"check_same_thread": False}
|
| 15 |
+
|
| 16 |
+
engine = create_engine(db_url, **engine_kwargs)
|
| 17 |
SessionLocal = sessionmaker(bind=engine, autoflush=False, autocommit=False)
|
| 18 |
|
| 19 |
def get_db():
|