Files
hunjing/backend/app/core/config/database_config.py
T
2026-08-21 16:00:13 +08:00

28 lines
1.1 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""数据库配置:SQLite / PostgreSQL 连接参数。"""
from __future__ import annotations
from typing import Literal
from pydantic_settings import BaseSettings
class DatabaseConfig(BaseSettings):
"""数据库配置。
本地开发默认使用 SQLite(``aiosqlite``);正式环境通过 ``DATABASE_TYPE=pgsql``
切换到 PostgreSQL(``asyncpg``)。``DATABASE_URL`` 优先级最高,可直接覆盖。
"""
database_type: Literal["sqlite", "pgsql"] = "sqlite" # 数据库类型
sqlite_database_path: str = "../db/hunjing.sqlite3" # SQLite 数据库路径(相对 backend)
database_url: str = "" # 自定义数据库连接 URL(优先级最高)
postgres_host: str = "127.0.0.1" # PostgreSQL 主机
postgres_port: int = 5432 # PostgreSQL 端口
postgres_db: str = "hunjing" # PostgreSQL 数据库名
postgres_user: str = "hunjing" # PostgreSQL 用户名
postgres_password: str = "change-me" # PostgreSQL 密码
postgres_ssl: bool = False # 是否启用 SSL
postgres_pool_size: int = 10 # 连接池大小
postgres_max_overflow: int = 20 # 连接池最大溢出连接数