| """Database connection settings.""" | |
| from functools import lru_cache | |
| from pydantic import Field | |
| from pydantic_settings import BaseSettings, SettingsConfigDict | |
| class DatabaseSettings(BaseSettings): | |
| """PostgreSQL database connection settings.""" | |
| model_config = SettingsConfigDict( | |
| env_prefix="POSTGRES_", | |
| extra="ignore", | |
| ) | |
| host: str = Field(default="localhost") | |
| port: int = Field(default=5432) | |
| user: str = Field(default="agentic_user") | |
| password: str = Field(default="") | |
| db: str = Field(default="agentic_hr") | |
| def url(self) -> str: | |
| """Build database URL.""" | |
| return f"postgresql://{self.user}:{self.password}@{self.host}:{self.port}/{self.db}" | |
| def psycopg2_url(self) -> str: | |
| """Build database URL with psycopg2 driver.""" | |
| return f"postgresql+psycopg2://{self.user}:{self.password}@{self.host}:{self.port}/{self.db}" | |
| def async_url(self) -> str: | |
| """Build async database URL for SQLAlchemy async.""" | |
| return f"postgresql+asyncpg://{self.user}:{self.password}@{self.host}:{self.port}/{self.db}" | |
| def get_database_settings() -> DatabaseSettings: | |
| """Get cached database settings.""" | |
| return DatabaseSettings() | |