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/modelstosrc/modelssrc/to_dotosrc/to_dosrc/.envtosrc/.envsrc/schema.rstosrc/schema.rsdocker-compose.ymltodocker-compose.ymlsrc/database.rstosrc/database.rsdiesel.tomltodiesel.toml
Follow these steps to connect to our database:
- Our modules are ready to be used. However, before we import them into the
mainfile, considering that the previous chapter (Chapter 11...