-
Book Overview & Buying
-
Table Of Contents
The Rust Programming Handbook
By :
Storing data in an in-memory Arc<Mutex<Vec<Todo>>> is great for examples, but it has a major drawback: all our data is lost when the server restarts.
For a real application, we need persistence.
This means storing our data in a database. In this section, we’ll refactor our API to use PostgreSQL, a powerful and popular open source relational database.
We’ll use sqlx, a modern, pure-Rust, and async-native SQL toolkit.
Before our Rust app can connect with a database, it’s important to have a database server up and running.
Although you can install PostgreSQL directly on your computer, using Docker to run it inside a container is a much cleaner, more straightforward, and more consistent approach for development.
This method keeps the database isolated, avoids any conflicts, and makes cleanup a breeze. Just stop the container when you’re done.
If you haven’...