Rust Tutorial #23: Database with SQLx
In the previous tutorial, we built a REST API with Axum using in-memory storage. Now we add a real database with SQLx. SQLx is an async database library for Rust. It supports PostgreSQL, MySQL, and SQLite. Unlike ORMs, SQLx lets you write plain SQL while still being type-safe. It can even check your queries at compile time against a real database. In this tutorial, we use SQLite because it needs no server setup. Everything you learn applies to PostgreSQL and MySQL too — just change the connection string and SQL dialect. ...