store

package
v0.0.0-...-c739cb8 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2020 License: MPL-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DB

type DB interface {
	PutTree(*objects.Tree) (string, error)
	GetTree(string) (*objects.Tree, error)
	ListTrees(*ListOpts) ([]*objects.Tree, error)
	UpdateTree(*objects.Tree) error
	DeleteTree(string) error
}

DB represents the storage needs of a harvest games' manager

type ListOpts

type ListOpts struct {
	RadiusMeters int               `json:"radius,omitempty"`
	Location     *objects.Location `json:"location,omitempty"`
	TaggedBy     []string          `json:"tagged_by,omitempty"`
	Species      []string          `json:"species,omitempty"`
}

ListOpts represents applicable filters when querying the db for a list of trees

type Memory

type Memory struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Memory implements the Store interface in-memory (mock)

func NewMemory

func NewMemory() *Memory

NewMemory is the constructor for a Memory storage

func (*Memory) DeleteTree

func (m *Memory) DeleteTree(id string) error

DeleteTree deletes a tree from the store

func (*Memory) GetTree

func (m *Memory) GetTree(id string) (*objects.Tree, error)

GetTree reads a tree from the store

func (*Memory) ListTrees

func (m *Memory) ListTrees(opts *ListOpts) ([]*objects.Tree, error)

ListTrees gets a list of trees from the db

func (*Memory) PutTree

func (m *Memory) PutTree(tree *objects.Tree) (string, error)

PutTree writes a new tree to the store

func (*Memory) UpdateTree

func (m *Memory) UpdateTree(tree *objects.Tree) error

UpdateTree updates a tree in the store

type Mongo

type Mongo struct {
	// contains filtered or unexported fields
}

Mongo implements the DB interface in mongodb

func NewMongo

func NewMongo(connStr, db string) (*Mongo, error)

NewMongo is the constructor for a Mongo type Store

the format of the mongo connection string is: mongodb://<user>:<pass>@<url>:<port>/<dbname>

func (*Mongo) DeleteTree

func (m *Mongo) DeleteTree(id string) error

DeleteTree deletes a tree from the db

func (*Mongo) GetTree

func (m *Mongo) GetTree(id string) (*objects.Tree, error)

GetTree reads a tree from the db

func (*Mongo) ListTrees

func (m *Mongo) ListTrees(opts *ListOpts) ([]*objects.Tree, error)

ListTrees gets a list of trees from the db note: opts must be validated before passing it this function

func (*Mongo) PutTree

func (m *Mongo) PutTree(tree *objects.Tree) (string, error)

PutTree writes a new tree to the db

func (*Mongo) UpdateTree

func (m *Mongo) UpdateTree(tree *objects.Tree) error

UpdateTree updates a tree in the db

Jump to

Keyboard shortcuts

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