Browse Source

fix(docs_src): changing all app.event refrence to asynccontextmanager

pull/13253/head
alireza.bahrami 2 months ago
parent
commit
a2c5b28c76
  1. 11
      docs_src/sql_databases/tutorial001.py
  2. 11
      docs_src/sql_databases/tutorial001_an.py
  3. 12
      docs_src/sql_databases/tutorial001_an_py310.py
  4. 11
      docs_src/sql_databases/tutorial001_an_py39.py
  5. 13
      docs_src/sql_databases/tutorial001_py310.py
  6. 12
      docs_src/sql_databases/tutorial001_py39.py
  7. 12
      docs_src/sql_databases/tutorial002.py
  8. 11
      docs_src/sql_databases/tutorial002_an.py
  9. 11
      docs_src/sql_databases/tutorial002_an_py310.py
  10. 11
      docs_src/sql_databases/tutorial002_an_py39.py
  11. 12
      docs_src/sql_databases/tutorial002_py310.py
  12. 12
      docs_src/sql_databases/tutorial002_py39.py

11
docs_src/sql_databases/tutorial001.py

@ -1,3 +1,4 @@
from contextlib import asynccontextmanager
from typing import List, Union
from fastapi import Depends, FastAPI, HTTPException, Query
@ -27,13 +28,15 @@ def get_session():
yield session
app = FastAPI()
@app.on_event("startup")
def on_startup():
create_db_and_tables()
@asynccontextmanager
async def lifespan(app:FastAPI):
create_db_and_tables() #Startup
yield #Allows app to run
#Shutdown
app = FastAPI(lifespan=lifespan)
@app.post("/heroes/")
def create_hero(hero: Hero, session: Session = Depends(get_session)) -> Hero:

11
docs_src/sql_databases/tutorial001_an.py

@ -1,3 +1,4 @@
from contextlib import asynccontextmanager
from typing import List, Union
from fastapi import Depends, FastAPI, HTTPException, Query
@ -30,13 +31,15 @@ def get_session():
SessionDep = Annotated[Session, Depends(get_session)]
app = FastAPI()
@asynccontextmanager
async def lifespan(app:FastAPI):
create_db_and_tables() #Startup
yield #Allows app to run
#Shutdown
@app.on_event("startup")
def on_startup():
create_db_and_tables()
app = FastAPI(lifespan=lifespan)
@app.post("/heroes/")
def create_hero(hero: Hero, session: SessionDep) -> Hero:

12
docs_src/sql_databases/tutorial001_an_py310.py

@ -1,3 +1,4 @@
from contextlib import asynccontextmanager
from typing import Annotated
from fastapi import Depends, FastAPI, HTTPException, Query
@ -29,13 +30,14 @@ def get_session():
SessionDep = Annotated[Session, Depends(get_session)]
app = FastAPI()
@asynccontextmanager
async def lifespan(app:FastAPI):
create_db_and_tables() #Startup
yield #This Allows app to run
#Statements below yield are ran after shutdown
@app.on_event("startup")
def on_startup():
create_db_and_tables()
app = FastAPI(lifespan=lifespan)
@app.post("/heroes/")
def create_hero(hero: Hero, session: SessionDep) -> Hero:

11
docs_src/sql_databases/tutorial001_an_py39.py

@ -1,3 +1,4 @@
from contextlib import asynccontextmanager
from typing import Annotated, Union
from fastapi import Depends, FastAPI, HTTPException, Query
@ -29,13 +30,15 @@ def get_session():
SessionDep = Annotated[Session, Depends(get_session)]
app = FastAPI()
@app.on_event("startup")
def on_startup():
create_db_and_tables()
@asynccontextmanager
async def lifespan(app:FastAPI):
create_db_and_tables() #Startup
yield #Allows app to run
#Shutdown
app = FastAPI(lifespan=lifespan)
@app.post("/heroes/")
def create_hero(hero: Hero, session: SessionDep) -> Hero:

13
docs_src/sql_databases/tutorial001_py310.py

