From 609d69fb5a965dd07fe1341bd86d07bedbb9292d Mon Sep 17 00:00:00 2001 From: royalcat Date: Mon, 17 Jun 2024 00:23:29 +0300 Subject: [PATCH] tkv --- src/tkv/new.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/tkv/new.go diff --git a/src/tkv/new.go b/src/tkv/new.go new file mode 100644 index 0000000..ded1cef --- /dev/null +++ b/src/tkv/new.go @@ -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 +}