Fix SQLAlchemy examples

This commit is contained in:
François Voron
2022-02-01 09:25:44 +01:00
parent 5f3d4fa044
commit 9b1f9bbd0f
8 changed files with 23 additions and 7 deletions

View File

@@ -1,5 +1,6 @@
from fastapi import Depends, FastAPI
from app.db import create_db_and_tables
from app.models import UserDB
from app.users import auth_backend, current_active_user, fastapi_users
@@ -25,3 +26,9 @@ app.include_router(fastapi_users.get_users_router(), prefix="/users", tags=["use
@app.get("/authenticated-route")
async def authenticated_route(user: UserDB = Depends(current_active_user)):
return {"message": f"Hello {user.email}!"}
@app.on_event("startup")
async def on_startup():
# Not needed if you setup a migration system like Alembic
await create_db_and_tables()

View File

@@ -1,4 +1,4 @@
import uvicorn
if __name__ == "__main__":
uvicorn.run("app.app:app", host="0.0.0.0", port=5000, log_level="info")
uvicorn.run("app.app:app", host="0.0.0.0", log_level="info")

View File

@@ -1,3 +1,4 @@
fastapi
fastapi-users[sqlalchemy]
fastapi-users[sqlalchemy2]
uvicorn[standard]
aiosqlite