stores

package
v0.0.0-...-89bf0d2 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2018 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrUnknownClause = errors.New("unknown clause")

ErrUnknownClause is returned when the update clause is not known.

Functions

func NewStorageController

func NewStorageController(store Interface, spec usher.Spec) usher.Controller

NewStorageController initializes a StorageController with given 'store' as the storage backend. If 'spec' is not nil, it will be assumed to be the type for `obj.Spec` field and type assertion will be done before reading.

Types

type ByParents

type ByParents struct {
	Parents usher.ParentRefs
}

ByParents is used to filter results by parents.

type ByState

type ByState struct {
	State string
}

ByState is used to filter results based on state

type ByTags

type ByTags struct {
	Tags map[string]string
}

ByTags is used to filter results by tags

type Interface

type Interface interface {

	// Get should populate `obj` with data in the first object that
	// exactly and completely matches the `id`. If no object found,
	// return value should be 404.
	Get(obj *usher.Object, id usher.ObjectID) *usher.Error

	// GetLatest should get the latest object matches all the query clauses
	// specified as `[]qa`. If no object found, return value should be 404.
	GetLatest(obj *usher.Object, kind string, qa ...interface{}) *usher.Error

	// GetAll should get all objects of given 'kind' matching all clauses
	// from 'qa'. If not object found, return value should be nil and `objList`
	// should be empty slice.
	GetAll(objList *[]usher.Object, kind string, qa ...interface{}) *usher.Error

	// Exists should return true if an object with the given `id` exists in the
	// storage.
	Exists(id usher.ObjectID) *usher.Error

	// Delete should delete the object identified by the `id` and populate `obj`
	// with the data from the deleted object.
	Delete(obj *usher.Object, id usher.ObjectID) *usher.Error

	// Update should apply ALL the updates provided as slice of 'UpdateClause'
	// to the object identified by the `id`. Finally, the 'obj' pointer must
	// point to the updated object.
	Update(obj *usher.Object, id usher.ObjectID, updates []usher.UpdateClause) *usher.Error

	// Create should Store the 'obj' into the Store as-is. Timestamps should be
	// set to the time at which the Store committed the object to backend.
	Create(obj *usher.Object) *usher.Error
}

Interface can be implemented to provide easy storage for Usher.

type StorageController

type StorageController struct {

	// Store to be used for storing objects
	Store Interface

	// Type of the 'spec' field (used only for validation
	Type reflect.Type
}

StorageController is a basic implementation of Usher Controller with storage support.

func (*StorageController) Create

func (sc *StorageController) Create(obj usher.Object) (*usher.Object, *usher.Error)

func (*StorageController) Delete

func (sc *StorageController) Delete(id usher.ObjectID) (*usher.Object, *usher.Error)

func (*StorageController) Exists

func (sc *StorageController) Exists(id usher.ObjectID) *usher.Error

func (*StorageController) Get

func (*StorageController) GetAll

func (sc *StorageController) GetAll(query usher.Query) (*[]usher.Object, *usher.Error)

GetAll handles `GET /{kind}`

func (*StorageController) PartialUpdate

func (sc *StorageController) PartialUpdate(id usher.ObjectID, updates []usher.UpdateClause) (*usher.Object, *usher.Error)

func (*StorageController) Update

func (sc *StorageController) Update(id usher.ObjectID, newObject usher.Object) (*usher.Object, *usher.Error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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