store

package
v0.0.102-dev Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2025 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 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) error

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