// AutoFillMealPlan assigns servings to every day in 'mp' using the top // suggestion for each day. func AutoFillMealPlan(q Queryable, mp *mpdata.MealPlan) (err error) { for _, date := range mp.Days() { err = AutoFillMealPlanDay(q, mp.ID, date) if err != nil { return err } } return nil }
// AddMealPlan adds the information contained in 'mp' to the database as a new // meal plan record. It assigns the identifier of the newly created record to // the ID field of the meal plan. func AddMealPlan(q Queryable, mp *mpdata.MealPlan) (err error) { result, err := q.Exec("INSERT INTO mealplan VALUES (NULL, ?, ?, ?)", mp.Notes, mp.StartDate, mp.EndDate) if err != nil { return err } mpID, err := result.LastInsertId() if err != nil { return err } mp.ID = uint64(mpID) return nil }