sqlite

package
v0.0.0-...-9290f5a Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2021 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func TotalKcal

func TotalKcal(reports []Report) uint32

TotalKcal calculates energy of all eaten food.

Types

type DB

type DB struct {
	// contains filtered or unexported fields
}

DB stores all bot data.

func NewDB

func NewDB(path string) (*DB, error)

NewDB opens the database and creates tables if they don't exist.

func (*DB) Close

func (d *DB) Close()

Close connection to the DB.

func (*DB) History

func (d *DB) History(uid int, dates ...time.Time) map[string]uint32

History of the user in the given days.

func (*DB) LastProducts

func (d *DB) LastProducts(n int) []Product

LastProducts returns n last added products.

func (*DB) Products

func (d *DB) Products() []Product

Products saved in the bot.

func (*DB) SaveProduct

func (d *DB) SaveProduct(food string, kcal uint32)

SaveProduct into the database.

func (*DB) SaveReport

func (d *DB) SaveReport(uid int, r Report)

SaveReport of the user into the database.

func (*DB) TodayReports

func (d *DB) TodayReports(uid int, userTime time.Time) []Report

TodayReports of the user.

func (*DB) Users

func (d *DB) Users() []User

Users of the bot.

type Product

type Product struct {
	Name string `json:"Name"`
	Kcal uint32 `json:"Kcal"`
}

Product represents a row in the Product table.

func (Product) String

func (p Product) String() string

type Report

type Report struct {
	Product
	Grams uint32
	When  time.Time
}

Report represents a row in the Reports table.

type User

type User struct {
	ID       int
	Name     string
	Limit    uint32
	Location *time.Location
}

User represents a row in the USER table.

Jump to

Keyboard shortcuts

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