Skip to main content

Database

Struct Database 

Source
pub struct Database { /* private fields */ }

Implementations§

Source§

impl Database

Source

pub fn open(path: &Path) -> Result<Self>

Source

pub fn open_in_memory() -> Result<Self>

Source

pub fn insert_food(&self, food: &NewFood) -> Result<Food>

Source

pub fn upsert_food_by_barcode(&self, food: &NewFood) -> Result<Food>

Source

pub fn get_food_by_id(&self, id: i64) -> Result<Food>

Source

pub fn get_food_by_barcode(&self, barcode: &str) -> Result<Option<Food>>

Source

pub fn search_foods_local(&self, query: &str) -> Result<Vec<Food>>

Source

pub fn list_foods(&self, search: Option<&str>) -> Result<Vec<Food>>

Source

pub fn insert_meal_entry(&self, entry: &NewMealEntry) -> Result<MealEntry>

Source

pub fn get_meal_entry(&self, id: i64) -> Result<MealEntry>

Source

pub fn delete_meal_entry(&self, id: i64) -> Result<bool>

Source

pub fn update_meal_entry( &self, id: i64, update: &UpdateMealEntry, ) -> Result<MealEntry>

Source

pub fn get_entries_for_date(&self, date: NaiveDate) -> Result<Vec<MealEntry>>

Source

pub fn get_entries_for_date_and_meal( &self, date: NaiveDate, meal_type: &str, ) -> Result<Vec<MealEntry>>

Source

pub fn set_target( &self, day_of_week: i64, calories: i64, protein_pct: Option<i64>, carbs_pct: Option<i64>, fat_pct: Option<i64>, ) -> Result<DailyTarget>

Source

pub fn get_target(&self, day_of_week: i64) -> Result<Option<DailyTarget>>

Source

pub fn get_all_targets(&self) -> Result<Vec<DailyTarget>>

Source

pub fn clear_target(&self, day_of_week: i64) -> Result<bool>

Source

pub fn clear_all_targets(&self) -> Result<bool>

Source

pub fn create_recipe(&self, name: &str, portions: f64) -> Result<Recipe>

Source

pub fn get_recipe_by_id(&self, id: i64) -> Result<Recipe>

Source

pub fn get_recipe_by_food_name(&self, name: &str) -> Result<Recipe>

Source

pub fn add_recipe_ingredient( &self, recipe_id: i64, food_id: i64, quantity_g: f64, ) -> Result<RecipeIngredient>

Source

pub fn remove_recipe_ingredient( &self, recipe_id: i64, food_name: &str, ) -> Result<bool>

Source

pub fn set_recipe_portions(&self, recipe_id: i64, portions: f64) -> Result<()>

Source

pub fn get_recipe_ingredients( &self, recipe_id: i64, ) -> Result<Vec<RecipeIngredient>>

Source

pub fn get_recipe_detail(&self, recipe_id: i64) -> Result<RecipeDetail>

Source

pub fn list_recipes(&self) -> Result<Vec<RecipeDetail>>

Source

pub fn delete_recipe(&self, recipe_id: i64) -> Result<()>

Source

pub fn record_tombstone(&self, uuid: &str, table_name: &str) -> Result<()>

Source

pub fn get_tombstones(&self) -> Result<Vec<SyncTombstone>>

Source

pub fn get_tombstones_since(&self, since: &str) -> Result<Vec<SyncTombstone>>

Source

pub fn clear_tombstones(&self) -> Result<()>

Source

pub fn get_foods_since(&self, since: &str) -> Result<Vec<Food>>

Source

pub fn get_all_foods(&self) -> Result<Vec<Food>>

Source

pub fn get_meal_entries_since( &self, since: &str, ) -> Result<Vec<ExportMealEntry>>

Source

pub fn get_all_meal_entries_export(&self) -> Result<Vec<ExportMealEntry>>

Source

pub fn get_recipes_since(&self, since: &str) -> Result<Vec<ExportRecipe>>

Source

pub fn get_all_recipes_export(&self) -> Result<Vec<ExportRecipe>>

Source

pub fn get_recipe_ingredients_since( &self, since: &str, ) -> Result<Vec<ExportRecipeIngredient>>

Source

pub fn get_all_recipe_ingredients_export( &self, ) -> Result<Vec<ExportRecipeIngredient>>

Source

pub fn get_targets_since(&self, since: &str) -> Result<Vec<ExportTarget>>

Source

pub fn get_all_targets_export(&self) -> Result<Vec<ExportTarget>>

Source

pub fn get_weight_entries_since( &self, since: &str, ) -> Result<Vec<ExportWeightEntry>>

Source

pub fn get_all_weight_entries_export(&self) -> Result<Vec<ExportWeightEntry>>

Source

pub fn changes_since( &self, since: Option<&str>, server_timestamp: &str, ) -> Result<SyncPayload>

Source

pub fn apply_remote_changes( &self, foods: &[Food], meal_entries: &[ExportMealEntry], recipes: &[ExportRecipe], recipe_ingredients: &[ExportRecipeIngredient], targets: &[ExportTarget], weight_entries: &[ExportWeightEntry], tombstones: &[SyncTombstone], ) -> Result<()>

Source

pub fn get_or_create_device_id(&self) -> Result<String>

Source

pub fn get_food_by_uuid(&self, uuid: &str) -> Result<Option<Food>>

Source

pub fn get_meal_entry_uuid(&self, id: i64) -> Result<Option<String>>

Source

pub fn get_recipe_uuid(&self, id: i64) -> Result<Option<String>>

Source

pub fn get_recipe_ingredient_uuids(&self, recipe_id: i64) -> Result<Vec<String>>

Source

pub fn export_all(&self) -> Result<ExportData>

Source

pub fn import_all(&self, data: &ExportData) -> Result<ImportSummary>

Source

pub fn upsert_weight(&self, entry: &NewWeightEntry) -> Result<WeightEntry>

Source

pub fn get_weight(&self, date: NaiveDate) -> Result<Option<WeightEntry>>

Source

pub fn get_weight_history(&self, days: Option<i64>) -> Result<Vec<WeightEntry>>

Source

pub fn delete_weight(&self, id: i64) -> Result<()>

Source

pub fn get_recently_logged_foods(&self, limit: i64) -> Result<Vec<RecentFood>>

Source

pub fn get_logging_streak(&self, today: NaiveDate) -> Result<i64>

Source

pub fn get_calorie_average(&self, days: i64) -> Result<f64>

Source

pub fn set_setting(&self, key: &str, value: &str) -> Result<()>

Source

pub fn get_setting(&self, key: &str) -> Result<Option<String>>

Source

pub fn delete_setting(&self, key: &str) -> Result<bool>

Source

pub fn build_daily_summary(&self, date: NaiveDate) -> Result<DailySummary>

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.