deptmatch-api / backend /database.py
maninglearchine's picture
feat: 금융공시 크롤링 + BGE-M3 부서 자동 매칭 서비스 초기 커밋
12f85b6
Raw
History Blame Contribute Delete
700 Bytes
from pathlib import Path
from sqlalchemy import create_engine
from sqlalchemy.orm import DeclarativeBase, sessionmaker
from .config import settings
_db_path = settings.DATABASE_URL.replace("sqlite:///", "")
Path(_db_path).parent.mkdir(parents=True, exist_ok=True)
engine = create_engine(
settings.DATABASE_URL,
connect_args={"check_same_thread": False},
echo=False,
)
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
class Base(DeclarativeBase):
pass
def create_tables():
from . import models # noqa: F401
Base.metadata.create_all(bind=engine)
def get_db():
db = SessionLocal()
try:
yield db
finally:
db.close()