This commit is contained in:
royalcat 2024-06-17 00:23:29 +03:00
parent e9df8925d1
commit 609d69fb5a

24
src/tkv/new.go Normal file
View file

@ -0,0 +1,24 @@
package tkv
import (
"path"
"git.kmsign.ru/royalcat/tstor/pkg/kvtrace"
tlog "git.kmsign.ru/royalcat/tstor/src/log"
"github.com/royalcat/kv"
"github.com/royalcat/kv/kvbadger"
"go.opentelemetry.io/otel/attribute"
)
func NewKV[K kv.Bytes, V any](dbdir, name string) (store kv.Store[K, V], err error) {
opts := kvbadger.DefaultOptions(path.Join(dbdir, name))
opts.BadgerOptions.Logger = tlog.BadgerLogger(name, "badger")
store, err = kvbadger.NewBadgerKVBytesKey[K, V](opts)
if err != nil {
return nil, err
}
store = kvtrace.WrapTracing(store, attribute.String("collection", name), attribute.String("database", "badger"))
return store, err
}