b0503baac5
2. callcenter 프로젝트 제작중
23 lines
596 B
Python
23 lines
596 B
Python
from sqlalchemy import create_engine
|
|
from sqlalchemy.orm import DeclarativeBase, sessionmaker
|
|
from pathlib import Path
|
|
|
|
Path("db").mkdir(parents=True, exist_ok=True)
|
|
|
|
# echo sql 구문 출력시키는
|
|
engine = create_engine('sqlite:///db/callcenter.db', echo=True)
|
|
|
|
# 세션 팩토리 생성
|
|
SessionLocal = sessionmaker(bind=engine, autoflush=False, autocommit=False)
|
|
|
|
# Base = declarative_Base()
|
|
class Base(DeclarativeBase):
|
|
pass
|
|
|
|
# session 을 다른 모듈에서 사용할 수 있도록 제공
|
|
def get_db():
|
|
db = SessionLocal()
|
|
try:
|
|
yield db
|
|
finally:
|
|
db.close() |