github.com/chain5j/chain5j-pkg@v1.0.7/database/kvstore/database.go (about)

     1  // Package kvstore
     2  //
     3  // @author: xwc1125
     4  package kvstore
     5  
     6  import "io"
     7  
     8  // KeyValueReader wraps the Has and Get method of a backing data store.
     9  type KeyValueReader interface {
    10  	// Has retrieves if a key is present in the key-value data store.
    11  	Has(key []byte) (bool, error)
    12  
    13  	// Get retrieves the given key if it's present in the key-value data store.
    14  	Get(key []byte) ([]byte, error)
    15  }
    16  
    17  // KeyValueWriter wraps the Put method of a backing data store.
    18  type KeyValueWriter interface {
    19  	// Put inserts the given value into the key-value data store.
    20  	Put(key []byte, value []byte) error
    21  
    22  	// Delete removes the key from the key-value data store.
    23  	Delete(key []byte) error
    24  }
    25  
    26  // Stater wraps the Stat method of a backing data store.
    27  type Stater interface {
    28  	// Stat returns a particular internal stat of the database.
    29  	Stat(property string) (string, error)
    30  }
    31  
    32  // Compacter wraps the Compact method of a backing data store.
    33  type Compacter interface {
    34  	// Compact flattens the underlying data store for the given key range. In essence,
    35  	// deleted and overwritten versions are discarded, and the data is rearranged to
    36  	// reduce the cost of operations needed to access them.
    37  	//
    38  	// A nil start is treated as a key before all keys in the data store; a nil limit
    39  	// is treated as a key after all keys in the data store. If both is nil then it
    40  	// will compact entire data store.
    41  	Compact(start []byte, limit []byte) error
    42  }
    43  
    44  // KeyValueStore contains all the methods required to allow handling different
    45  // key-value data stores backing the high level database.
    46  type KeyValueStore interface {
    47  	KeyValueReader
    48  	KeyValueWriter
    49  	Batcher
    50  	Iteratee
    51  	Stater
    52  	Compacter
    53  	io.Closer
    54  }
    55  
    56  // Reader contains the methods required to read data from both key-value as well as
    57  // immutable ancient data.
    58  type Reader interface {
    59  	KeyValueReader
    60  }
    61  
    62  // Writer contains the methods required to write data to both key-value as well as
    63  // immutable ancient data.
    64  type Writer interface {
    65  	KeyValueWriter
    66  }
    67  
    68  // Database contains all the methods required by the high level database to not
    69  // only access the key-value data store but also the chain freezer.
    70  type Database interface {
    71  	Reader
    72  	Writer
    73  	Batcher
    74  	Iteratee
    75  	Stater
    76  	Compacter
    77  	io.Closer
    78  }