Documentation
¶
Index ¶
- Variables
- func MarshalBinary(v any) ([]byte, error)
- func UnmarshalBinary(b []byte) (any, error)
- type KVStore
- func (db *KVStore) Close() error
- func (db *KVStore) Delete(key string) error
- func (db *KVStore) DeleteMany(keys []string) error
- func (db *KVStore) Get(key string) (any, error)
- func (db *KVStore) GetAll(limit int) (map[string]any, error)
- func (db *KVStore) Info(key string) (KeyInfo, bool)
- func (db *KVStore) Open(path string) error
- func (db *KVStore) Revert(key string) error
- func (db *KVStore) Set(key string, value any) error
- func (db *KVStore) SetDefault(key string, value any, info KeyInfo) error
- func (db *KVStore) SetMany(pairs map[string]any) error
- type KeyInfo
- type KeyValueStore
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 ¶
func MarshalBinary ¶
MarshalBinary uses gob encoding to marshal a value to a byte slice. To encode structs, use gob.Register(yourstruct{}) to register them.
func UnmarshalBinary ¶
UnmarshalBinary assumes that a gob encoded byte slice is given and nmarshals it into a variable of the empty interface type, returns an error if the data is malformed.
Types ¶
type KVStore ¶
type KVStore struct {
// contains filtered or unexported fields
}
KVStore implements KvStore interface with an sqlite database backend.
func (*KVStore) DeleteMany ¶ added in v1.1.0
DeleteMany removes all given keys in one transaction.
func (*KVStore) 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 (*KVStore) GetAll ¶ added in v1.1.0
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 (*KVStore) 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 (*KVStore) 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 (*KVStore) Revert ¶
Revert reverts the value for the given key to its default. If no default has been set, NoDefaultErr is returned.
func (*KVStore) Set ¶
Set sets the value for the given key, overwriting an existing value for the key if there is one.
func (*KVStore) SetDefault ¶
SetDefault sets a default value for the given key, as well as info and category.
type KeyValueStore ¶
type KeyValueStore interface {
Open(path string) error // open the database at directory path
Close() error // close the database
Set(key string, value any) error // set the key to the given value, which must be gob serializable
Get(key string) (any, error) // get the value for key, NotFoundErr if there is no key
SetMany(map[string]any) error // set all key-value pairs in the map in one transaction
GetAll(limit int) (map[string]any, 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 any,
info KeyInfo) error
}
KeyValueStore is the interface for a key value database.
