github.com/iotexproject/iotex-core@v1.14.1-rc1/db/kvstore.go (about) 1 // Copyright (c) 2019 IoTeX Foundation 2 // This source code is provided 'as is' and no warranties are given as to title or non-infringement, merchantability 3 // or fitness for purpose and, to the extent permitted by law, all liability for your use of the code is disclaimed. 4 // This source code is governed by Apache License 2.0 that can be found in the LICENSE file. 5 6 package db 7 8 import ( 9 "github.com/iotexproject/iotex-core/pkg/lifecycle" 10 11 "github.com/iotexproject/iotex-core/db/batch" 12 ) 13 14 type ( 15 // Condition spells the condition for <k, v> to be filtered out 16 Condition func(k, v []byte) bool 17 18 // KVStoreBasic is the interface of basic KV store. 19 KVStoreBasic interface { 20 lifecycle.StartStopper 21 22 // Put insert or update a record identified by (namespace, key) 23 Put(string, []byte, []byte) error 24 // Get gets a record by (namespace, key) 25 Get(string, []byte) ([]byte, error) 26 // Delete deletes a record by (namespace, key) 27 Delete(string, []byte) error 28 } 29 30 // KVStore is a KVStore with WriteBatch API 31 KVStore interface { 32 KVStoreBasic 33 // WriteBatch commits a batch 34 WriteBatch(batch.KVStoreBatch) error 35 // Filter returns <k, v> pair in a bucket that meet the condition 36 Filter(string, Condition, []byte, []byte) ([][]byte, [][]byte, error) 37 } 38 39 // KVStoreWithRange is KVStore with Range() API 40 KVStoreWithRange interface { 41 KVStore 42 // Range gets a range of records by (namespace, key, count) 43 Range(string, []byte, uint64) ([][]byte, error) 44 } 45 46 // KVStoreForRangeIndex is KVStore for range index 47 KVStoreForRangeIndex interface { 48 KVStore 49 // Insert inserts a value into the index 50 Insert([]byte, uint64, []byte) error 51 // SeekNext returns value by the key (if key not exist, use next key) 52 SeekNext([]byte, uint64) ([]byte, error) 53 // Remove removes an existing key 54 Remove([]byte, uint64) error 55 // Purge deletes an existing key and all keys before it 56 Purge([]byte, uint64) error 57 // GetBucketByPrefix retrieves all bucket those with const namespace prefix 58 GetBucketByPrefix([]byte) ([][]byte, error) 59 // GetKeyByPrefix retrieves all keys those with const prefix 60 GetKeyByPrefix(namespace, prefix []byte) ([][]byte, error) 61 // SeekPrev returns value by the key (if key not exist, use previous key) 62 SeekPrev([]byte, uint64) ([]byte, error) 63 } 64 )