This commit is contained in:
David Bejo 2025-12-16 21:07:32 +00:00 committed by GitHub
commit ef4d23d5e6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
12 changed files with 86 additions and 51 deletions

View File

@ -1,3 +1,4 @@
from contextlib import asynccontextmanager
from typing import List, Union from typing import List, Union
from fastapi import Depends, FastAPI, HTTPException, Query from fastapi import Depends, FastAPI, HTTPException, Query
@ -27,12 +28,13 @@ def get_session():
yield session yield session
app = FastAPI() @asynccontextmanager
async def lifespan(app: FastAPI):
@app.on_event("startup")
def on_startup():
create_db_and_tables() create_db_and_tables()
yield
app = FastAPI(lifespan=lifespan)
@app.post("/heroes/") @app.post("/heroes/")

View File

@ -1,3 +1,4 @@
from contextlib import asynccontextmanager
from typing import List, Union from typing import List, Union
from fastapi import Depends, FastAPI, HTTPException, Query from fastapi import Depends, FastAPI, HTTPException, Query
@ -30,12 +31,14 @@ def get_session():
SessionDep = Annotated[Session, Depends(get_session)] SessionDep = Annotated[Session, Depends(get_session)]
app = FastAPI()
@asynccontextmanager
@app.on_event("startup") async def lifespan(app: FastAPI):
def on_startup():
create_db_and_tables() create_db_and_tables()
yield
app = FastAPI(lifespan=lifespan)
@app.post("/heroes/") @app.post("/heroes/")

View File

@ -1,3 +1,4 @@
from contextlib import asynccontextmanager
from typing import Annotated from typing import Annotated
from fastapi import Depends, FastAPI, HTTPException, Query from fastapi import Depends, FastAPI, HTTPException, Query
@ -29,12 +30,14 @@ def get_session():
SessionDep = Annotated[Session, Depends(get_session)] SessionDep = Annotated[Session, Depends(get_session)]
app = FastAPI()
@asynccontextmanager
@app.on_event("startup") async def lifespan(app: FastAPI):
def on_startup():
create_db_and_tables() create_db_and_tables()
yield
app = FastAPI(lifespan=lifespan)
@app.post("/heroes/") @app.post("/heroes/")

View File

@ -1,3 +1,4 @@
from contextlib import asynccontextmanager
from typing import Annotated, Union from typing import Annotated, Union
from fastapi import Depends, FastAPI, HTTPException, Query from fastapi import Depends, FastAPI, HTTPException, Query
@ -29,12 +30,14 @@ def get_session():
SessionDep = Annotated[Session, Depends(get_session)] SessionDep = Annotated[Session, Depends(get_session)]
app = FastAPI()
@asynccontextmanager
@app.on_event("startup") async def lifespan(app: FastAPI):
def on_startup():
create_db_and_tables() create_db_and_tables()
yield
app = FastAPI(lifespan=lifespan)
@app.post("/heroes/") @app.post("/heroes/")

View File

@ -1,3 +1,5 @@
from contextlib import asynccontextmanager
from fastapi import Depends, FastAPI, HTTPException, Query from fastapi import Depends, FastAPI, HTTPException, Query
from sqlmodel import Field, Session, SQLModel, create_engine, select from sqlmodel import Field, Session, SQLModel, create_engine, select
@ -25,12 +27,13 @@ def get_session():
yield session yield session
app = FastAPI() @asynccontextmanager
async def lifespan(app: FastAPI):
@app.on_event("startup")
def on_startup():
create_db_and_tables() create_db_and_tables()
yield
app = FastAPI(lifespan=lifespan)
@app.post("/heroes/") @app.post("/heroes/")

View File

@ -1,3 +1,4 @@
from contextlib import asynccontextmanager
from typing import Union from typing import Union
from fastapi import Depends, FastAPI, HTTPException, Query from fastapi import Depends, FastAPI, HTTPException, Query
@ -27,12 +28,13 @@ def get_session():
yield session yield session
app = FastAPI() @asynccontextmanager
async def lifespan(app: FastAPI):
@app.on_event("startup")
def on_startup():
create_db_and_tables() create_db_and_tables()
yield
app = FastAPI(lifespan=lifespan)
@app.post("/heroes/") @app.post("/heroes/")

View File

