21 lines
581 B
Python
21 lines
581 B
Python
|
from pydantic_settings import BaseSettings, SettingsConfigDict
|
||
|
from pydantic import PositiveInt, computed_field, MySQLDsn
|
||
|
from pydantic_core import Url
|
||
|
|
||
|
|
||
|
class Configs(BaseSettings):
|
||
|
HOST: str
|
||
|
PORT: PositiveInt
|
||
|
DATABASE: str
|
||
|
USER: str
|
||
|
PASSWORD: str
|
||
|
|
||
|
@computed_field
|
||
|
def DB_URI(self) -> MySQLDsn:
|
||
|
return Url(
|
||
|
f"mysql+aiomysql://{self.USER}:{self.PASSWORD}@{self.HOST}:{self.PORT}/{self.DATABASE}?charset=utf8mb4"
|
||
|
)
|
||
|
|
||
|
model_config = SettingsConfigDict(env_file='.env', env_file_encoding='utf-8')
|
||
|
|
||
|
configs = Configs()
|