Documentation ¶
Overview ¶
Package simplebolt provides a simple way to use the Bolt database. The API design is similar to xyproto/simpleredis, and the database backends are interchangeable, by using the xyproto/pinterface package.
Index ¶
- Constants
- Variables
- type BoltCreator
- type Database
- type HashMap
- func (h *HashMap) All() ([]string, error)
- func (h *HashMap) Clear() error
- func (h *HashMap) Del(elementid string) error
- func (h *HashMap) DelKey(elementid, key string) error
- func (h *HashMap) Exists(elementid string) (bool, error)
- func (h *HashMap) Get(elementid, key string) (string, error)
- func (h *HashMap) Has(elementid, key string) (bool, error)
- func (h *HashMap) Keys(owner string) ([]string, error)
- func (h *HashMap) Remove() error
- func (h *HashMap) Set(elementid, key, value string) error
- type KeyValue
- type List
- type Set
- type StoredData
Constants ¶
const (
// Version number. Stable API within major version numbers.
Version = 5.1
)
Variables ¶
var ( // ErrBucketNotFound may be returned if a no Bolt bucket was found ErrBucketNotFound = errors.New("Bucket not found") // ErrKeyNotFound will be returned if the key was not found in a HashMap or KeyValue struct ErrKeyNotFound = errors.New("Key not found") // ErrDoesNotExist will be returned if an element was not found. Used in List, Set, HashMap and KeyValue. ErrDoesNotExist = errors.New("Does not exist") // ErrExistsInSet is only returned if an element is added to a Set, but it already exists ErrExistsInSet = errors.New("Element already exists in set") // ErrInvalidID is only returned if adding an element to a HashMap that contains a colon (:) ErrInvalidID = errors.New("Element ID can not contain \":\"") )
Functions ¶
This section is empty.
Types ¶
type BoltCreator ¶
type BoltCreator struct {
// contains filtered or unexported fields
}
BoltCreator is used for implementing pinterface.ICreator. It contains a database and provides functions for creating data structures within that database.
func NewCreator ¶
func NewCreator(db *Database) *BoltCreator
NewCreator can create a new BoltCreator struct
func (*BoltCreator) NewHashMap ¶
func (b *BoltCreator) NewHashMap(id string) (pinterface.IHashMap, error)
NewHashMap can create a new HashMap with the given ID. The HashMap elements have a name and then a key+value. For example a username for the name, then "password" as the key and a password hash as the value.
func (*BoltCreator) NewKeyValue ¶
func (b *BoltCreator) NewKeyValue(id string) (pinterface.IKeyValue, error)
NewKeyValue can create a new KeyValue with the given ID. The KeyValue elements have a key with a corresponding value.
func (*BoltCreator) NewList ¶
func (b *BoltCreator) NewList(id string) (pinterface.IList, error)
NewList can create a new List with the given ID
func (*BoltCreator) NewSet ¶
func (b *BoltCreator) NewSet(id string) (pinterface.ISet, error)
NewSet can create a new Set with the given ID
type Database ¶
Database represents Bolt database
func New ¶
New creates a new Bolt database struct, using the given file or creating a new file, as needed
type HashMap ¶
type HashMap boltBucket
HashMap is a Bolt bucket, with methods for acting like a hash map (with an ID and then key=>value)
func NewHashMap ¶
NewHashMap loads or creates a new HashMap struct, with the given ID
func (*HashMap) DelKey ¶
DelKey will remove a key for an entry in a hashmap (for instance the email field for a user)
func (*HashMap) Get ¶
Get a value from a hashmap given the element id (for instance a user id) and the key (for instance "password")
type KeyValue ¶
type KeyValue boltBucket
KeyValue is a Bolt bucket, with methods for acting like a key=>value store
func NewKeyValue ¶
NewKeyValue loads or creates a new KeyValue struct, with the given ID
type List ¶
type List boltBucket
List is a Bolt bucket, with methods for acting like a list
type Set ¶
type Set boltBucket
Set is a Bolt bucket, with methods for acting like a set, only allowing unique keys
type StoredData ¶
type StoredData interface { // Value returns the current value of the // element at which the item refers to. Value() []byte // Update resets the value of the element at // which the item refers to with newData. // // Returns "Empty data" error if newData is nil. // // It may also return an error in case of bbolt Update or protocol buffer // serialization/deserialization fail. In both cases, the data isn't updated. Update(newData []byte) error // Remove deletes from Bolt the element at which the item data refers to. // // It may return an error in case of bbolt Update or protocol buffer // serialization/deserialization fail. In both cases, the data isn't removed. Remove() error }
StoredData is the set of methods that provides access to the element's underlying data in every data structure.