Search⌘ K
AI Features

List Resource

Explore how to create Rust models for products and variants, serialize and test database queries, and return listings with related data using Diesel. Understand setting up models, connecting to test databases, and implementing functions that fetch product details and their variants.

We'll cover the following...

List products

We add the models.rs file for our models in the src folder with the products model.

Note: Find more information about the file structure in the Set Up Diesel lesson.

Rust 1.40.0
use serde::{Serialize, Deserialize};
use diesel::Queryable;
#[derive(Queryable, Debug, Serialize, Deserialize)]
pub struct Product {
pub id: i32,
pub name: String,
pub cost: f64,
pub active: bool,
}

The first model, Product, will be used to get data from the database.

It needs to be serialized, so ...