Files
TK-BOM-Project/backend/app/database.py
Hyungi Ahn eaf31bf754 feat: SQLAlchemy 모델 및 스키마 파일 생성 완료
- database.py: PostgreSQL 연결 설정 및 세션 관리
- models.py: Project, File, Material SQLAlchemy 모델 정의
- schemas.py: Pydantic 요청/응답 스키마 정의
- 완전한 데이터베이스 연동 구조 완성
2025-07-14 12:09:09 +09:00

25 lines
607 B
Python

from sqlalchemy import create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker
import os
# 데이터베이스 URL
DATABASE_URL = "postgresql://tkmp_user:tkmp_password_2025@localhost:5432/tk_mp_bom"
# SQLAlchemy 엔진 생성
engine = create_engine(DATABASE_URL)
# 세션 팩토리 생성
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
# Base 클래스 생성
Base = declarative_base()
# 데이터베이스 의존성 함수
def get_db():
db = SessionLocal()
try:
yield db
finally:
db.close()