arnaucube
arnaucube/asmtPublic Self-hosted repository
asmt/db/types.go
db/types.goRaw
 1/**
 2 *  @file
 3 *  @copyright defined in aergo/LICENSE.txt
 4 */
 5
 6package db
 7
 8// ImplType represents implementators of a DB interface
 9type ImplType string
10
11const (
12	// LevelImpl represents a name of DB interface implementation using leveldb
13	LevelImpl ImplType = "leveldb"
14
15	// MemoryImpl represents a name of DB interface implementation in memory
16	MemoryImpl ImplType = "memorydb"
17)
18
19type dbConstructor func(dir string) (DB, error)
20
21// DB is an general interface to access at storage data
22type DB interface {
23	Type() string
24	Set(key, value []byte)
25	Delete(key []byte)
26	Get(key []byte) []byte
27	Exist(key []byte) bool
28	Iterator(start, end []byte) Iterator
29	NewTx() Transaction
30	NewBulk() Bulk
31	Close()
32	//Print()
33	//Stats() map[string]string
34}
35
36// Transaction is used to batch multiple operations
37type Transaction interface {
38	//	Get(key []byte) []byte
39	Set(key, value []byte)
40	Delete(key []byte)
41	Commit()
42	Discard()
43}
44
45// Bulk is used to batch multiple transactions
46// This will internally commit transactions when reach maximum tx size
47type Bulk interface {
48	Set(key, value []byte)
49	Delete(key []byte)
50	Flush()
51	DiscardLast()
52}
53
54// Iterator is used to navigate specific key ranges
55type Iterator interface {
56	Next()
57	Valid() bool
58	Key() []byte
59	Value() []byte
60}