@ -1,3 +1,4 @@
from contextlib import asynccontextmanager
from typing import List, Union from typing import List, Union
from fastapi import Depends, FastAPI, HTTPException, Query from fastapi import Depends, FastAPI, HTTPException, Query
@ -44,12 +45,13 @@ def get_session():
yield session yield session
app = FastAPI() @asynccontextmanager
async def lifespan(app: FastAPI):
@app.on_event("startup")
def on_startup():
create_db_and_tables() create_db_and_tables()
yield
app = FastAPI(lifespan=lifespan)
@app.post("/heroes/", response_model=HeroPublic) @app.post("/heroes/", response_model=HeroPublic)

View File

@ -1,3 +1,4 @@
from contextlib import asynccontextmanager
from typing import List, Union from typing import List, Union
from fastapi import Depends, FastAPI, HTTPException, Query from fastapi import Depends, FastAPI, HTTPException, Query
@ -46,12 +47,15 @@ def get_session():
SessionDep = Annotated[Session, Depends(get_session)] SessionDep = Annotated[Session, Depends(get_session)]
app = FastAPI()
@app.on_event("startup") @asynccontextmanager
def on_startup(): async def lifespan(app: FastAPI):
create_db_and_tables() create_db_and_tables()
yield
app = FastAPI(lifespan=lifespan)
@app.post("/heroes/", response_model=HeroPublic) @app.post("/heroes/", response_model=HeroPublic)

View File

@ -1,3 +1,4 @@
from contextlib import asynccontextmanager
from typing import Annotated from typing import Annotated
from fastapi import Depends, FastAPI, HTTPException, Query from fastapi import Depends, FastAPI, HTTPException, Query
@ -45,12 +46,15 @@ def get_session():
SessionDep = Annotated[Session, Depends(get_session)] SessionDep = Annotated[Session, Depends(get_session)]
app = FastAPI()
@app.on_event("startup") @asynccontextmanager
def on_startup(): async def lifespan(app: FastAPI):
create_db_and_tables() create_db_and_tables()
yield
app = FastAPI(lifespan=lifespan)
@app.post("/heroes/", response_model=HeroPublic) @app.post("/heroes/", response_model=HeroPublic)

View File

@ -1,3 +1,4 @@
from contextlib import asynccontextmanager
from typing import Annotated, Union from typing import Annotated, Union
from fastapi import Depends, FastAPI, HTTPException, Query from fastapi import Depends, FastAPI, HTTPException, Query
@ -45,12 +46,15 @@ def get_session():
SessionDep = Annotated[Session, Depends(get_session)] SessionDep = Annotated[Session, Depends(get_session)]
app = FastAPI()
@app.on_event("startup") @asynccontextmanager
def on_startup(): async def lifespan(app: FastAPI):
create_db_and_tables() create_db_and_tables()
yield
app = FastAPI(lifespan=lifespan)
@app.post("/heroes/", response_model=HeroPublic) @app.post("/heroes/", response_model=HeroPublic)

View File

@ -1,3 +1,5 @@
from contextlib import asynccontextmanager
from fastapi import Depends, FastAPI, HTTPException, Query from fastapi import Depends, FastAPI, HTTPException, Query
from sqlmodel import Field, Session, SQLModel, create_engine, select from sqlmodel import Field, Session, SQLModel, create_engine, select
@ -42,12 +44,13 @@ def get_session():
yield session yield session
app = FastAPI() @asynccontextmanager
async def lifespan(app: FastAPI):
@app.on_event("startup")
def on_startup():
create_db_and_tables() create_db_and_tables()
yield
app = FastAPI(lifespan=lifespan)
@app.post("/heroes/", response_model=HeroPublic) @app.post("/heroes/", response_model=HeroPublic)

View File

@ -1,3 +1,4 @@
from contextlib import asynccontextmanager
from typing import Union from typing import Union
from fastapi import Depends, FastAPI, HTTPException, Query from fastapi import Depends, FastAPI, HTTPException, Query
@ -44,12 +45,13 @@ def get_session():
yield session yield session
app = FastAPI() @asynccontextmanager
async def lifespan(app: FastAPI):
@app.on_event("startup")
def on_startup():
create_db_and_tables() create_db_and_tables()
yield
app = FastAPI(lifespan=lifespan)
@app.post("/heroes/", response_model=HeroPublic) @app.post("/heroes/", response_model=HeroPublic)