-
Notifications
You must be signed in to change notification settings - Fork 8
/
interface.go
51 lines (43 loc) · 1.4 KB
/
interface.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 kvi
// Options are the options for loading the KeyValue driver
type Options struct {
BulkLoad bool
}
// KVBuilder is function implemented by the various key/value storage drivers
// that returns an initialized KVInterface given a file/path argument
type KVBuilder func(path string, opts Options) (KVInterface, error)
// KVInterface is the base interface for key/value based graph driver
type KVInterface interface {
HasKey(key []byte) bool
Set(key, value []byte) error
Get(key []byte) ([]byte, error)
DeletePrefix(prefix []byte) error
Delete(key []byte) error
View(func(it KVIterator) error) error
Update(func(tx KVTransaction) error) error
BulkWrite(func(bl KVBulkWrite) error) error
Close() error
}
// KVIterator is a genetic interface used by KVInterface.View to allow the
// KVGraph to scan the values stored in the key value driver
type KVIterator interface {
Seek(k []byte) error
SeekReverse(k []byte) error
Valid() bool
Key() []byte
Value() ([]byte, error)
Next() error
Get(key []byte) ([]byte, error)
}
type KVBulkWrite interface {
Set(key, value []byte) error
}
// KVTransaction is a generic interface used by KVInterface.Update to allow the
// KVGraph to alter the values stored in the key value driver
type KVTransaction interface {
Get(key []byte) ([]byte, error)
HasKey(key []byte) bool
Set(key, value []byte) error
Delete(key []byte) error
View(func(it KVIterator) error) error
}