♻️ Use of pydantic to manage config+env variables
FastAPI release has been updated allowing to use lifespan parameter to prepare/shutdown sub components.
This commit is contained in:
@@ -13,7 +13,7 @@ from sqlalchemy.ext.asyncio import (
|
||||
)
|
||||
|
||||
from .base_class import Base
|
||||
|
||||
from ..settings import DatabaseSettings
|
||||
|
||||
logger = getLogger(__name__)
|
||||
|
||||
@@ -33,9 +33,17 @@ class Database:
|
||||
return None
|
||||
|
||||
# TODO: Preserve UserLastStopSearchResults table from drop.
|
||||
async def connect(self, db_path: str, clear_static_data: bool = False) -> bool:
|
||||
async def connect(
|
||||
self, settings: DatabaseSettings, clear_static_data: bool = False
|
||||
) -> bool:
|
||||
password = settings.password
|
||||
path = (
|
||||
f"{settings.driver}://{settings.user}:"
|
||||
f"{password.get_secret_value() if password is not None else ''}"
|
||||
f"@{settings.host}:{settings.port}/{settings.name}"
|
||||
)
|
||||
self._async_engine = create_async_engine(
|
||||
db_path, pool_pre_ping=True, pool_size=10, max_overflow=20
|
||||
path, pool_pre_ping=True, pool_size=10, max_overflow=20
|
||||
)
|
||||
|
||||
if self._async_engine is not None:
|
||||
|
Reference in New Issue
Block a user