store

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2022 License: MIT Imports: 7 Imported by: 0

Documentation

Index

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

type DB struct {
	*sql.DB
}

DB is the database used to store all persistent data.

func GetDB

func GetDB(filepath string) (DB, error)

GetDB returns the database. If it does not exist, it will be created and initialized first.

func (DB) AddComponent

func (db DB) AddComponent(component Component) (id int64, token string, err error)

AddComponent adds a new component. ID and Token will be generated and returned. Type and CreatedAt must be specified.

func (DB) ComponentsPresent

func (db DB) ComponentsPresent() (bool, error)

ComponentsPresent returns true if the database contains at least one component.

func (DB) DeleteComponent

func (db DB) DeleteComponent(id int64) error

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

func (db DB) GetAllSpecies() ([]string, error)

GetAllSpecies returns a list of all different species that components posses.

func (DB) GetChildren

func (db DB) GetChildren(parent int64) ([]int64, error)

GetChildren finds all children for the given parent in the database.

func (DB) GetComponent

func (db DB) GetComponent(id int64) (Component, error)

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

func (db DB) GetComponents(ids []int64) (components []Component, err error)

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

func (db DB) GetParents(child int64) ([]int64, error)

GetParents finds all parents for the given child in the database.

func (DB) SetParents

func (db DB) SetParents(child int64, parents []int64) error

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

func (db DB) UpdateComponent(id int64, createdAt time.Time, notes string, gone bool) error

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.

func (DB) UpdateSpecies

func (db DB) UpdateSpecies(ids []int64, species string) error

UpdateSpecies updates the species of all given ids. Make sure to always update all relatives at once to avoid invalid lineages.

Jump to

Keyboard shortcuts

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