entity

package
v0.0.0-...-157c9c8 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ErrKeyNotFound is returned by Load when the key is not found the Store.
	ErrKeyNotFound = lerr.Str("key not found")
	// ErrIndexNotFound
	ErrIndexNotFound       = lerr.Str("index not found")
	ErrIndexNameBlank      = lerr.Str("index name was blank")
	ErrIndexAlreadyDefined = lerr.Str("an index with the given name already exists")
)

Variables

This section is empty.

Functions

This section is empty.

Types

type BaseIndexer

type BaseIndexer[E Entity] struct {
	IndexName string
	Fn        func(E) []byte
	M         bool
}

func (BaseIndexer[E]) IndexKey

func (bi BaseIndexer[E]) IndexKey(e E) []byte

func (BaseIndexer[E]) Multi

func (bi BaseIndexer[E]) Multi() bool

func (BaseIndexer[E]) Name

func (bi BaseIndexer[E]) Name() string

type EntKeySetter

type EntKeySetter interface {
	SetEntKey([]byte)
}

EntKeySetter can optionally be fulfilled by an Entity. If it is fulfilled, it will be invoked whenever an Entity is deserialized from a Store.

type EntStore

type EntStore[T Entity] struct {
	Init func() T
	store.Store
	serial.Serializer
	serial.Deserializer
	IdxStore store.Store
	// contains filtered or unexported fields
}

EntStore provides methods for saving and retreiving and Entity from a Store. The Serializer and Deserializer will be used for the Entity Value while EntKey will be used for the key.

func (*EntStore[T]) AddIndex

func (es *EntStore[T]) AddIndex(name string, multi bool, fn func(T) []byte) StoreIndex[T]

func (*EntStore[T]) AddIndexer

func (es *EntStore[T]) AddIndexer(idx Indexer[T]) StoreIndex[T]

func (*EntStore[T]) Get

func (es *EntStore[T]) Get(key []byte) (found bool, ent T, err error)

Get an entity by key.

func (*EntStore[T]) GetIter

func (es *EntStore[T]) GetIter(i liter.Iter[[]byte], buf []T) ([]T, error)

func (*EntStore[T]) GetSlice

func (es *EntStore[T]) GetSlice(fn filter.Filter[[]byte], buf []T) ([]T, error)

GetSlice returns all entities in the Store if fn is nil and if fn is defined it returns all entities for which fn returns true given their key. If buf is provided, it will be used as the return slice.

func (*EntStore[T]) Index

func (es *EntStore[T]) Index(name string) (StoreIndex[T], bool)

func (*EntStore[T]) Load

func (es *EntStore[T]) Load(ent T) error

Load an entity. This requires that EntKey returns the key of the value to be loaded.

func (*EntStore[T]) Put

func (es *EntStore[T]) Put(ent T, buf []byte) ([]byte, error)

Put writes an entity to the store. If buf is provided, it will be used for Serialization.

type Entity

type Entity interface {
	EntKey() []byte
}

Entity to be written to Store by EntKey.

type Indexer

type Indexer[E Entity] interface {
	Name() string
	IndexKey(E) []byte
	Multi() bool
}

type StoreIndex

type StoreIndex[E Entity] struct {
	// contains filtered or unexported fields
}

func (StoreIndex[E]) Lookup

func (si StoreIndex[E]) Lookup(idxKey []byte) (entIds liter.Iter[[]byte], err error)

func (StoreIndex[E]) LookupEnts

func (si StoreIndex[E]) LookupEnts(idxKey []byte) (ents slice.Slice[E], err error)

func (StoreIndex[E]) MultiEntLookup

func (si StoreIndex[E]) MultiEntLookup(idxKeys liter.Iter[[]byte]) (ents slice.Slice[E], err error)

func (StoreIndex[E]) MultiLookup

func (si StoreIndex[E]) MultiLookup(idxKeys liter.Iter[[]byte]) (entIds liter.Iter[[]byte], err error)

func (StoreIndex[E]) Search

func (si StoreIndex[E]) Search(f filter.Filter[[]byte]) (idxKeys liter.Iter[[]byte], err error)

func (StoreIndex[E]) SearchEnts

func (si StoreIndex[E]) SearchEnts(f filter.Filter[[]byte]) (ents slice.Slice[E], err error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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