datasource

package
v0.0.0-...-1b63e00 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 30, 2022 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BoltDataSource

type BoltDataSource struct {
	DB *storm.DB
}

BoltDataSource is an implementation of the DataSource interface for boltdb

func (*BoltDataSource) AddEntry

func (ds *BoltDataSource) AddEntry(entryDate string, calories int, food string) error

AddEntry fetches the current config and weight to calculate the metabolic rate and adds the data into the entry table

func (*BoltDataSource) AddWeight

func (ds *BoltDataSource) AddWeight(weight float64) error

AddWeight adds the given weight for todays date

func (*BoltDataSource) CurrentWeight

func (ds *BoltDataSource) CurrentWeight() (*model.Weight, error)

CurrentWeight fetches and returns the current weight, which is the last entry in the table

func (*BoltDataSource) Export

func (ds *BoltDataSource) Export() (*model.ImpEx, error)

Export creates a JSON representation of the database

func (*BoltDataSource) FetchAllEntries

func (ds *BoltDataSource) FetchAllEntries() (model.Entries, error)

FetchAllEntries fetches and returns all entries

func (*BoltDataSource) FetchConfig

func (ds *BoltDataSource) FetchConfig() (config *model.Config, err error)

FetchConfig fetches and returns the current config

func (*BoltDataSource) FetchEntries

func (ds *BoltDataSource) FetchEntries(entryDate string) (model.Entries, error)

FetchEntries fetches and returns all entries for a given date

func (*BoltDataSource) FetchWeights

func (ds *BoltDataSource) FetchWeights() ([]model.Weight, error)

FetchWeights fetches all weight entries

func (*BoltDataSource) Import

func (ds *BoltDataSource) Import(data *model.ImpEx) error

Import imports the given data to the database, overwriting the previous data

func (*BoltDataSource) RemoveEntries

func (ds *BoltDataSource) RemoveEntries(entryDate string) error

RemoveEntries removes all entries for a given day from the database

func (*BoltDataSource) RemoveEntry

func (ds *BoltDataSource) RemoveEntry(entryDate string, id int) error

RemoveEntry removes the entry with the given id for a given day from the database

func (*BoltDataSource) SetConfig

func (ds *BoltDataSource) SetConfig(c *model.Config) error

SetConfig overrides the current config with the given values by deleting the old config and adding a new one

func (*BoltDataSource) SetConfigFromImport

func (ds *BoltDataSource) SetConfigFromImport(c *model.Config) error

SetConfigFromImport overrides the current config with the given values by deleting the old config and adding a new one

func (*BoltDataSource) Setup

func (ds *BoltDataSource) Setup(connection string) (func() error, error)

Setup creates the file and the table structure

type DataSource

type DataSource interface {
	Setup(connection string) (func() error, error)
	SetConfig(*model.Config) error
	SetConfigFromImport(*model.Config) error
	FetchConfig() (*model.Config, error)
	AddWeight(weight float64) error
	CurrentWeight() (*model.Weight, error)
	FetchWeights() ([]model.Weight, error)
	AddEntry(entryDate string, calories int, food string) error
	FetchEntries(entryDate string) (model.Entries, error)
	FetchAllEntries() (model.Entries, error)
	RemoveEntries(entryDate string) error
	RemoveEntry(entryDate string, id int) error
	Import(data *model.ImpEx) error
	Export() (*model.ImpEx, error)
}

DataSource is the interface to the data layer

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL