Documentation ¶
Overview ¶
Package elldb provides LevelDB database utility.
Index ¶
- Constants
- func MakeKey(key []byte, prefixes ...[]byte) []byte
- func MakePrefix(prefixes ...[]byte) (result []byte)
- type DB
- type KVObject
- type LevelDB
- func (db *LevelDB) Close() error
- func (db *LevelDB) DeleteByPrefix(prefix []byte) error
- func (db *LevelDB) GetByPrefix(prefix []byte) []*KVObject
- func (db *LevelDB) GetFirstOrLast(prefix []byte, first bool) *KVObject
- func (db *LevelDB) Iterate(prefix []byte, first bool, iterFunc func(kv *KVObject) bool) error
- func (db *LevelDB) NewTx() (Tx, error)
- func (db *LevelDB) Open(namespace string) error
- func (db *LevelDB) Put(objs []*KVObject) error
- func (db *LevelDB) Truncate() error
- type Transaction
- func (tx *Transaction) Commit() error
- func (tx *Transaction) DeleteByPrefix(prefix []byte) error
- func (tx *Transaction) Discard()
- func (tx *Transaction) GetByPrefix(prefix []byte) []*KVObject
- func (tx *Transaction) Iterate(prefix []byte, first bool, iterFunc func(kv *KVObject) bool)
- func (tx *Transaction) Put(objs []*KVObject) error
- func (tx *Transaction) Rollback()
- type Tx
- type TxCreator
Constants ¶
const (
// KeyPrefixSeparator is used to separate prefix and key
KeyPrefixSeparator = "@@"
)
Variables ¶
This section is empty.
Functions ¶
func MakePrefix ¶
MakePrefix creates a prefix string
Types ¶
type DB ¶
type DB interface { // Open opens the database Open(namespace string) error // Close closes the database Close() error // Put writes many objects to the database in one atomic request Put([]*KVObject) error // GetByPrefix returns valyes matching a prefix GetByPrefix([]byte) (result []*KVObject) // GetFirstOrLast returns one value matching a prefix. // Set first to return the first value we find or false if the last. GetFirstOrLast(prefix []byte, first bool) *KVObject // Iterate finds a set of objects by prefix and passes them ro iterFunc // for further processing. If iterFunc returns true, the iterator is immediately released. // If first is set to true, it begins from the first item, otherwise, the last Iterate(prefix []byte, first bool, iterFunc func(kv *KVObject) bool) error // DeleteByPrefix deletes one or many records by prefix DeleteByPrefix([]byte) error // Truncate removes all items Truncate() error // NewTx creates a transaction NewTx() (Tx, error) }
DB describes the database access, model and available functionalities
type KVObject ¶
type KVObject struct { Key []byte `json:"key"` Value []byte `json:"value"` Prefix []byte `json:"prefix"` }
KVObject represents an item in the elldb
func FromKeyValue ¶
FromKeyValue takes a key and creates a KVObject
func NewKVObject ¶
NewKVObject creates a key value object. The prefixes provided is joined together and prepended to the key before insertion.
type LevelDB ¶
LevelDB provides local data storage and functionalities for various purpose. It implements DB interface
func (*LevelDB) DeleteByPrefix ¶
DeleteByPrefix deletes items with the matching prefix
func (*LevelDB) GetByPrefix ¶
GetByPrefix returns keys matching a prefix. Their key and value are returned
func (*LevelDB) GetFirstOrLast ¶
GetFirstOrLast returns one value matching a prefix. Set first to return the first value we find or false if the last.
func (*LevelDB) Iterate ¶
Iterate finds a set of objects and passes them to iterFunc for further processing. If iterFunc returns true, the iteration is discontinued. If first is set to true, iteration begins from the first item, or the last if set to false
type Transaction ¶
Transaction defines interface for working with a database transaction
func (*Transaction) DeleteByPrefix ¶
func (tx *Transaction) DeleteByPrefix(prefix []byte) error
DeleteByPrefix deletes items with the matching prefix
func (*Transaction) GetByPrefix ¶
func (tx *Transaction) GetByPrefix(prefix []byte) []*KVObject
GetByPrefix get objects by prefix
func (*Transaction) Iterate ¶
func (tx *Transaction) Iterate(prefix []byte, first bool, iterFunc func(kv *KVObject) bool)
Iterate finds a set of objects by prefix and passes them ro iterFunc for further processing. If iterFunc returns true, the iterator is immediately released. If first is set to true, it begins from the first item, otherwise, the last
func (*Transaction) Put ¶
func (tx *Transaction) Put(objs []*KVObject) error
Put adds a key and value
type Tx ¶
type Tx interface { // Put puts one or more objects Put([]*KVObject) error // GetByPrefix gets objects by prefix GetByPrefix([]byte) (result []*KVObject) // Iterate finds a set of objects by prefix and passes them to iterFunc // for further processing. If iterFunc returns true, the iterator is immediately released. // If first is set to true, it begins from the first item, otherwise, the last Iterate(prefix []byte, first bool, iterFunc func(kv *KVObject) bool) // DeleteByPrefix deletes one or many records by prefix DeleteByPrefix([]byte) error // Commit commits the transaction Commit() error // Rollback roles back the transaction Rollback() // Discard the transaction. Do not call // functions in the transaction after this. Discard() }
Tx represents a database transaction instance