How to use async database connections and share it in request.app.state #11534
Unanswered
harshguptaserver
asked this question in
Questions
Replies: 2 comments
-
The only way I found is :ref: |
Beta Was this translation helpful? Give feedback.
0 replies
-
You can also take a look at middlewares. Starlette Admin has a middleware for SQLAlchemy Contrib, check that out. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
First Check
Commit to Help
Example Code
Description
Requirement: I want to create database connection pools after deprecation on app.on_event("startup") and use request.app.state.connection_pool_object
I was using :
Then in subrouter i used to use
Now I upgraded to latest fastapi version and I am unable to use on event startup, I tried referring to lifespan page but it does not help in subrouter.
Operating System
Linux
Operating System Details
cat /etc/os-release
NAME="Pop!_OS"
VERSION="22.04 LTS"
ID=pop
ID_LIKE="ubuntu debian"
PRETTY_NAME="Pop!_OS 22.04 LTS"
VERSION_ID="22.04"
FastAPI Version
0.111.0
Pydantic Version
2.7.1
Python Version
Python 3.12.2
Additional Context
I want to be able to use request.app.state.x again using lifespan or any other way since on_startup is deprecated.
Beta Was this translation helpful? Give feedback.
All reactions