new Fastapi https://fastapi.tiangolo.com/release-notes/#0940 introduced a new way to handle lifespan events
ref https://fastapi.tiangolo.com/advanced/events/#alternative-events-deprecated
|
@app.on_event("startup") |
|
async def startup_event() -> None: |
|
"""Connect to database on startup.""" |
|
await connect_to_db(app, settings=postgres_settings) |
|
await register_collection_catalog( |
|
app, |
|
schemas=db_settings.schemas, |
|
exclude_schemas=db_settings.exclude_schemas, |
|
tables=db_settings.tables, |
|
exclude_tables=db_settings.exclude_tables, |
|
function_schemas=db_settings.function_schemas, |
|
exclude_function_schemas=db_settings.exclude_function_schemas, |
|
functions=db_settings.functions, |
|
exclude_functions=db_settings.exclude_functions, |
|
spatial=db_settings.only_spatial_tables, |
|
) |
|
|
|
|
|
@app.on_event("shutdown") |
|
async def shutdown_event() -> None: |
|
"""Close database connection.""" |
|
await close_db_connection(app) |