Files
xian_algorithm_new/app/config/database_config.py
T
2026-05-05 19:49:12 +08:00

38 lines
953 B
Python

"""
数据库配置
"""
from .base_config import BaseConfig
class DatabaseConfig(BaseConfig):
"""数据库配置类"""
# PostgreSQL配置
DB_HOST: str = "localhost"
DB_PORT: int = 5432
DB_USER: str = "postgres"
DB_PASSWORD: str = "postgres"
DB_NAME: str = "test_db"
# 连接池配置
DB_POOL_SIZE: int = 10
DB_MAX_OVERFLOW: int = 20
DB_POOL_TIMEOUT: int = 30
DB_POOL_RECYCLE: int = 3600
@property
def DATABASE_URL(self) -> str:
"""构建数据库连接URL"""
return (
f"postgresql://{self.DB_USER}:{self.DB_PASSWORD}"
f"@{self.DB_HOST}:{self.DB_PORT}/{self.DB_NAME}"
)
@property
def ASYNC_DATABASE_URL(self) -> str:
"""构建异步数据库连接URL"""
return (
f"postgresql+asyncpg://{self.DB_USER}:{self.DB_PASSWORD}"
f"@{self.DB_HOST}:{self.DB_PORT}/{self.DB_NAME}"
)