db

package
v0.0.0-...-f683377 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2019 License: GPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StepPrepare = iota
	StepMash
	StepBoil
	StepFermentation
	StepBottle
	StepDone
	StepMax = StepDone
)

Brew steps.

Variables

This section is empty.

Functions

func GenToken

func GenToken(sz int) string

Generates a random 32 chars token.

func StepName

func StepName(step int64) (string, string)

Translate steps to names and descriptions.

Types

type Brew

type Brew struct {
	Id       int64
	RecipeId int64
	UserId   int64
	Step     int64
	File     string
	XML      *beerxml.Recipe
}

Represents a brew.

type DB

type DB struct {
	*sql.DB
	Styles *[]beerxml.Style
	// contains filtered or unexported fields
}

func Open

func Open(rootdir string) (*DB, error)

Open a database, and create it if it does not exists.

func (*DB) ActivateUser

func (db *DB) ActivateUser(token string) error

Activate an user based on a provided token.

func (*DB) AddBrew

func (db *DB) AddBrew(b *Brew) (int64, error)

Add a new brew.

func (*DB) AddIngredient

func (db *DB) AddIngredient(i *Ingredient) error

Add a new ingredient.

func (*DB) AddRecipe

func (db *DB) AddRecipe(r *Recipe) (int64, error)

Add a new recipe.

func (*DB) AddUser

func (db *DB) AddUser(name, password, token string, verification bool) error

Adds a new user.

func (*DB) DeleteBrew

func (db *DB) DeleteBrew(b *Brew) error

Delete a brew.

func (*DB) DeleteIngredient

func (db *DB) DeleteIngredient(i *Ingredient) error

Delete an ingredient.

func (*DB) DeleteRecipe

func (db *DB) DeleteRecipe(r *Recipe) error

Delete a recipe.

func (*DB) DeleteUser

func (db *DB) DeleteUser(u *User) error

Delete an user and all its data.

func (*DB) GetBrew

func (db *DB) GetBrew(id int64) (*Brew, error)

Retrieve a single brew given its id.

func (*DB) GetIngredient

func (db *DB) GetIngredient(id int64) (*Ingredient, error)

Retrieve a single ingredient given its id.

func (*DB) GetRecipe

func (db *DB) GetRecipe(id int64) (*Recipe, error)

Retrives a recipe given its id.

func (*DB) GetUserBrews

func (db *DB) GetUserBrews(uid int64) ([]*Brew, error)

Retrieve all brews for a given user.

func (*DB) GetUserByEmail

func (db *DB) GetUserByEmail(email string) (*User, error)

Retrieves an user information from the db, given an email.

func (*DB) GetUserById

func (db *DB) GetUserById(uid int64) (*User, error)

Retrieves an user information from the db, given an uid.

func (*DB) GetUserIngredients

func (db *DB) GetUserIngredients(uid int64) ([]*Ingredient, error)

Retrieve the ingredients for a given user.

func (*DB) GetUserRecipes

func (db *DB) GetUserRecipes(uid int64) ([]*Recipe, error)

Retrieves all recipes for a given user.

func (*DB) HashPassword

func (db *DB) HashPassword(user, password string) (string, error)

Hashes a plaintext password.

func (*DB) LoadKey

func (db *DB) LoadKey(name string, length int) []byte

Load a persistent key or generate one if it do not exist.

func (*DB) UpdateBrew

func (db *DB) UpdateBrew(b *Brew) error

Update a brew.

func (*DB) UpdateIngredient

func (db *DB) UpdateIngredient(i *Ingredient) error

Update an ingredient.

func (*DB) UpdateRecipe

func (db *DB) UpdateRecipe(r *Recipe) error

Update a recipe.

func (*DB) UpdateUser

func (db *DB) UpdateUser(u *User) error

Update an user info.

type Ingredient

type Ingredient struct {
	Id     int64
	UserId int64
	Name   string
	Type   string
	Link   string
	File   string
	XML    interface{}
}

Represents an ingredient (fermentable, hops, yeats, ...) in an user inventory and contains a path to its associated BeerXML file.

type Recipe

type Recipe struct {
	Id     int64
	UserId int64
	Name   string
	File   string
	Public bool
	XML    *beerxml.Recipe
}

Represents a recipe and contains a path to its associated BeerXML file.

type User

type User struct {
	Id               int64
	Email            string
	Password         string
	RegistrationDate string
	Token            string
	Enabled          bool
	Lang             string
}

Represents an user.

Jump to

Keyboard shortcuts

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