-
Notifications
You must be signed in to change notification settings - Fork 9
/
storage.go
69 lines (51 loc) · 1.63 KB
/
storage.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package storage
import "fmt"
var (
ErrorNotFound = fmt.Errorf("not found in DB")
)
type Storage interface {
Write
// Get retrieves the object `value` named by `key`.
// Get will return nil if the key is not mapped to a value.
Get(key []byte) []byte
// Has returns whether the `key` is mapped to a `value`.
Has(key []byte) bool
// Iterator iterates over a DB's key/value pairs in key order.
Iterator(start, end []byte) Iterator
// Prefix iterates over a DB's key/value pairs in key order including prefix.
Prefix(prefix []byte) Iterator
NewBatch() Batch
Close() error
// GetStats return database statistics
GetStats() (interface{}, error)
}
// Write is the write-side of the storage interface.
type Write interface {
// Put stores the object `value` named by `key`.
Put(key, value []byte)
// Delete removes the value for given `key`.
Delete(key []byte)
}
type Iterator interface {
// Next moves the iterator to the next key/value pair.
// It returns false if the iterator is exhausted.
Next() bool
// Prev moves the iterator to the previous key/value pair.
// It returns false if the iterator is exhausted.
Prev() bool
// Seek moves the iterator to the first key/value pair whose key is greater
// than or equal to the given key.
// It returns whether such pair exist.
//
// It is safe to modify the contents of the argument after Seek returns.
Seek(key []byte) bool
// Key returns the key of the current key/value pair, or nil if done.
Key() []byte
// Value returns the value of the current key/value pair, or nil if done.
Value() []byte
}
type Batch interface {
Put(key, value []byte)
Delete(key []byte)
Commit()
}