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) ComponentsPresent() (bool, error)
- func (db DB) DeleteComponent(id int64) 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) GetParents(child int64) ([]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
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) 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) 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) GetParents ¶
GetParents finds all parents for the given child in the database.
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 ¶
Update 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.