@ -1,3 +1,5 @@
from contextlib import asynccontextmanager
from fastapi import Depends, FastAPI, HTTPException, Query
from sqlmodel import Field, Session, SQLModel, create_engine, select
@ -25,13 +27,14 @@ def get_session():
yield session
app = FastAPI()
@app.on_event("startup")
def on_startup():
create_db_and_tables()
@asynccontextmanager
async def lifespan(app:FastAPI):
create_db_and_tables() #Startup
yield #Allows app to run
#Shutdown
app = FastAPI(lifespan=lifespan)
@app.post("/heroes/")
def create_hero(hero: Hero, session: Session = Depends(get_session)) -> Hero:

12
docs_src/sql_databases/tutorial001_py39.py

@ -1,3 +1,4 @@
from contextlib import asynccontextmanager
from typing import Union
from fastapi import Depends, FastAPI, HTTPException, Query
@ -27,13 +28,14 @@ def get_session():
yield session
app = FastAPI()
@asynccontextmanager
async def lifespan(app:FastAPI):
create_db_and_tables() #Startup
yield #Allows app to run
#Shutdown
@app.on_event("startup")
def on_startup():
create_db_and_tables()
app = FastAPI(lifespan=lifespan)
@app.post("/heroes/")
def create_hero(hero: Hero, session: Session = Depends(get_session)) -> Hero:

12
docs_src/sql_databases/tutorial002.py

@ -1,3 +1,4 @@
from contextlib import asynccontextmanager
from typing import List, Union
from fastapi import Depends, FastAPI, HTTPException, Query
@ -44,14 +45,17 @@ def get_session():
yield session
app = FastAPI()
@app.on_event("startup")
def on_startup():
create_db_and_tables()
@asynccontextmanager
async def lifespan(app:FastAPI):
create_db_and_tables() #StartUp
yield #Allows app to run
#Shut down
app = FastAPI(lifespan=lifespan)
@app.post("/heroes/", response_model=HeroPublic)
def create_hero(hero: HeroCreate, session: Session = Depends(get_session)):
db_hero = Hero.model_validate(hero)

11
docs_src/sql_databases/tutorial002_an.py

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

11
docs_src/sql_databases/tutorial002_an_py310.py

@ -1,3 +1,4 @@
from contextlib import asynccontextmanager
from typing import Annotated
from fastapi import Depends, FastAPI, HTTPException, Query
@ -45,13 +46,15 @@ def get_session():
SessionDep = Annotated[Session, Depends(get_session)]
app = FastAPI()
@app.on_event("startup")
def on_startup():
create_db_and_tables()
@asynccontextmanager
async def lifespan(app:FastAPI):
create_db_and_tables() #Startup
yield #Allows app to run
#Shutdown
app = FastAPI(lifespan=lifespan)
@app.post("/heroes/", response_model=HeroPublic)
def create_hero(hero: HeroCreate, session: SessionDep):

11
docs_src/sql_databases/tutorial002_an_py39.py

@ -1,3 +1,4 @@
from contextlib import asynccontextmanager
from typing import Annotated, Union
from fastapi import Depends, FastAPI, HTTPException, Query
@ -45,13 +46,15 @@ def get_session():
SessionDep = Annotated[Session, Depends(get_session)]
app = FastAPI()
@app.on_event("startup")
def on_startup():
create_db_and_tables()
@asynccontextmanager
async def lifespan(app:FastAPI):
create_db_and_tables() #Startup
yield #Allows app to run
#Shutdown
app = FastAPI(lifespan=lifespan)
@app.post("/heroes/", response_model=HeroPublic)
def create_hero(hero: HeroCreate, session: SessionDep):

12
docs_src/sql_databases/tutorial002_py310.py

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

12
docs_src/sql_databases/tutorial002_py39.py

@ -1,3 +1,4 @@
from contextlib import asynccontextmanager
from typing import Union
from fastapi import Depends, FastAPI, HTTPException, Query
@ -44,13 +45,14 @@ def get_session():
yield session
app = FastAPI()
@asynccontextmanager
async def lifespan(app:FastAPI):
create_db_and_tables() #Startup
yield #Allows app to run
#Shutdown
@app.on_event("startup")
def on_startup():
create_db_and_tables()
app = FastAPI(lifespan=lifespan)
@app.post("/heroes/", response_model=HeroPublic)
def create_hero(hero: HeroCreate, session: Session = Depends(get_session)):

Loading…
Cancel
Save