Spaces:
Sleeping
Sleeping
File size: 596 Bytes
7858910 4408369 45e75f8 7858910 45e75f8 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker, declarative_base
from app.config import settings
# SQLiteかどうか検知
is_sqlite = settings.DATABASE_URL.startswith("sqlite+")
engine = create_engine(
settings.DATABASE_URL,
pool_pre_ping=not is_sqlite,
future=True,
connect_args={"check_same_thread": False} if is_sqlite else {},
)
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine, future=True)
Base = declarative_base()
def get_db():
db = SessionLocal()
try:
yield db
finally:
db.close()
|