33 lines
1020 B
Python
33 lines
1020 B
Python
from functools import lru_cache
|
|
from typing import Optional
|
|
from os import getenv
|
|
from pydantic import BaseSettings, PostgresDsn
|
|
|
|
class Settings(BaseSettings):
|
|
database_url: Optional[PostgresDsn]
|
|
|
|
@lru_cache
|
|
def get_settings() -> Settings:
|
|
settings = Settings() # type: ignore
|
|
|
|
# if (db := getenv("POSTGRES_DB")) is not None:
|
|
# # settings.database_url = PostgresDsn.build(
|
|
# # scheme="postgresql",
|
|
# # user=settings.database_url.user,
|
|
# # password=settings.database_url.password,
|
|
# # host=settings.database_url.host,
|
|
# # port=settings.database_url.port,
|
|
# # path=f"/{db}",
|
|
# # )
|
|
# settings.database_url = PostgresDsn.build(
|
|
# scheme="postgresql",
|
|
# user='barbie',
|
|
# password='redStar4,1',
|
|
# host='localhost',
|
|
# port='5432',
|
|
# path=f"/{db}",
|
|
# )
|
|
if (db := getenv("CONNECTION_STRING")) is not None:
|
|
settings.database_url = getenv("CONNECTION_STRING")
|
|
|
|
return settings |