Documentation ¶
Index ¶
- Variables
- func IsBucketError(err error) bool
- func StringFunc(s *string) func(b []byte) error
- type BucketError
- type KV
- type Marshaler
- type Node
- func (n Node) Delete(k string) error
- func (n Node) Drop() error
- func (n Node) DropExceptLast(last int) error
- func (n Node) Each(fn func(k string, b []byte, len int) error) error
- func (n Node) EachReverse(fn func(k string, b []byte, len int) error) error
- func (n Node) Exists(k string) (exists bool)
- func (n Node) FromPath(path NodePath) Node
- func (n Node) Get(k string, f func([]byte) error) error
- func (n Node) GetAny(k string, v interface{}) error
- func (n Node) Length(prefix string) (int, error)
- func (n Node) Node(names ...string) Node
- func (n Node) Set(k string, v []byte) error
- func (n Node) SetAny(k string, v interface{}) error
- func (n Node) SetIfNone(k string, v []byte) error
- func (n Node) TxUpdate(f func(n Node) error) error
- func (n Node) TxView(f func(n Node) error) error
- func (n Node) Unmarshal(b []byte, v interface{}) error
- func (n Node) UnmarshalFunc(v interface{}) func([]byte) error
- type NodePath
Constants ¶
This section is empty.
Variables ¶
var EachBreak = errors.New("each break (not an error)")
EachBreak is an error that Each callbacks could return to stop the loop and return nil.
var ErrKeyNotFound = errors.New("key not found in database")
ErrKeyNotFound is returned if either a key or a bucket is not found.
Functions ¶
func IsBucketError ¶
IsBucketError returns true if the given error is a bucket error.
func StringFunc ¶
StringFunc returns a new function for setting a string with Get
Types ¶
type BucketError ¶
type BucketError struct {
// contains filtered or unexported fields
}
BucketError wraps an error for bucket traversal errors.
type KV ¶
type KV struct { Marshaler // contains filtered or unexported fields }
func (*KV) DropPrefix ¶
DropPrefix drops the whole given prefix.
func (*KV) NodeFromPath ¶
NodeFromPath creates a new Node from path.
type Marshaler ¶
type Marshaler interface { Marshal(interface{}) ([]byte, error) Unmarshal([]byte, interface{}) error }
var JSONMarshaler Marshaler = jsonMarshaler{}
JSONMarshaler is the default key-value marshaler.
type Node ¶
type Node struct {
// contains filtered or unexported fields
}
func (Node) DropExceptLast ¶
DropExceptLast drops the entire node except for the last few values. This method heavily relies on keyed values being sorted properly, and that the stored values are NOT nested.
func (Node) Each ¶
Each iterates over the bucket all possible keys with the prefix, or no prefix. It takes in a pointer.
Caveats ¶
Since the pointer is reused, the user will need to manually copy it if they want to store the reference to that matched struct. Key includes the prefix.
Example ¶
For iterating, as mentioned above, the user will need to manually copy the pointer by dereferencing and re-referencing it.
var obj Struct var objs []Struct n.Each(&obj, "", func(k string) error { if obj.Thing == "what I want" { objs = append(objs, obj) return EachBreak } return nil })
func (Node) EachReverse ¶
EachReverse is like Each, except the iteration is done in reverse.
func (Node) FromPath ¶
FromPath creates a new node with the given full path. The path will completely override the old path.
func (Node) Length ¶
Length queries the number of keys within the node, similarly to running AllKeys and taking the length of what was returned.
func (Node) Node ¶
Node creates a child node with the given names appended to its path. If the node has an ongoing transaction, then it is inherited over.
func (Node) SetIfNone ¶
SetIfNone sets the key into the database only if the key does not exist. This method is useful primarily for filling up the cache with data fetched from the API while data from /sync should be prioritized.
func (Node) TxUpdate ¶
TxUpdate creates a new Node with an active transaction and calls f. If this method is called in a Node that already has a transaction, then that transaction is reused.
func (Node) TxView ¶
TxUpdate creates a new Node with an active read-only transaction and calls f. If this method is called in a Node that already has a transaction, then that transaction is reused.
func (Node) UnmarshalFunc ¶
UnmarshalFunc creates a new function for unmarshaling with Get.
type NodePath ¶
type NodePath [][]byte
NodePath contains the full path to a node. It can be used as a lighter way to store nodes.
func (NodePath) Bucket ¶
NodePath traverses the given transaction and returns the bucket. If any of the buckets don't exist, then a new one is created, unless the transaction is read-only.
If NodePath is empty, then a Bucket with a nil byte is returned.
func (NodePath) BucketExists ¶
BucketExists traverses and returns true if the bucket exists.