Documentation
¶
Index ¶
- type Component
- type ComponentFilter
- type ComponentType
- type DB
- func (db DB) AddComponent(component Component) (id int64, token string, err error)
- func (db DB) AttachGrowInfo(compID int64, yield *int, yieldComment string) error
- func (db DB) ComponentsPresent() (bool, error)
- func (db DB) DeleteComponent(id int64) error
- func (db DB) DeleteGrowInfoIfPresent(compID int64) (bool, error)
- func (db DB) FindComponents(filter ComponentFilter) ([]Component, error)
- func (db DB) GetAllSpecies() ([]string, error)
- func (db DB) GetChildren(parent int64) ([]int64, error)
- func (db DB) GetComponent(id int64) (Component, error)
- func (db DB) GetComponents(ids []int64) (components []Component, err error)
- func (db DB) GetGrowInfo(id int64) (GrowInfo, error)
- func (db DB) GetParents(child int64) ([]int64, error)
- func (db DB) GetYields(compFilter ComponentFilter) (map[int64]*int, error)
- func (db DB) MarkComponentsAsGone(ids []int64) error
- func (db DB) SetParents(child int64, parents []int64) error
- func (db DB) UpdateComponent(id int64, createdAt time.Time, notes string, gone bool) error
- func (db DB) UpdateSpecies(ids []int64, species string) error
- type GrowInfo
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Component ¶
type Component struct {
ID int64
Type ComponentType
Species string
Token string // A short token helping humans identify the component.
// Time at which a sporeprint was taken, mycelium or spawn was
// inoculated or a grow was started. Will only be stored as a date, the
// exact time of day will be ignored.
CreatedAt time.Time
Notes string
Gone bool // True, if the component does not exist physically anymore.
}
A Component is one node in a family tree. Type will signify whether it's spores, mycelium, spawn or a grow.
type ComponentFilter ¶
type ComponentFilter struct {
Types []ComponentType // If empty, all types will be matched.
Species []string // If empty, all species will be matched.
Since *time.Time // If nil, no filtering will occur.
Until *time.Time // If nil, no filtering will occur.
Gone *bool // If nil, no filtering will occur.
}
A ComponentFilter can contain filter criteria for finding components.
type ComponentType ¶
type ComponentType string
ComponentType signifies the type of a component and determines which relationships are legal for a component.
const ( TypeSpores ComponentType = "SPORES" TypeMycelium ComponentType = "MYC" TypeSpawn ComponentType = "SPAWN" TypeGrow ComponentType = "GROW" )
type DB ¶
DB is the database used to store all persistent data.
func GetDB ¶
GetDB returns the database. If it does not exist, it will be created and initialized first.
func (DB) AddComponent ¶
AddComponent adds a new component. ID and Token will be generated and returned. Type and CreatedAt must be specified.
func (DB) AttachGrowInfo ¶ added in v0.2.0
AttachGrowInfo adds or updates an entry to the grow table. yield is the total yield of a grow in milligrams.
func (DB) ComponentsPresent ¶
ComponentsPresent returns true if the database contains at least one component.
func (DB) DeleteComponent ¶
DeleteComponent deletes a component and all its relationships from the database.
func (DB) DeleteGrowInfoIfPresent ¶ added in v0.2.0
DeleteGrowInfoIfPresent deletes the grow info with the given ID. If the entry was successfully removed, true is returned, if there was no entry, false is returned.
func (DB) FindComponents ¶
func (db DB) FindComponents(filter ComponentFilter) ([]Component, error)
FindComponents retrieves all components matching the given filter from the database.
func (DB) GetAllSpecies ¶
GetAllSpecies returns a list of all different species that components posses.
func (DB) GetChildren ¶
GetChildren finds all children for the given parent in the database.
func (DB) GetComponent ¶
GetComponent retrieves the component with the given ID from the database. If the component cannot be found, an error will be returned.
func (DB) GetComponents ¶
GetComponents retrieves the components for the given IDs from the database. If any component cannot be found, an error will be returned.
func (DB) GetGrowInfo ¶ added in v0.2.0
GetGrowInfo finds the additional grow information for a component in the database. If there is none, the default info will be returned.
func (DB) GetParents ¶
GetParents finds all parents for the given child in the database.
func (DB) GetYields ¶ added in v0.2.0
func (db DB) GetYields(compFilter ComponentFilter) (map[int64]*int, error)
GetYields finds the yields in milligrams for the components matching the given compFilter.
func (DB) MarkComponentsAsGone ¶ added in v0.2.0
MarkComponentsAsGone sets gone to "true" for the components with the given IDs.
func (DB) SetParents ¶
SetParents stores the relationships between child and its parents in the database. An error will be returned if the species of a parent does not match the one of the child or if a parent has not been created before the child.
func (DB) UpdateComponent ¶
UpdateComponent updates the component with the given ID. If the ID does not exist, an error will be returned. createdAt must be after all its parents.