Connecting to our database
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. Theoretically, we could just use this, but Rocket does have some functionality that can wrap around diesel. To demonstrate this, we are going to create a simple GET
view that accepts a user ID and returns the to-do items that belong to the user with that ID.
Using Diesel crate to connect to our database
Remember that, throughout this book, we have been building isolated modules. We can reuse them. We will need to serialize the database being returned:
- The modules that we built in the previous chapters are reusable. Because of this, we can copy
src/json_serialization
from Chapter 10, Deploying Our Application on AWS, to oursrc/json_serialization
directory. We will also be using the same data models. Because of this, we need to copysrc/models
tosrc/models
,src/schema.rs
tosrc/schema.rs
,docker-compose...