Using `check_same_thread=False` allows FastAPI to use the same SQLite database in different threads. This is necessary as **one single request** could use **more than one thread** (for example in dependencies).
Using `check_same_thread=False` allows FastAPI to use the same SQLite database in different threads. This is necessary as **one single request** could use **more than one thread** (for example in dependencies).
@ -87,7 +87,7 @@ Don't worry, with the way the code is structured, we'll make sure we use **a sin
We then add a function that uses `SQLModel.metadata.create_all(engine)` to **create the tables** for all the *table models*.
We then add a function that uses `SQLModel.metadata.create_all(engine)` to **create the tables** for all the *table models*.
Here we use the `SessionDep` dependency (a `Session`) to add the new `Hero` to the `Session` instance, commit the changes to the database, refresh the data in the `hero`, and then return it.
Here we use the `SessionDep` dependency (a `Session`) to add the new `Hero` to the `Session` instance, commit the changes to the database, refresh the data in the `hero`, and then return it.
@ -133,19 +133,19 @@ Here we use the `SessionDep` dependency (a `Session`) to add the new `Hero` to t
We can **read**`Hero`s from the database using a `select()`. We can include a `limit` and `offset` to paginate the results.
We can **read**`Hero`s from the database using a `select()`. We can include a `limit` and `offset` to paginate the results.
### Create with `HeroCreate` and return a `HeroPublic` { #create-with-herocreate-and-return-a-heropublic }
### Create with `HeroCreate` and return a `HeroPublic` { #create-with-herocreate-and-return-a-heropublic }
@ -289,8 +289,8 @@ We receive in the request a `HeroCreate` *data model*, and from it, we create a
This new *table model*`Hero` will have the fields sent by the client, and will also have an `id` generated by the database.
This new *table model*`Hero` will have the fields sent by the client, and will also have an `id` generated by the database.
Then we return the same *table model*`Hero` as is from the function. But as we declare the `response_model` with the `HeroPublic`*data model*, **FastAPI** will use `HeroPublic` to validate and serialize the data.
Then we return the same *table model*`Hero` as is from the function. But as we declare the `response_model` with the `HeroPublic`*data model*, **FastAPI** will use `HeroPublic` to validate and serialize the data.
@ -306,13 +306,13 @@ By declaring it in `response_model` we are telling **FastAPI** to do its thing,
We can do the same as before to **read**`Hero`s, again, we use `response_model=list[HeroPublic]` to ensure that the data is validated and serialized correctly.
We can do the same as before to **read**`Hero`s, again, we use `response_model=list[HeroPublic]` to ensure that the data is validated and serialized correctly.