datastore

package
Version: v0.0.0-...-45f56e5 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2021 License: Apache-2.0 Imports: 6 Imported by: 16

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	//ErrNilEntity returned when Entity parameter is nil
	ErrNilEntity = errors.New("nil Entity")
	//ErrNilContext returned when Context parameter is nil
	ErrNilContext = errors.New("nil Context")
	//ErrNilKind returned when Kind parameter is nil
	ErrNilKey = errors.New("nil Key")
	//ErrEmptyKindID returned when a key has an empty ID
	ErrEmptyKindID = errors.New("empty Kind id")
	//ErrEmptyKind returned when a key has an empty kind
	ErrEmptyKind = errors.New("empty Kind")
)
View Source
var ErrNoSuchElement = errors.New("no such element")

ErrNoSuchElement if requested element not available

Functions

func IsErrNoSuchEntity

func IsErrNoSuchEntity(err error) bool

IsErrNoSuchEntity check see if error param is of type ErrNoSuchEntity

func Register

func Register(driver Driver)

Register a driver to use for the context

func SafeUnmarshal

func SafeUnmarshal(data []byte, v interface{}) error

SafeUnmarshal sets the json decoder to use number types

Types

type Connection

type Connection interface {

	// Put adds or updates an entity in the datastore using the Key.
	Put(key Key, data JSONMessage) error

	// Get returns an entity from the datastore. Can return ErrNoSuchEntity if the entity does not exists
	Get(key Key) (JSONMessage, error)

	// Delete deletes an entity associated with the key
	Delete(key Key) error

	// Query evaluates the query and returns a list of entities form the datastore
	Query(query esapi.SearchRequest) ([]JSONMessage, error)
}

Connection is the interface for interacting with a datastore

type Context

type Context interface {
	// Get a connection to the datastore
	Connection() (Connection, error)

	// Get the Metrics object from the context
	Metrics() *metrics.Metrics

	// Get and set the user for audit logging
	SetUser(user string)
	User() string
}

Context is the context of the application or request being made

func Get

func Get() Context

Get returns the global Context

func GetNew

func GetNew() Context

GetNew() returns a new global context. This function is not intended for production use, but is for the purpose of getting fresh contexts for performance testing with metrics for troubleshooting.

func GetNewInstance

func GetNewInstance() Context

GetNewInstance returns a new instance of the context object, but with the metrics and connections from the global context object.

type DataStore

type DataStore struct{}

DataStore EntityStore type

func (*DataStore) Delete

func (ds *DataStore) Delete(ctx Context, key Key) error

Delete removes the entity

func (*DataStore) Get

func (ds *DataStore) Get(ctx Context, key Key, entity ValidEntity) error

Get an entity. Return ErrNoSuchEntity if nothing found for the key.

func (*DataStore) Put

func (ds *DataStore) Put(ctx Context, key Key, entity ValidEntity) error

Put adds or updates an entity

type Driver

type Driver interface {
	// GetConnection returns a connection to the datastore.
	GetConnection() (Connection, error)
}

Driver is the interface for a driver to a datastore

type Entity

type Entity interface {
	GetID() string
	GetType() string
}

Entity is the interface for encapsulating an object's name and type for use with modules such as a logger.

type EntityStore

type EntityStore interface {

	// Put adds or updates an entity
	Put(ctx Context, key Key, entity ValidEntity) error

	// Get an entity. Return ErrNoSuchEntity if nothing found for the key.
	Get(ctx Context, key Key, entity ValidEntity) error

	// Delete removes the entity
	Delete(ctx Context, key Key) error
}

EntityStore interface for storing and retrieving data types from a datastore.

func New

func New() EntityStore

New returns a new EntityStore

type ErrNoSuchEntity

type ErrNoSuchEntity struct {
	Key Key
}

ErrNoSuchEntity is returned when no entity was found for a given key.

func (ErrNoSuchEntity) Error

func (e ErrNoSuchEntity) Error() string

type JSONMessage

type JSONMessage interface {
	// Bytes return the JSON bytes of an entity
	Bytes() json.RawMessage
	Version() map[string]int
}

JSONMessage Represents a enity as JSON

func NewJSONMessage

func NewJSONMessage(data []byte, version map[string]int) JSONMessage

NewJSONMessage creates a JSONMessage using the provided bytes. The bytes should represent valid JSON

type Key

type Key interface {
	// Kind is the type of the entity
	Kind() string
	// ID is the id of the entity
	ID() string
}

Key is a unique identifier for an entity. A key is composed of a kind or type of entity and the id of the entity.

func NewKey

func NewKey(kind string, id string) Key

NewKey returns an initialized Key

type Query

type Query interface {

	// Execute performs the query and returns an Results to the results.  For now this query is specific to the
	// underlying Connection and Driver implementation.
	Execute(query esapi.SearchRequest) (Results, error)
}

Query is a query used to search for and return entities from a datastore

func NewQuery

func NewQuery(ctx Context) Query

NewQuery returns a Query type to be executed

type Results

type Results interface {
	// Next retrieves the next available result into entity and advances the Results to the next available entity.
	// ErrNoSuchElement is returned if no more results.
	Next(entity ValidEntity) error

	// HasNext returns true if a call to next would yield a value or false if no more entities are available
	HasNext() bool

	//Len return the length of the results
	Len() int

	//Len return the length of the results
	Get(idx int, entity ValidEntity) error
}

Results iterates or indexes into the results returned from a query

type ValidEntity

type ValidEntity interface {
	ValidEntity() error
	GetType() string
	SetType(string)
	GetSeqNo() int
	SetSeqNo(int)
	GetPrimaryTerm() int
	SetPrimaryTerm(int)
}

ValidEntity interface for entities that can be stored in the EntityStore

type VersionedEntity

type VersionedEntity struct {
	IfSeqNo       int    `json:"-"`
	IfPrimaryTerm int    `json:"-"`
	Type          string `json:"type,omitempty"`
}

func (*VersionedEntity) GetPrimaryTerm

func (e *VersionedEntity) GetPrimaryTerm() int

func (*VersionedEntity) GetSeqNo

func (e *VersionedEntity) GetSeqNo() int

func (*VersionedEntity) GetType

func (e *VersionedEntity) GetType() string

func (*VersionedEntity) SetPrimaryTerm

func (e *VersionedEntity) SetPrimaryTerm(i int)

func (*VersionedEntity) SetSeqNo

func (e *VersionedEntity) SetSeqNo(i int)

func (*VersionedEntity) SetType

func (e *VersionedEntity) SetType(t string)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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