tstor/pkg/kvsingle/single.go

29 lines
536 B
Go
Raw Permalink Normal View History

2024-06-14 22:14:44 +00:00
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}
}
2024-06-16 21:34:46 +00:00
func (s *Value[K, V]) Get(ctx context.Context) (V, error) {
2024-06-14 22:14:44 +00:00
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)
}
2024-07-08 21:19:04 +00:00
func (s *Value[K, V]) Edit(ctx context.Context, edit kv.Edit[V]) error {
return s.db.Edit(ctx, s.Key, edit)
}