40 lines
852 B
Python
40 lines
852 B
Python
"""
|
|
C-Stone Invoice Check — Datenbankkonfiguration
|
|
SQLAlchemy Engine und Session Management
|
|
"""
|
|
|
|
import os
|
|
from sqlalchemy import create_engine
|
|
from sqlalchemy.orm import sessionmaker, declarative_base
|
|
from dotenv import load_dotenv
|
|
|
|
# Load environment variables
|
|
load_dotenv()
|
|
|
|
DATABASE_URL = os.getenv(
|
|
"DATABASE_URL",
|
|
"postgresql://postgres:postgres@localhost:5432/invoice_check"
|
|
)
|
|
|
|
# Engine erstellen
|
|
engine = create_engine(
|
|
DATABASE_URL,
|
|
echo=False, # SQL-Logging (False für Production)
|
|
pool_pre_ping=True, # Verbindungs-Check
|
|
pool_size=10,
|
|
max_overflow=20
|
|
)
|
|
|
|
# Session
|
|
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
|
|
|
|
# Base für Models
|
|
Base = declarative_base()
|
|
|
|
# Dependency für FastAPI
|
|
def get_db():
|
|
db = SessionLocal()
|
|
try:
|
|
yield db
|
|
finally:
|
|
db.close()
|