genericstore

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2026 License: Apache-2.0, MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Codec

type Codec[T any] interface {
	Encode(T) ([]byte, error)
	Decode([]byte) (T, error)
}

Codec defines encoding/decoding for a value type.

type Config

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

Config holds configuration options for a generic store.

type Option

type Option func(*Config)

Option is a functional option for configuring a generic store.

func WithNamespace

func WithNamespace(namespace string) Option

WithNamespace sets a key namespace that is prepended to all keys. This is useful when multiple logical stores share a single bucket.

type Store

type Store[T any] struct {
	// contains filtered or unexported fields
}

Store is a generic key-value store backed by a ListableStore.

func New

func New[T any](backend objectstore.ListableStore, codec Codec[T], opts ...Option) *Store[T]

New creates a new generic store. By default, no namespace is used. Use WithNamespace to add a key namespace when multiple stores share the same backend.

func (*Store[T]) Delete

func (s *Store[T]) Delete(ctx context.Context, key string) error

Delete removes a value by its key.

func (*Store[T]) Exists

func (s *Store[T]) Exists(ctx context.Context, key string) (bool, error)

Exists checks if a key exists (exact match).

func (*Store[T]) ExistsWithPrefix

func (s *Store[T]) ExistsWithPrefix(ctx context.Context, keyPrefix string) (bool, error)

ExistsWithPrefix checks if any key with the given prefix exists.

func (*Store[T]) Get

func (s *Store[T]) Get(ctx context.Context, key string) (T, error)

Get retrieves a value by its key.

func (*Store[T]) GetAny

func (s *Store[T]) GetAny(ctx context.Context, keyPrefix string) (T, error)

GetAny retrieves any value matching the given key prefix. Returns store.ErrNotFound if no matching key exists.

func (*Store[T]) GetAnyMatching

func (s *Store[T]) GetAnyMatching(ctx context.Context, keyPrefix string, match func(T) bool) (T, error)

GetAnyMatching retrieves the first value matching the key prefix where the predicate returns true. If match is nil, returns the first value found (equivalent to GetAny). Returns store.ErrNotFound if no matching value exists.

func (*Store[T]) ListPrefix

func (s *Store[T]) ListPrefix(ctx context.Context, keyPrefix string) iter.Seq2[T, error]

ListPrefix returns an iterator over all values with the given key prefix.

func (*Store[T]) Put

func (s *Store[T]) Put(ctx context.Context, key string, value T) error

Put stores a value at the given key.

Jump to

Keyboard shortcuts

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