carcost/api/database.py
yuany3721 71e11eaf30 feat: Add OIDC authentication with Authentik and refactor project structure
Backend:
- Add auth.py for JWT token verification
- Update main.py to protect all routes with auth middleware
- Remove dashboard router (frontend handles aggregation)
- Add Docker support with Dockerfile and docker-compose.yml

Frontend:
- Add OIDC authentication using oidc-client-ts with PKCE flow
- Create router.js with auth guards for automatic login/logout
- Add api.js for unified Axios instance with auth headers
- Add composables: useAuth.js, useVehicleData.js for caching
- Add views/Main.vue as main application page
- Simplify App.vue to router-view container
- Add deploy-web.sh deployment script

Documentation:
- Update AGENTS.md with new architecture and auth flow
2026-04-12 13:31:27 +08:00

34 lines
730 B
Python

from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker, Session
from config import settings
# 创建数据库引擎
engine = create_engine(
settings.DATABASE_URL,
echo=settings.DEBUG,
pool_pre_ping=True,
pool_size=5,
max_overflow=10,
)
# 创建会话工厂
SessionLocal = sessionmaker(bind=engine)
def get_session() -> Session:
"""获取新的数据库会话
使用示例:
session = get_session()
try:
result = session.query(Model).all()
session.commit()
return result
except Exception:
session.rollback()
raise
finally:
session.close()
"""
return SessionLocal()