use super::schema::recipes; use super::schema::ingredients; use super::diesel::prelude::*; #[derive(Debug, Clone, Queryable)] pub struct Recipe { pub id: i32, pub title: String, pub category: i32, pub ingredients: String, pub preparation: String, } #[derive(Insertable)] #[table_name="recipes"] pub struct NewRecipe<'a> { pub title: &'a str, pub category: i32, pub ingredients: &'a str, pub preparation: &'a str, } impl<'a> NewRecipe<'a> { pub fn new(title: &'a str, category: i32, ingredients: &'a str, preparation: &'a str) -> Self { NewRecipe{ title, category, ingredients, preparation, } } pub fn insert(self, conn: &SqliteConnection) -> Result { diesel::insert_into(recipes::table) .values(&self) .execute(conn) .expect("Error inserting recipe"); Ok(self) } } #[derive(Queryable)] pub struct Ingredient { pub id: i32, pub alias: String, } #[derive(Insertable)] #[table_name="ingredients"] pub struct NewIngredient<'a> { pub alias: &'a str, }