How to use Diesel ORM

Install Diesel via Cargo, define your schema, and use the CLI to generate safe database queries for your Rust application.

Use Diesel by adding it to your Cargo.toml, defining your database schema, and running the diesel CLI to generate types.

[dependencies]
diesel = { version = "2.2.10", features = ["sqlite", "r2d2"] }
libsqlite3-sys = { version = "0.30", features = ["bundled"] }

[dev-dependencies]
diesel_migrations = "2.2.10"

Run cargo install diesel_cli --no-default-features --features sqlite to install the CLI, then diesel setup to create the database and migrations folder. Define your schema in src/schema.rs using diesel::table! macros, and use diesel::prelude::* in your code to query data.