mirror of
https://github.com/grillazz/fastapi-sqlalchemy-asyncpg.git
synced 2026-01-17 11:40:39 +03:00
- implement postgres connection pool
- adapt current sqlalchemy based methods to produce raw sql
This commit is contained in:
@@ -70,5 +70,29 @@ class Settings(BaseSettings):
|
||||
path=self.POSTGRES_DB,
|
||||
)
|
||||
|
||||
@computed_field
|
||||
@property
|
||||
def postgres_url(self) -> PostgresDsn:
|
||||
"""
|
||||
This is a computed field that generates a PostgresDsn URL
|
||||
|
||||
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 "postgres".
|
||||
- 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.
|
||||
"""
|
||||
return MultiHostUrl.build(
|
||||
scheme="postgres",
|
||||
username=self.POSTGRES_USER,
|
||||
password=self.POSTGRES_PASSWORD,
|
||||
host=self.POSTGRES_HOST,
|
||||
path=self.POSTGRES_DB,
|
||||
)
|
||||
|
||||
|
||||
settings = Settings()
|
||||
|
||||
Reference in New Issue
Block a user