Connecting to our database
In order to connect to our database, we will use the diesel
crate. We have used the diesel
crate throughout this book for connecting to our database. We also have to remember that, throughout this book, we have been building isolated modules. We can reuse these.
We will need to serialize the database being returned. Because of this, we can copy src/json_serialization
from Chapter 11, Understanding Rocket Web Framework, to src/json_serialization
.
We will also be using the same data models, so we will need to copy the following:
src/models
tosrc/models
src/to_do
tosrc/to_do
src/.env
tosrc/.env
src/schema.rs
tosrc/schema.rs
docker-compose.yml
todocker-compose.yml
src/database.rs
tosrc/database.rs
diesel.toml
todiesel.toml
Follow these steps to connect to our database:
- Our modules are ready to be used. However, before we import them into the
main
file, considering that the previous chapter (Chapter 11...