Skip to content

Commit 7ee866e

Browse files
committed
[db] add Base() method
1 parent 332e0b5 commit 7ee866e

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

db/db_versioned.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ type (
3232
VersionedDB interface {
3333
lifecycle.StartStopper
3434

35+
// Base returns the underlying KVStore
36+
Base() KVStore
37+
3538
// Put insert or update a record identified by (namespace, key)
3639
Put(uint64, string, []byte, []byte) error
3740

@@ -59,8 +62,8 @@ type (
5962

6063
// Namespace specifies the name and key length of the versioned namespace
6164
Namespace struct {
62-
ns string
63-
keyLen uint32
65+
Ns string
66+
KeyLen uint32
6467
}
6568
)
6669

@@ -70,7 +73,7 @@ type BoltDBVersionedOption func(*BoltDBVersioned)
7073
func VnsOption(ns ...Namespace) BoltDBVersionedOption {
7174
return func(k *BoltDBVersioned) {
7275
for _, v := range ns {
73-
k.vns[v.ns] = int(v.keyLen)
76+
k.vns[v.Ns] = int(v.KeyLen)
7477
}
7578
}
7679
}
@@ -122,6 +125,10 @@ func (b *BoltDBVersioned) addVersionedNamespace() error {
122125
return nil
123126
}
124127

128+
func (b *BoltDBVersioned) Base() KVStore {
129+
return b.db
130+
}
131+
125132
// Put writes a <key, value> record
126133
func (b *BoltDBVersioned) Put(version uint64, ns string, key, value []byte) error {
127134
if !b.db.IsReady() {

db/kvstore_versioned.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ import (
1313
"github.com/iotexproject/iotex-core/v2/pkg/lifecycle"
1414
)
1515

16+
const (
17+
// MetadataNamespace is the default namespace to store metadata
18+
MetadataNamespace = "metadata"
19+
)
20+
1621
type (
1722
// KvVersioned is a versioned key-value store, where each key has multiple
1823
// versions of value (corresponding to different heights in a blockchain)
@@ -44,6 +49,9 @@ type (
4449
KvVersioned interface {
4550
lifecycle.StartStopper
4651

52+
// Base returns the underlying KVStore
53+
Base() KVStore
54+
4755
// Version returns the key's most recent version
4856
Version(string, []byte) (uint64, error)
4957

@@ -94,6 +102,10 @@ func (b *KvWithVersion) Stop(ctx context.Context) error {
94102
return b.db.Stop(ctx)
95103
}
96104

105+
func (b *KvWithVersion) Base() KVStore {
106+
return b.db.Base()
107+
}
108+
97109
// Put writes a <key, value> record
98110
func (b *KvWithVersion) Put(ns string, key, value []byte) error {
99111
return b.db.Put(b.version, ns, key, value)

0 commit comments

Comments
 (0)