index

package
v0.8.1 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2023 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

Types

type Field

type Field interface {
	// Value returns the value of the field
	Value() protoreflect.Value
	// Keys returns an iterator over the keys of the messages that have this value for this field
	Keys(ctx context.Context) (Iterator[string], error)
	// Descriptors returns the field descriptors for this field
	Descriptors() []protoreflect.FieldDescriptor
}

Field is an indexed field in the index

type FieldReader

type FieldReader interface {
	// Get returns the field for the given field descriptor
	Get(ctx context.Context, f protoreflect.Name) (Iterator[Field], bool, error)
}

FieldReader is an interface for reading a type fields from the index

type Func

type Func func(ctx context.Context, fds ...protoreflect.FieldDescriptor) (bool, error)

Func is a function that is called to determine if a field should be indexed It takes a context and a list of field descriptors that represent the path to the field It returns a bool indicating if the field should be indexed or not and an error if any

type Index

type Index interface {
	// Insert inserts and indexes the given message with the given key
	Insert(ctx context.Context, k string, m proto.Message) error
	// Update updates the index for the given message with the given key
	Update(ctx context.Context, k string, m proto.Message) error
	// Remove removes the given key from the index
	Remove(ctx context.Context, k string) error
	// Find returns the keys of the messages that match the given FieldFilterer
	Find(ctx context.Context, t protoreflect.FullName, f filters.FieldFilterer) ([]string, error)
}

Index is a protobuf message index

func New

func New(s Store, fn Func) Index

New creates a new index using the given store and index function If the store is nil, a new in-memory store is created If the index function is nil, all fields are indexed

type Iterator

type Iterator[T any] interface {
	Next() bool
	Value() (T, error)
}

Iterator is an interface for iterating over a collection of values It is used by the Index to iterate over the values of a field that can be stored in a remote database

type Store

type Store interface {
	// For returns a FieldReader for the given message type.
	For(ctx context.Context, t protoreflect.FullName) (FieldReader, error)
	// Add adds a value to the store for the given key and field descriptor.
	Add(ctx context.Context, k string, v protoreflect.Value, fds ...protoreflect.FieldDescriptor) error
	// Remove removes a value from the store for the given key and field descriptor.
	Remove(ctx context.Context, k string, f protoreflect.FieldDescriptor, v protoreflect.Value) error
	// Clear removes all values from the store for the given key.
	Clear(ctx context.Context, k string) error
}

Store is an interface for storing and retrieving protobuf message fields.

type Tx

type Tx interface {
	Store
	// Commit commits the transaction.
	Commit(ctx context.Context) error
	// Close closes the transaction.
	// If the transaction has not been committed, it will be rolled back.
	// If the transaction has been committed, it should be a no-op.
	Close() error
}

Tx is an interface for a transaction.

type Txer

type Txer interface {
	// Tx returns a transaction.
	Tx(ctx context.Context) (Tx, error)
}

Txer is an interface for a transactioner.

Jump to

Keyboard shortcuts

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