The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
grafana/pkg/infra/x/persistentcollection/model.go

21 lines
958 B

package persistentcollection
import (
"context"
)
type Predicate[T any] func(item T) (bool, error)
type UpdateFn[T any] func(item T) (updated bool, updatedItem T, err error)
// PersistentCollection is a collection of items that's going to retain its state between Grafana restarts.
// The main purpose of this API is to reduce the time-to-Proof-of-Concept - this is NOT intended for production use.
//
// The item type needs to be serializable to JSON.
// @alpha -- EXPERIMENTAL
type PersistentCollection[T any] interface {
Delete(ctx context.Context, namespace string, predicate Predicate[T]) (deletedCount int, err error)
FindFirst(ctx context.Context, namespace string, predicate Predicate[T]) (T, error)
Find(ctx context.Context, namespace string, predicate Predicate[T]) ([]T, error)
Update(ctx context.Context, namespace string, updateFn UpdateFn[T]) (updatedCount int, err error)
Insert(ctx context.Context, namespace string, item T) error
}