Documentation
¶
Index ¶
- Constants
- Variables
- func WithDebug() func(*StorageSQLite)
- type Activity
- type Backup
- type Bundle
- type BundleBackup
- type Food
- type FoodBackup
- type Journal
- type JournalBackup
- type JournalMealItem
- type JournalMealReport
- type JournalReport
- type JournalStats
- type Meal
- type Storage
- type StorageSQLite
- func (r *StorageSQLite) Backup(ctx context.Context) (*Backup, error)
- func (r *StorageSQLite) Close() error
- func (r *StorageSQLite) CopyJournal(ctx context.Context, userID int64, from time.Time, mealFrom Meal, to time.Time, ...) (int, error)
- func (r *StorageSQLite) DeleteActivity(ctx context.Context, userID int64, timestamp time.Time) error
- func (r *StorageSQLite) DeleteBundle(ctx context.Context, userID int64, key string) error
- func (r *StorageSQLite) DeleteFood(ctx context.Context, key string) error
- func (r *StorageSQLite) DeleteJournal(ctx context.Context, userID int64, timestamp time.Time, meal Meal, ...) error
- func (r *StorageSQLite) DeleteJournalMeal(ctx context.Context, userID int64, timestamp time.Time, meal Meal) error
- func (r *StorageSQLite) DeleteWeight(ctx context.Context, userID int64, timestamp time.Time) error
- func (r *StorageSQLite) FindFood(ctx context.Context, pattern string) ([]Food, error)
- func (r *StorageSQLite) GetActivity(ctx context.Context, userID int64, timestamp time.Time) (*Activity, error)
- func (r *StorageSQLite) GetActivityList(ctx context.Context, userID int64, from, to time.Time) ([]Activity, error)
- func (r *StorageSQLite) GetBundle(ctx context.Context, userID int64, key string) (*Bundle, error)
- func (r *StorageSQLite) GetBundleList(ctx context.Context, userID int64) ([]Bundle, error)
- func (r *StorageSQLite) GetFood(ctx context.Context, key string) (*Food, error)
- func (r *StorageSQLite) GetFoodList(ctx context.Context) ([]Food, error)
- func (r *StorageSQLite) GetJournalFoodAvgWeight(ctx context.Context, userID int64, from, to time.Time, foodkey string) (float64, error)
- func (r *StorageSQLite) GetJournalMealReport(ctx context.Context, userID int64, timestamp time.Time, meal Meal) (*JournalMealReport, error)
- func (r *StorageSQLite) GetJournalReport(ctx context.Context, userID int64, from, to time.Time) ([]JournalReport, error)
- func (r *StorageSQLite) GetJournalStats(ctx context.Context, userID int64, from, to time.Time) ([]JournalStats, error)
- func (r *StorageSQLite) GetUserSettings(ctx context.Context, userID int64) (*UserSettings, error)
- func (r *StorageSQLite) GetWeightList(ctx context.Context, userID int64, from, to time.Time) ([]Weight, error)
- func (r *StorageSQLite) SetActivity(ctx context.Context, userID int64, activity *Activity) error
- func (r *StorageSQLite) SetBundle(ctx context.Context, userID int64, bndl *Bundle) error
- func (r *StorageSQLite) SetFood(ctx context.Context, food *Food) error
- func (r *StorageSQLite) SetFoodComment(ctx context.Context, key, comment string) error
- func (r *StorageSQLite) SetJournal(ctx context.Context, userID int64, journal *Journal) error
- func (r *StorageSQLite) SetJournalBundle(ctx context.Context, userID int64, timestamp time.Time, meal Meal, ...) error
- func (r *StorageSQLite) SetUserSettings(ctx context.Context, userID int64, settings *UserSettings) error
- func (r *StorageSQLite) SetWeight(ctx context.Context, userID int64, weight *Weight) error
- type TxFn
- type UserSettings
- type UserSettingsBackup
- type Weight
- type WeightBackup
Constants ¶
View Source
const StorageOperationTimeout = 15 * time.Second
Variables ¶
View Source
var ( // Food ErrFoodNotFound = errors.New("food not found") ErrFoodInvalid = errors.New("invalid food") ErrFoodEmptyList = errors.New("empty food list") ErrFoodIsUsed = errors.New("food is used") // Bundle ErrBundleInvalid = errors.New("invalid bundle") ErrBundleNotFound = errors.New("bundle not found") ErrBundleEmptyList = errors.New("empty bundle list") ErrBundleDepBundleNotFound = errors.New("dependent bundle not found") ErrBundleDepFoodNotFound = errors.New("dependent food not found") ErrBundleDepRecursive = errors.New("dependent recursive bundle not allowed") ErrBundleIsUsed = errors.New("bundle is used") // Journal ErrJournalInvalid = errors.New("journal invalid") ErrJournalMealReportEmpty = errors.New("empty journal meal report") ErrJournalReportEmpty = errors.New("empty journal report") ErrJournalStatsEmpty = errors.New("empty journal stats") ErrJournalInvalidFood = errors.New("journal invalid food") ErrCopyToNotEmpty = errors.New("copy destination not empty") // Weight ErrWeightNotFound = errors.New("weight not found") ErrWeightInvalid = errors.New("invalid weight") ErrWeightEmptyList = errors.New("empty weight list") // UserSettings ErrUserSettingsNotFound = errors.New("user settings not found") ErrUserSettingsInvalid = errors.New("invalid user settings") // Activity ErrActivityNotFound = errors.New("activity not found") ErrActivityInvalid = errors.New("activity invalid") ErrActivityEmptyList = errors.New("activity empty list") )
Functions ¶
func WithDebug ¶
func WithDebug() func(*StorageSQLite)
Types ¶
type Backup ¶
type Backup struct { Timestamp int64 `json:"timestamp"` Weight []WeightBackup `json:"weight"` Food []FoodBackup `json:"food"` Journal []JournalBackup `json:"journal"` Bundle []BundleBackup `json:"bundle"` UserSettings []UserSettingsBackup `json:"user_settings"` }
type Bundle ¶
type BundleBackup ¶
type Food ¶
type FoodBackup ¶
type JournalBackup ¶
type JournalMealItem ¶
type JournalMealReport ¶
type JournalMealReport struct { ConsumedDayCal float64 ConsumedMealCal float64 Items []JournalMealItem }
type JournalReport ¶
type JournalStats ¶
type Storage ¶
type Storage interface { // Food GetFood(ctx context.Context, key string) (*Food, error) SetFood(ctx context.Context, food *Food) error SetFoodComment(ctx context.Context, key, comment string) error GetFoodList(ctx context.Context) ([]Food, error) FindFood(ctx context.Context, pattern string) ([]Food, error) DeleteFood(ctx context.Context, key string) error // Bundle SetBundle(ctx context.Context, userID int64, bndl *Bundle) error GetBundle(ctx context.Context, userID int64, key string) (*Bundle, error) GetBundleList(ctx context.Context, userID int64) ([]Bundle, error) DeleteBundle(ctx context.Context, userID int64, key string) error // Weight GetWeightList(ctx context.Context, userID int64, from, to time.Time) ([]Weight, error) SetWeight(ctx context.Context, userID int64, weight *Weight) error DeleteWeight(ctx context.Context, userID int64, timestamp time.Time) error // Journal SetJournal(ctx context.Context, userID int64, journal *Journal) error SetJournalBundle(ctx context.Context, userID int64, timestamp time.Time, meal Meal, bndlKey string) error DeleteJournal(ctx context.Context, userID int64, timestamp time.Time, meal Meal, foodkey string) error DeleteJournalMeal(ctx context.Context, userID int64, timestamp time.Time, meal Meal) error GetJournalMealReport(ctx context.Context, userID int64, timestamp time.Time, meal Meal) (*JournalMealReport, error) GetJournalReport(ctx context.Context, userID int64, from, to time.Time) ([]JournalReport, error) GetJournalStats(ctx context.Context, userID int64, from, to time.Time) ([]JournalStats, error) CopyJournal(ctx context.Context, userID int64, from time.Time, mealFrom Meal, to time.Time, mealTo Meal) (int, error) GetJournalFoodAvgWeight(ctx context.Context, userID int64, from, to time.Time, foodkey string) (float64, error) // Activity GetActivityList(ctx context.Context, userID int64, from, to time.Time) ([]Activity, error) GetActivity(ctx context.Context, userID int64, timestamp time.Time) (*Activity, error) SetActivity(ctx context.Context, userID int64, activity *Activity) error DeleteActivity(ctx context.Context, userID int64, timestamp time.Time) error // UserSettings GetUserSettings(ctx context.Context, userID int64) (*UserSettings, error) SetUserSettings(ctx context.Context, userID int64, settings *UserSettings) error // Backup Backup(ctx context.Context) (*Backup, error) Close() error }
type StorageSQLite ¶
type StorageSQLite struct {
// contains filtered or unexported fields
}
func NewStorageSQLite ¶
func NewStorageSQLite(dbFilePath string, opts ...func(*StorageSQLite)) (*StorageSQLite, error)
func (*StorageSQLite) Close ¶
func (r *StorageSQLite) Close() error
func (*StorageSQLite) CopyJournal ¶
func (*StorageSQLite) DeleteActivity ¶
func (*StorageSQLite) DeleteBundle ¶
func (*StorageSQLite) DeleteFood ¶
func (r *StorageSQLite) DeleteFood(ctx context.Context, key string) error
func (*StorageSQLite) DeleteJournal ¶
func (*StorageSQLite) DeleteJournalMeal ¶
func (*StorageSQLite) DeleteWeight ¶
func (*StorageSQLite) GetActivity ¶
func (*StorageSQLite) GetActivityList ¶
func (*StorageSQLite) GetBundleList ¶
func (*StorageSQLite) GetFoodList ¶
func (r *StorageSQLite) GetFoodList(ctx context.Context) ([]Food, error)
func (*StorageSQLite) GetJournalFoodAvgWeight ¶
func (*StorageSQLite) GetJournalMealReport ¶
func (r *StorageSQLite) GetJournalMealReport(ctx context.Context, userID int64, timestamp time.Time, meal Meal) (*JournalMealReport, error)
func (*StorageSQLite) GetJournalReport ¶
func (r *StorageSQLite) GetJournalReport(ctx context.Context, userID int64, from, to time.Time) ([]JournalReport, error)
func (*StorageSQLite) GetJournalStats ¶
func (r *StorageSQLite) GetJournalStats(ctx context.Context, userID int64, from, to time.Time) ([]JournalStats, error)
func (*StorageSQLite) GetUserSettings ¶
func (r *StorageSQLite) GetUserSettings(ctx context.Context, userID int64) (*UserSettings, error)
func (*StorageSQLite) GetWeightList ¶
func (*StorageSQLite) SetActivity ¶
func (*StorageSQLite) SetFood ¶
func (r *StorageSQLite) SetFood(ctx context.Context, food *Food) error
func (*StorageSQLite) SetFoodComment ¶
func (r *StorageSQLite) SetFoodComment(ctx context.Context, key, comment string) error
func (*StorageSQLite) SetJournal ¶
func (*StorageSQLite) SetJournalBundle ¶
func (*StorageSQLite) SetUserSettings ¶
func (r *StorageSQLite) SetUserSettings(ctx context.Context, userID int64, settings *UserSettings) error
type UserSettings ¶
func (*UserSettings) Validate ¶
func (r *UserSettings) Validate() bool
type UserSettingsBackup ¶
type WeightBackup ¶
Click to show internal directories.
Click to hide internal directories.