Files
group_xinghuo_jinrong/app/config/database.py
T
zhanghongyu_0626 3995cb44d8 Implement authentication and chat functionality with JWT support
- Added `auth.py` for mock login and JWT issuance.
- Introduced `chat.py` for handling chat requests with role-based access control.
- Enhanced `main.py` to include new routers and middleware for tracing.
- Implemented input validation in `input_guard.py` to prevent SQL injection.
- Created repositories for managing agent sessions and audit logs.
- Added exception handling for authorization errors.
- Updated settings to include JWT configuration.
- Introduced tests for authentication and input validation.
2026-09-07 17:20:42 +08:00

28 lines
732 B
Python

"""MySQL / Redis 连接工厂。"""
from functools import lru_cache
from sqlalchemy import create_engine
from sqlalchemy.engine import Engine
from app.config.settings import settings
def _mysql_url(database: str) -> str:
pwd = settings.mysql_password
auth = f"{settings.mysql_user}:{pwd}" if pwd else settings.mysql_user
return (
f"mysql+pymysql://{auth}@{settings.mysql_host}:{settings.mysql_port}"
f"/{database}?charset=utf8mb4"
)
@lru_cache
def get_agent_engine() -> Engine:
return create_engine(_mysql_url(settings.mysql_database), pool_pre_ping=True)
@lru_cache
def get_core_engine() -> Engine:
return create_engine(_mysql_url(settings.mysql_core_database), pool_pre_ping=True)