Coverage for fastid / database / config.py: 100%

13 statements  

« prev     ^ index     » next       coverage.py v7.13.1, created at 2026-10-18 16:37 +0000

1from typing import Any 

2 

3from pydantic import AliasChoices, Field, PositiveInt 

4from pydantic_settings import SettingsConfigDict 

5 

6from fastid.core.schemas import ENV_PREFIX, BaseSettings 

7 

8 

9class DBSettings(BaseSettings): 

10 url: str = Field( 

11 validation_alias=AliasChoices( 

12 f"{ENV_PREFIX}db_url", 

13 f"{ENV_PREFIX}test_db_url", 

14 ), 

15 ) 

16 echo: bool = False 

17 

18 # --- pool settings --- 

19 pool_size: PositiveInt = Field(default=20) 

20 max_overflow: int = Field(default=40, ge=0) 

21 pool_recycle: int = Field(default=3600, ge=0) 

22 pool_timeout: int = Field(default=30, ge=0) 

23 pool_pre_ping: bool = Field(default=True) 

24 

25 # --- connect_args (asyncpg) --- 

26 server_settings: dict[str, Any] = Field(default_factory=lambda: {"application_name": "fastid", "timezone": "UTC"}) 

27 

28 # --- asyncpg timeouts --- 

29 connect_timeout: PositiveInt | None = Field(default=10) 

30 command_timeout: PositiveInt | None = Field(default=60) 

31 

32 model_config = SettingsConfigDict(env_prefix=f"{ENV_PREFIX}db_") 

33 

34 

35db_settings = DBSettings()