models

package
v0.0.0-...-94b89ae Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2019 License: BSD-3-Clause Imports: 3 Imported by: 0

Documentation

Overview

Package models interfaces with the SQLite DB

Index

Constants

This section is empty.

Variables

View Source
var DB *sql.DB

DB is our connection so we dont' have to keep opening / closing

Functions

func Close

func Close()

Close just wraps the regular database Close function

func CreateIngredient

func CreateIngredient(ingredient string, viscosity float32) error

CreateIngredient puts a new ingredient in the db

func DeleteDrink

func DeleteDrink(id int64) error

DeleteDrink removes the drink and its ingredients from the db

func DeleteIngredient

func DeleteIngredient(ingredient string) error

DeleteIngredient lets users cover up their mistakes because they probably typoed something

func Open

func Open(file string) error

Open opens the connection and stashes it in DB

func UpdateIngredient

func UpdateIngredient(ingredient string, viscosity float32) error

UpdateIngredient lets a user update the viscosity of the fluid, if we ever need that

func UpdatePump

func UpdatePump(id int, flowrate float32, ingredient string) error

UpdatePump allows the user to update either the flow rate or the attached ingredient

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

func CreateDrink(name string, notes string) (*Drink, error)

CreateDrink puts a drink in the drinks table, ingredients are added elsewhere

func GetAllDrinks

func GetAllDrinks(simple bool) ([]*Drink, error)

GetAllDrinks returns all the drinks in the system ordered by name if simple is true, don't populate the ingredients

func GetDrink

func GetDrink(id int64, name string) (*Drink, error)

GetDrink returns the drink + ingredients to the user, it looks it up by id or name in that order

func UpdateDrink

func UpdateDrink(id int64, name string, notes string) (*Drink, error)

UpdateDrink lets the user update the name / notes of a drink, for ingredient updates call ClearIngredients / AddIngredient

func (*Drink) AddIngredient

func (d *Drink) AddIngredient(ingredient string, amount float32, units string, dispense bool) error

AddIngredient adds an entry to the drink_ingredients table

func (*Drink) ClearIngredients

func (d *Drink) ClearIngredients() error

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

type Ingredient struct {
	Ingredient string  `sql:"ingredient"`
	Viscosity  float32 `sql:"viscosity"`
}

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

func GetAllPumps() ([]*Pump, error)

GetAllPumps returns an ordered list of all the pumps in the DB

func GetPump

func GetPump(id int) (*Pump, error)

GetPump returns the details of a single pump

Jump to

Keyboard shortcuts

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