Install Diesel by adding it to your Cargo.toml dependencies and running diesel CLI commands to set up your database schema.
[dependencies]
diesel = "2.2.10"
[dev-dependencies]
diesel = { version = "2.2.10", features = ["sqlite", "libsqlite3-sys/bundled"] }
- Add the
dieselcrate to yourCargo.tomlwith thesqliteandlibsqlite3-sys/bundledfeatures for embedded testing. - Run
cargo install diesel_cli --no-default-features --features sqliteto install the command-line tool. - Execute
diesel setupto create the database and run migrations. - Generate your schema file with
diesel print-schema > src/schema.rs. - Define your database models in
src/lib.rsusing thediesel::preludemacros.