Documentation
¶
Overview ¶
Package models interfaces with the SQLite DB
Index ¶
- Variables
- func Close()
- func CreateIngredient(ingredient string, viscosity float32) error
- func DeleteDrink(id int64) error
- func DeleteIngredient(ingredient string) error
- func Open(file string) error
- func UpdateIngredient(ingredient string, viscosity float32) error
- func UpdatePump(id int, flowrate float32, ingredient string) error
- type Drink
- type DrinkIngredient
- type Ingredient
- type Pump
Constants ¶
This section is empty.
Variables ¶
var DB *sql.DB
DB is our connection so we dont' have to keep opening / closing
Functions ¶
func CreateIngredient ¶
CreateIngredient puts a new ingredient in the db
func DeleteDrink ¶
DeleteDrink removes the drink and its ingredients from the db
func DeleteIngredient ¶
DeleteIngredient lets users cover up their mistakes because they probably typoed something
func UpdateIngredient ¶
UpdateIngredient lets a user update the viscosity of the fluid, if we ever need that
Types ¶
type Drink ¶
type Drink struct {
ID int64 `sql:"drink_id" json:"id"`
Name string `sql:"name" json:"name"`
Notes string `sql:"notes" json:"notes"`
Ingredients []*DrinkIngredient `json:"ingredients"`
}
Drink is the model of the drinks table
func CreateDrink ¶
CreateDrink puts a drink in the drinks table, ingredients are added elsewhere
func GetAllDrinks ¶
GetAllDrinks returns all the drinks in the system ordered by name if simple is true, don't populate the ingredients
func GetDrink ¶
GetDrink returns the drink + ingredients to the user, it looks it up by id or name in that order
func UpdateDrink ¶
UpdateDrink lets the user update the name / notes of a drink, for ingredient updates call ClearIngredients / AddIngredient
func (*Drink) AddIngredient ¶
AddIngredient adds an entry to the drink_ingredients table
func (*Drink) ClearIngredients ¶
ClearIngredients deletes all the drink_ingredients rows for a drink, this would be in prep to add new ones, that is far easier than any complicated comparison of what we want vs what we have
type DrinkIngredient ¶
type DrinkIngredient struct {
Ingredient string `sql:"ingredient" json:"ingredient"`
Amount float32 `sql:"amount" json:"amount"`
Units string `sql:"units" json:"units"`
Dispense bool `sql:"dispense" json:"dispense"`
DrinkID int64 `sql:"drink_id" json:"drink_id"`
}
DrinkIngredient is the model of the drink_ingredients table
type Ingredient ¶
Ingredient is the model of the db table ingredients
func GetAllIngredients ¶
func GetAllIngredients() ([]*Ingredient, error)
GetAllIngredients returns all ingredients sorted by name from the db
func GetIngredient ¶
func GetIngredient(name string) (*Ingredient, error)
GetIngredient returns the ingredient row for the given name
type Pump ¶
type Pump struct {
ID int `sql:"pump_id"`
FlowRate float32 `sql:"flow_rate"`
Ingredient sql.NullString `sql:"ingredient"`
Pin string `sql:"gpio_pin"`
}
Pump is the model of the db table pumps it is similar to hw.Pump except this should match types to the db
func GetAllPumps ¶
GetAllPumps returns an ordered list of all the pumps in the DB