Skip to content

Commit

Permalink
Fix tortoise example
Browse files Browse the repository at this point in the history
  • Loading branch information
uriyyo committed Sep 26, 2023
1 parent ee740e3 commit 636620a
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions examples/pagination_tortoise.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,7 @@ class Config:
orm_mode = True


@asynccontextmanager
async def lifespan(_: Any) -> None:
for _ in range(100):
await User.create(
name=faker.name(),
email=faker.email(),
)
yield


app = FastAPI(lifespan=lifespan)
app = FastAPI()

register_tortoise(
app,
Expand All @@ -52,6 +42,14 @@ async def lifespan(_: Any) -> None:
generate_schemas=True,
)

@app.on_event("startup")
async def on_startup() -> None:
for _ in range(100):
await User.create(
name=faker.name(),
email=faker.email(),
)


@app.post("/users", response_model=UserOut)
async def create_user(user_in: UserIn) -> Any:
Expand Down

0 comments on commit 636620a

Please sign in to comment.