📝 Add technical details about async def handling (#61)

#33
This commit is contained in:
Sebastián Ramírez
2019-03-02 13:48:06 +04:00
committed by GitHub
parent 76fb2879ed
commit 819b3b2516
2 changed files with 41 additions and 2 deletions

View File

@@ -130,7 +130,7 @@ This will then give us better editor support inside the path operation function,
{!./src/sql_databases/tutorial001.py!}
```
!!! info "Technical Detail"
!!! info "Technical Details"
The parameter `db` is actually of type `SessionLocal`, but this class (created with `sessionmaker()`) is a "proxy" of a SQLAlchemy `Session`, so, the editor doesn't really know what methods are provided.
But by declaring the type as `Session`, the editor now can know the available methods (`.add()`, `.query()`, `.commit()`, etc) and can provide better support (like completion). The type declaration doesn't affect the actual object.
@@ -247,6 +247,9 @@ Then we should declare the path operation without `async def`, just with a norma
{!./src/sql_databases/tutorial001.py!}
```
!!! note "Very Technical Details"
If you are curious and have a deep technical knowledge, you can check <a href="https://fastapi.tiangolo.com/async/#very-technical-details" target="_blank">the very technical details of how this `async def` vs `def` is handled</a>.
## Migrations
Because we are using SQLAlchemy directly and we don't require any kind of plug-in for it to work with **FastAPI**, we could integrate database <abbr title="Automatically updating the database to have any new column we define in our models.">migrations</abbr> with <a href="https://alembic.sqlalchemy.org" target="_blank">Alembic</a> directly.