42 lines
1.1 KiB
Python
42 lines
1.1 KiB
Python
from pydantic_settings import BaseSettings, SettingsConfigDict
|
|
|
|
"""
|
|
pool_pre_ping=True, # Verify connection before using
|
|
pool_size=20, # Maximum number of permanent connections
|
|
max_overflow=10, # Maximum number of additional connections
|
|
pool_recycle=600, # Recycle connections after 1 hour
|
|
pool_timeout=30, # Wait up to 30 seconds for a connection
|
|
echo=True, # Set to True for debugging SQL queries
|
|
"""
|
|
|
|
|
|
class Configs(BaseSettings):
|
|
"""
|
|
Postgresql configuration settings.
|
|
"""
|
|
|
|
DB: str = ""
|
|
USER: str = ""
|
|
PASSWORD: str = ""
|
|
HOST: str = ""
|
|
PORT: str = 0
|
|
ENGINE: str = ""
|
|
POOL_PRE_PING: bool = True
|
|
POOL_SIZE: int = 20
|
|
MAX_OVERFLOW: int = 10
|
|
POOL_RECYCLE: int = 600
|
|
POOL_TIMEOUT: int = 30
|
|
ECHO: bool = True
|
|
|
|
@property
|
|
def url(self):
|
|
"""Generate the database URL."""
|
|
return f"{self.ENGINE}://{self.USER}:{self.PASSWORD}@{self.HOST}:{self.PORT}/{self.DB}"
|
|
|
|
model_config = SettingsConfigDict(env_prefix="POSTGRES_")
|
|
|
|
|
|
postgres_configs = (
|
|
Configs()
|
|
) # singleton instance of the POSTGRESQL configuration settings
|