Documentation
¶
Index ¶
- Variables
- type BinaryKeyValueStore
- type KVB
- func (db *KVB) Close() error
- func (db *KVB) Delete(key string) error
- func (db *KVB) DeleteMany(keys []string) error
- func (db *KVB) Get(key string) ([]byte, error)
- func (db *KVB) GetAll(limit int) (map[string][]byte, error)
- func (db *KVB) HasKey(key string) bool
- func (db *KVB) Info(key string) (KeyInfo, bool)
- func (db *KVB) Open(path string) error
- func (db *KVB) Revert(key string) error
- func (db *KVB) Set(key string, value []byte) error
- func (db *KVB) SetDefault(key string, value []byte, info KeyInfo) error
- func (db *KVB) SetMany(pairs map[string][]byte) error
- type KeyInfo
Constants ¶
This section is empty.
Variables ¶
var AlreadyOpenErr = errors.New(`database already open`)
var NoDefaultErr = errors.New(`no default value set for given key`)
var NotFoundErr = errors.New(`key not found`)
var NotOpenErr = errors.New(`key value store is closed`)
Functions ¶
This section is empty.
Types ¶
type BinaryKeyValueStore ¶
type BinaryKeyValueStore interface {
Open(path string) error // open the database at directory path
Close() error // close the database
Set(key string, value []byte) error // set the key to the given value, which must be gob serializable
Get(key string) ([]byte, error) // get the value for key, NotFoundErr if there is no key
SetMany(map[string][]byte) error // set all key-value pairs in the map in one transaction
GetAll(limit int) (map[string][]byte, error) // get all key-value pairs as a map
Revert(key string) error // revert key to its default
Info(key string) (KeyInfo, bool) // returns key information for a key if it is present
Delete(key string) error // remove the key and value for the key
DeleteMany(keys []string) error // remove all the given keys in one transaction
SetDefault(key string,
value []byte,
info KeyInfo) error
}
BinaryKeyValueStore is the interface for a key value database.
type KVB ¶
type KVB struct {
// contains filtered or unexported fields
}
KVB implements BinaryKeyValueStore interface with an sqlite database backend.
func (*KVB) DeleteMany ¶
DeleteMany removes all given keys in one transaction.
func (*KVB) Get ¶
Get gets the value for the given key, the default if no value for the key is stored but a default is present, and NotFoundErr if neither of them is present.
func (*KVB) GetAll ¶
GetAll returns all key-value pairs as a map. If limit is 0 or negative, all key value pairs are returned. Although this is usually not advisable, this method may be used in combination with SetMany to save and load maps, i.e., use the key value store merely for persistence and keep the data in memory.
func (*KVB) HasKey ¶
HasKey returns true if the key is set. Notice that the value and default for the key may still be nil, as nil can also be set as a value. If the database is not open, false is returned.
func (*KVB) Info ¶
Info attempts to obtain information about the given key, returns false if none can be found. This method will also return false if an error occurs.
func (*KVB) Open ¶
Open a database at the path specified when the database was created, which holds all database files. If directories to path/name do not exist, they are created recursively with Unix permissions 0755.
func (*KVB) Revert ¶
Revert reverts the value for the given key to its default. If no default has been set, NoDefaultErr is returned.
func (*KVB) Set ¶
Set sets the value for the given key, overwriting an existing value for the key if there is one.
func (*KVB) SetDefault ¶
SetDefault sets a default value for the given key, as well as info and category.
