delete_nutrition_day
Remove a nutrition day from fitness tracking records and optionally delete associated meals and food items to maintain clean data.
Instructions
Delete a nutrition day and optionally cascade to meals/items.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| date | Yes | ||
| cascade | No |
Implementation Reference
- src/main.py:612-629 (handler)The implementation of the 'delete_nutrition_day' tool, which deletes a nutrition day from the database, with an optional cascading delete for associated meals and meal items.
@app.tool() def delete_nutrition_day(date: str, cascade: bool = True) -> dict[str, bool]: """Delete a nutrition day and optionally cascade to meals/items.""" date = _ensure_date(date) conn = get_connection() cursor = conn.cursor() if cascade: # Get meal IDs first cursor.execute("SELECT id FROM meals WHERE day_id IN (SELECT id FROM nutrition_days WHERE date = ?)", (date,)) meal_ids = [r[0] for r in cursor.fetchall()] if meal_ids: placeholders = ",".join("?" * len(meal_ids)) cursor.execute(f"DELETE FROM meal_items WHERE meal_id IN ({placeholders})", meal_ids) cursor.execute("DELETE FROM meals WHERE day_id IN (SELECT id FROM nutrition_days WHERE date = ?)", (date,)) cursor.execute("DELETE FROM nutrition_days WHERE date = ?", (date,)) conn.commit() conn.close() return {"deleted": cursor.rowcount > 0}