File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -184,7 +184,7 @@ app = FastAPI()
184184# Database
185185sync_db = Database.create(" sqlite:///amisadmin.db?check_same_thread=False" )
186186
187- app.add_middleware(BaseHTTPMiddleware, dispatch = sync_db.asgi_dispatch )
187+ app.add_middleware(sync_db.asgi_middleware )
188188
189189
190190@app.get (" /user/{id} " )
@@ -195,7 +195,7 @@ def get_user(id: int):
195195# AsyncDatabase
196196async_db = AsyncDatabase.create(" sqlite+aiosqlite:///amisadmin.db?check_same_thread=False" )
197197
198- app.add_middleware(BaseHTTPMiddleware, dispatch = async_db.asgi_dispatch )
198+ app.add_middleware(async_db.asgi_middleware )
199199
200200
201201@app.get (" /user/{id} " )
Original file line number Diff line number Diff line change @@ -183,7 +183,7 @@ app = FastAPI()
183183# Database
184184sync_db = Database.create(" sqlite:///amisadmin.db?check_same_thread=False" )
185185
186- app.add_middleware(BaseHTTPMiddleware, dispatch = sync_db.asgi_dispatch )
186+ app.add_middleware(sync_db.asgi_middleware )
187187
188188
189189@app.get (" /user/{id} " )
@@ -194,7 +194,7 @@ def get_user(id: int):
194194# AsyncDatabase
195195async_db = AsyncDatabase.create(" sqlite+aiosqlite:///amisadmin.db?check_same_thread=False" )
196196
197- app.add_middleware(BaseHTTPMiddleware, dispatch = async_db.asgi_dispatch )
197+ app.add_middleware(async_db.asgi_middleware )
198198
199199
200200@app.get (" /user/{id} " )
Original file line number Diff line number Diff line change @@ -184,7 +184,7 @@ app = FastAPI()
184184# Database
185185sync_db = Database.create(" sqlite:///amisadmin.db?check_same_thread=False" )
186186
187- app.add_middleware(BaseHTTPMiddleware, dispatch = sync_db.asgi_dispatch )
187+ app.add_middleware(sync_db.asgi_middleware )
188188
189189
190190@app.get (" /user/{id} " )
@@ -195,7 +195,7 @@ def get_user(id: int):
195195# AsyncDatabase
196196async_db = AsyncDatabase.create(" sqlite+aiosqlite:///amisadmin.db?check_same_thread=False" )
197197
198- app.add_middleware(BaseHTTPMiddleware, dispatch = async_db.asgi_dispatch )
198+ app.add_middleware(async_db.asgi_middleware )
199199
200200
201201@app.get (" /user/{id} " )
Original file line number Diff line number Diff line change @@ -88,7 +88,7 @@ def session(self) -> AsyncSession:
8888 Example:
8989 ```Python
9090 app = FastAPI()
91- app.add_middleware(BaseHTTPMiddleware, dispatch= db.asgi_dispatch )
91+ app.add_middleware(db.asgi_middleware )
9292
9393 @app.get('/get_user')
9494 async def get_user(id:int):
Original file line number Diff line number Diff line change 44from sqlalchemy import select
55from sqlalchemy .ext .asyncio import AsyncSession
66from sqlalchemy .orm import Session
7- from starlette .middleware .base import BaseHTTPMiddleware
87from starlette .testclient import TestClient
98
109from tests .conftest import User , async_db , sync_db
@@ -26,7 +25,7 @@ def test_sync_db_in_fastapi():
2625 app = FastAPI ()
2726 sub_app = FastAPI ()
2827 app .mount ("/sub" , sub_app )
29- app .add_middleware (BaseHTTPMiddleware , dispatch = sync_db .asgi_dispatch )
28+ app .add_middleware (sync_db .asgi_middleware )
3029 client = TestClient (app )
3130
3231 @app .get ("/users" )
You can’t perform that action at this time.
0 commit comments