forked from yihuang/cometbft-db
-
Notifications
You must be signed in to change notification settings - Fork 5
/
prefixdb_batch.go
51 lines (43 loc) · 978 Bytes
/
prefixdb_batch.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package db
type prefixDBBatch struct {
prefix []byte
source Batch
}
var _ Batch = (*prefixDBBatch)(nil)
func newPrefixBatch(prefix []byte, source Batch) prefixDBBatch {
return prefixDBBatch{
prefix: prefix,
source: source,
}
}
// Set implements Batch.
func (pb prefixDBBatch) Set(key, value []byte) error {
if len(key) == 0 {
return errKeyEmpty
}
if value == nil {
return errValueNil
}
pkey := append(cp(pb.prefix), key...)
return pb.source.Set(pkey, value)
}
// Delete implements Batch.
func (pb prefixDBBatch) Delete(key []byte) error {
if len(key) == 0 {
return errKeyEmpty
}
pkey := append(cp(pb.prefix), key...)
return pb.source.Delete(pkey)
}
// Write implements Batch.
func (pb prefixDBBatch) Write() error {
return pb.source.Write()
}
// WriteSync implements Batch.
func (pb prefixDBBatch) WriteSync() error {
return pb.source.WriteSync()
}
// Close implements Batch.
func (pb prefixDBBatch) Close() error {
return pb.source.Close()
}