pre-commit-ci-lite[bot]
7 months ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with
10 additions and
5 deletions
-
docs_src/sql_databases/tutorial001_an_py310.py
-
docs_src/sql_databases/tutorial001_an_py39.py
-
docs_src/sql_databases/tutorial001_py310.py
-
docs_src/sql_databases/tutorial001_py39.py
|
|
|
@ -1,5 +1,6 @@ |
|
|
|
from typing import Annotated |
|
|
|
from contextlib import asynccontextmanager |
|
|
|
from typing import Annotated |
|
|
|
|
|
|
|
from fastapi import Depends, FastAPI, HTTPException, Query |
|
|
|
from sqlmodel import Field, Session, SQLModel, create_engine, select |
|
|
|
|
|
|
|
@ -33,6 +34,7 @@ async def lifespan(app: FastAPI): |
|
|
|
yield |
|
|
|
# will leave this as is for now |
|
|
|
|
|
|
|
|
|
|
|
SessionDep = Annotated[Session, Depends(get_session)] |
|
|
|
|
|
|
|
app = FastAPI(lifespan=lifespan) |
|
|
|
|
|
|
|
@ -1,5 +1,6 @@ |
|
|
|
from typing import Annotated, Union |
|
|
|
from contextlib import asynccontextmanager |
|
|
|
from typing import Annotated, Union |
|
|
|
|
|
|
|
from fastapi import Depends, FastAPI, HTTPException, Query |
|
|
|
from sqlmodel import Field, Session, SQLModel, create_engine, select |
|
|
|
|
|
|
|
|
|
|
|
@ -1,6 +1,7 @@ |
|
|
|
from contextlib import asynccontextmanager |
|
|
|
|
|
|
|
from fastapi import Depends, FastAPI, HTTPException, Query |
|
|
|
from sqlmodel import Field, Session, SQLModel, create_engine, select |
|
|
|
from contextlib import asynccontextmanager |
|
|
|
|
|
|
|
|
|
|
|
class Hero(SQLModel, table=True): |
|
|
|
|
|
|
|
@ -1,5 +1,6 @@ |
|
|
|
from typing import Union |
|
|
|
from contextlib import asynccontextmanager |
|
|
|
from typing import Union |
|
|
|
|
|
|
|
from fastapi import Depends, FastAPI, HTTPException, Query |
|
|
|
from sqlmodel import Field, Session, SQLModel, create_engine, select |
|
|
|
|
|
|
|
@ -26,6 +27,7 @@ def get_session(): |
|
|
|
with Session(engine) as session: |
|
|
|
yield session |
|
|
|
|
|
|
|
|
|
|
|
@asynccontextmanager |
|
|
|
async def lifespan(app: FastAPI): |
|
|
|
create_db_and_tables() |
|
|
|
@ -36,7 +38,6 @@ async def lifespan(app: FastAPI): |
|
|
|
app = FastAPI(lifespan=lifespan) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@app.post("/heroes/") |
|
|
|
def create_hero(hero: Hero, session: Session = Depends(get_session)) -> Hero: |
|
|
|
session.add(hero) |
|
|
|
|