kv

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: May 15, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type KeyExistsError

type KeyExistsError struct{}

KeyExistsError represents an error caused due to a key which exists.

func (*KeyExistsError) Error

func (e *KeyExistsError) Error() string

type KeyNotFoundError

type KeyNotFoundError struct{}

KeyNotFoundError represents an error caused due to a key which does not exist.

func (*KeyNotFoundError) Error

func (e *KeyNotFoundError) Error() string

type Manager

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

Manager of multiple object stores that are persisted together.

func NewManager

func NewManager(s Store) *Manager

NewManager returns a new manager.

func (*Manager) GetObjectStore

func (m *Manager) GetObjectStore(name string, sampleObject any) store.ObjectStore

GetObjectStore returns a store for a specific object type.

type ObjectStore

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

ObjectStore represents a persistent store of objects, backed by a KV-store. Key format for an object is: <storeName>.<objectName>.

func NewObjectStore

func NewObjectStore(name string, s Store, sampleObject any) *ObjectStore

NewObjectStore returns a new object store backed by a KV-store.

func (*ObjectStore) Create

func (s *ObjectStore) Create(name string, value any) error

Create an object.

func (*ObjectStore) Delete

func (s *ObjectStore) Delete(name string) error

Delete an object identified by the given name.

func (*ObjectStore) GetAll

func (s *ObjectStore) GetAll() ([]any, error)

GetAll returns all of the objects in the store.

func (*ObjectStore) Update

func (s *ObjectStore) Update(name string, mutator func(any) any) error

Update an object.

type Store

type Store interface {
	// Create a (key, value) in the store.
	// Returns KeyExistsError if key already exists.
	Create(key, value []byte) error
	// Update a (key, value) in the store.
	// Returns KeyNotFoundError if key does not exist.
	Update(key []byte, mutator func([]byte) ([]byte, error)) error
	// Delete a key (with its respective value) from the store.
	Delete(key []byte) error
	// Range calls f sequentially for each (key, value) where key starts with the given prefix.
	Range(prefix []byte, f func(key, value []byte) error) error
	// Close frees all resources (e.g. file handles, network sockets) used by the Store.
	Close() error
}

Store represents a key-value store.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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