Adds write script for recipes, adds ingredients migrations
This commit is contained in:
@@ -12,6 +12,7 @@ mod importer;
|
||||
use diesel::prelude::*;
|
||||
use dotenv::dotenv;
|
||||
use std::env;
|
||||
use crate::models::{Recipe, NewRecipe, Ingredient, NewIngredient};
|
||||
|
||||
pub fn establish_connection() -> SqliteConnection {
|
||||
dotenv().ok();
|
||||
@@ -21,7 +22,27 @@ pub fn establish_connection() -> SqliteConnection {
|
||||
.expect(&format!("Error connecting to {}", db_url))
|
||||
}
|
||||
|
||||
pub fn create_recipe(conn: &SqliteConnection, title: &str, ingdts: &str) -> usize {
|
||||
use self::schema::recipes;
|
||||
|
||||
let new_recipe = NewRecipe {
|
||||
title: title,
|
||||
category: 0,
|
||||
ingredients: ingdts.to_string(),
|
||||
preparation: &String::new(),
|
||||
};
|
||||
|
||||
diesel::insert_into(recipes::table)
|
||||
.values(&new_recipe)
|
||||
.execute(conn)
|
||||
.expect("Error inserting recipe")
|
||||
|
||||
}
|
||||
|
||||
pub fn find_ingredient(conn: &SqliteConnection, alias: &str) -> Option<Ingredient> {
|
||||
// Find ingredient by alias
|
||||
None
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
|
||||
Reference in New Issue
Block a user