tkv
This commit is contained in:
parent
e9df8925d1
commit
609d69fb5a
1 changed files with 24 additions and 0 deletions
24
src/tkv/new.go
Normal file
24
src/tkv/new.go
Normal 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
|
||||||
|
}
|
Loading…
Reference in a new issue