dsindex

package
v0.0.0-...-e23051b Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2023 License: Apache-2.0, MIT Imports: 8 Imported by: 0

Documentation

Overview

Package dsindex provides secondary indexing functionality for a datastore.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrEmptyKey   = errors.New("key is empty")
	ErrEmptyValue = errors.New("value is empty")
)

Functions

func SyncIndex

func SyncIndex(ctx context.Context, ref, target Indexer) (bool, error)

SyncIndex synchronizes the keys in the target Indexer to match those of the ref Indexer. This function does not change this indexer's key root (name passed into New).

Types

type Indexer

type Indexer interface {
	// Add adds the specified value to the key
	Add(ctx context.Context, key, value string) error

	// Delete deletes the specified value from the key.  If the value is not in
	// the datastore, this method returns no error.
	Delete(ctx context.Context, key, value string) error

	// DeleteKey deletes all values in the given key.  If a key is not in the
	// datastore, this method returns no error.  Returns a count of values that
	// were deleted.
	DeleteKey(ctx context.Context, key string) (count int, err error)

	// DeleteAll deletes all keys managed by this Indexer.  Returns a count of
	// the values that were deleted.
	DeleteAll(ctx context.Context) (count int, err error)

	// ForEach calls the function for each value in the specified key, until
	// there are no more values, or until the function returns false.  If key
	// is empty string, then all keys are iterated.
	ForEach(ctx context.Context, key string, fn func(key, value string) bool) error

	// HasValue determines if the key contains the specified value
	HasValue(ctx context.Context, key, value string) (bool, error)

	// HasAny determines if any value is in the specified key.  If key is
	// empty string, then all values are searched.
	HasAny(ctx context.Context, key string) (bool, error)

	// Search returns all values for the given key
	Search(ctx context.Context, key string) (values []string, err error)
}

Indexer maintains a secondary index. An index is a collection of key-value mappings where the key is the secondary index that maps to one or more values, where each value is a unique key being indexed.

func New

func New(dstore ds.Datastore, name ds.Key) Indexer

New creates a new datastore index. All indexes are stored under the specified index name.

To persist the actions of calling Indexer functions, it is necessary to call dstore.Sync.

Jump to

Keyboard shortcuts

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