Inject every models variations and DB model in DB adapters (#84)

* Inject every model variations in router and DB model in DB adapters

* Update documentation and import Tortoise in db module

* Use path operation decorator dependencies for superuser routes
This commit is contained in:
François Voron
2020-01-04 15:36:34 +01:00
committed by GitHub
parent c903b30161
commit 104a6c6bf5
29 changed files with 501 additions and 269 deletions

View File

@ -24,7 +24,7 @@ For the sake of this tutorial from now on, we'll use a simple SQLite databse.
Let's create a `metadata` object and declare our User table.
```py hl_lines="4 14 15"
```py hl_lines="5 32 33"
{!./src/db_sqlalchemy.py!}
```
@ -34,7 +34,7 @@ As you can see, **FastAPI Users** provides a mixin that will include base fields
We'll now create an SQLAlchemy enigne and ask it to create all the defined tables.
```py hl_lines="18 19 20 21 22"
```py hl_lines="36 37 38 39 40"
{!./src/db_sqlalchemy.py!}
```
@ -45,11 +45,15 @@ We'll now create an SQLAlchemy enigne and ask it to create all the defined table
The database adapter of **FastAPI Users** makes the link between your database configuration and the users logic. Create it like this.
```py hl_lines="24 25"
```py hl_lines="42 43"
{!./src/db_sqlalchemy.py!}
```
Notice that we declare the `users` variable, which is the actual SQLAlchemy table behind the table class. We also use our `database` instance, which allows us to do asynchronous request to the database.
Notice that we pass it three things:
* A reference to your [`UserDB` model](../model.md).
* The `users` variable, which is the actual SQLAlchemy table behind the table class.
* A `database` instance, which allows us to do asynchronous request to the database.
## Next steps