tstor/pkg/kvsingle/single.go
royalcat 0371af3344
All checks were successful
docker / build-docker (linux/arm64) (push) Successful in 2m10s
docker / build-docker (linux/amd64) (push) Successful in 2m12s
file controller
2024-07-09 00:19:04 +03:00

28 lines
536 B
Go

package kvsingle
import (
"context"
"github.com/royalcat/kv"
)
type Value[K, V any] struct {
Key K
db kv.Store[K, V]
}
func New[K, V any](db kv.Store[K, V], key K) *Value[K, V] {
return &Value[K, V]{Key: key, db: db}
}
func (s *Value[K, V]) Get(ctx context.Context) (V, error) {
return s.db.Get(ctx, s.Key)
}
func (s *Value[K, V]) Set(ctx context.Context, value V) error {
return s.db.Set(ctx, s.Key, value)
}
func (s *Value[K, V]) Edit(ctx context.Context, edit kv.Edit[V]) error {
return s.db.Edit(ctx, s.Key, edit)
}