store

package
v2.1.1 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2026 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrElementNotFound = errors.New("element not found")

Functions

This section is empty.

Types

type Collection

type Collection[T any] struct {
	Generation int64
	Elements   []T
}

type ErrConflictGeneration

type ErrConflictGeneration struct {
	ObservedGeneration int64
	StoreGeneration    int64
}

func (ErrConflictGeneration) Error

func (e ErrConflictGeneration) Error() string

type ErrMaxElementsExceeded added in v2.1.0

type ErrMaxElementsExceeded struct {
	Max int
}

ErrMaxElementsExceeded is returned by Upsert when inserting a new element would exceed the configured maximum number of elements in the collection.

func (ErrMaxElementsExceeded) Error added in v2.1.0

func (e ErrMaxElementsExceeded) Error() string

type GenericStore

type GenericStore[T any, H StoreHelper[T]] struct {
	// contains filtered or unexported fields
}

func New

func New[T any, H StoreHelper[T]](
	logger log.Logger, bucket objstore.Bucket, key Key, helper H,
) *GenericStore[T, H]

func (*GenericStore[T, H]) Delete

func (s *GenericStore[T, H]) Delete(ctx context.Context, id string) error

func (*GenericStore[T, H]) Get

func (s *GenericStore[T, H]) Get(ctx context.Context) (*Collection[T], error)

func (*GenericStore[T, H]) Read

func (s *GenericStore[T, H]) Read(ctx context.Context, txn ReadTxn[T]) error

func (*GenericStore[T, H]) Update

func (s *GenericStore[T, H]) Update(
	ctx context.Context,
	txn UpdateTxn[T],
) error

Update will under write lock, call a transaction the Collection. If there is an error returned, the update will be cancelled.

func (*GenericStore[T, H]) Upsert

func (s *GenericStore[T, H]) Upsert(ctx context.Context, elem T, observedGeneration *int64, maxElements int) error

Upsert inserts or updates elem in the collection. If maxElements is greater than 0, inserting a new element is rejected with ErrMaxElementsExceeded once the collection already holds maxElements elements. Updates to an existing element are never affected by maxElements. The check runs inside the write transaction, so the limit is enforced atomically against concurrent upserts.

type Key

type Key struct {
	TenantID string
}

type ReadTxn

type ReadTxn[T any] func(context.Context, *Collection[T]) error

ReadTxn is a transaction that runs under the read lock of the cache. The Collection should not be mutated at all.

type StoreHelper

type StoreHelper[T any] interface {
	ID(T) string
	GetGeneration(T) int64
	SetGeneration(T, int64)
	FromStore(json.RawMessage) (T, error)
	ToStore(T) (json.RawMessage, error)
	TypePath() string
}

type UpdateTxn

type UpdateTxn[T any] func(context.Context, *Collection[T]) error

Jump to

Keyboard shortcuts

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