mirror of
https://github.com/grillazz/fastapi-sqlalchemy-asyncpg.git
synced 2025-11-30 13:20:40 +03:00
refactor: simplify postgresql env vars
This commit is contained in:
@@ -21,10 +21,10 @@ class Settings(BaseSettings):
|
||||
JWT_ALGORITHM: str
|
||||
JWT_EXPIRE: int
|
||||
|
||||
SQL_USER: str
|
||||
SQL_PASS: str
|
||||
SQL_HOST: str
|
||||
SQL_DB: str
|
||||
POSTGRES_USER: str
|
||||
POSTGRES_PASSWORD: str
|
||||
POSTGRES_HOST: str
|
||||
POSTGRES_DB: str
|
||||
|
||||
@computed_field
|
||||
@property
|
||||
@@ -57,20 +57,20 @@ class Settings(BaseSettings):
|
||||
|
||||
The URL is built using the MultiHostUrl.build method, which takes the following parameters:
|
||||
- scheme: The scheme of the URL. In this case, it is "postgresql+asyncpg".
|
||||
- username: The username for the SQL database, retrieved from the SQL_USER environment variable.
|
||||
- password: The password for the SQL database, retrieved from the SQL_PASS environment variable.
|
||||
- host: The host of the SQL database, retrieved from the SQL_HOST environment variable.
|
||||
- path: The path of the SQL database, retrieved from the SQL_DB environment variable.
|
||||
- username: The username for the Postgres database, retrieved from the POSTGRES_USER environment variable.
|
||||
- password: The password for the Postgres database, retrieved from the POSTGRES_PASSWORD environment variable.
|
||||
- host: The host of the Postgres database, retrieved from the POSTGRES_HOST environment variable.
|
||||
- path: The path of the Postgres database, retrieved from the POSTGRES_DB environment variable.
|
||||
|
||||
Returns:
|
||||
PostgresDsn: The constructed PostgresDsn URL for asyncpg.
|
||||
"""
|
||||
return MultiHostUrl.build(
|
||||
scheme="postgresql+asyncpg",
|
||||
username=self.SQL_USER,
|
||||
password=self.SQL_PASS,
|
||||
host=self.SQL_HOST,
|
||||
path=self.SQL_DB,
|
||||
username=self.POSTGRES_USER,
|
||||
password=self.POSTGRES_PASSWORD,
|
||||
host=self.POSTGRES_HOST,
|
||||
path=self.POSTGRES_DB,
|
||||
)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user