Documentation ¶
Overview ¶
Package bboltx contains utilities for working with BoltDB databases.
Index ¶
- func Bucket(p BucketParent, path ...[]byte) *bbolt.Bucket
- func CreateBucketIfNotExists(p BucketParent, path ...[]byte) *bbolt.Bucket
- func DeletePath(p BucketParent, path ...[]byte)
- func GetPath(p BucketParent, path ...[]byte) []byte
- func Must(err error)
- func Open(ctx context.Context, path string, mode os.FileMode, opts *bbolt.Options) (*bbolt.DB, error)
- func PutPath(p BucketParent, v []byte, path ...[]byte)
- func Recover(err *error)
- func TryBucket(p BucketParent, path ...[]byte) (b *bbolt.Bucket, ok bool)
- func Update(db *bbolt.DB, fn func(tx *bbolt.Tx))
- func View(db *bbolt.DB, fn func(tx *bbolt.Tx))
- type BucketParent
- type PanicSentinel
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Bucket ¶
func Bucket(p BucketParent, path ...[]byte) *bbolt.Bucket
Bucket gets nested buckets with names given by the elements of path.
It panics if any of the nested buckets does not exist.
func CreateBucketIfNotExists ¶
func CreateBucketIfNotExists(p BucketParent, path ...[]byte) *bbolt.Bucket
CreateBucketIfNotExists creates nested buckets with names given by the elements of path.
func DeletePath ¶
func DeletePath(p BucketParent, path ...[]byte)
DeletePath removes a value at a given path, recursively deleting any intermediate buckets that become empty.
The last element in the path is the value's key. All preceeding elements are bucket names. Therefore, the path must contain at least 2 elements (1 bucket, and the key).
func GetPath ¶
func GetPath(p BucketParent, path ...[]byte) []byte
GetPath loads a value at a given path. It returns nil if any of the intermediate buckets do not exist.
The last element in the path is the value's key. All preceeding elements are bucket names. Therefore, the path must contain at least 2 elements (1 bucket, and the key).
func Open ¶
func Open( ctx context.Context, path string, mode os.FileMode, opts *bbolt.Options, ) (*bbolt.DB, error)
Open creates and opens a database at the given path.
If mode is zero, 0600 is used.
If the deadline from ctx is sooner than opts.Timeout, the context deadline is used instead.
func PutPath ¶
func PutPath(p BucketParent, v []byte, path ...[]byte)
PutPath stores a value at a given path, creating intermediate buckets as necessary.
The last element in the path is the value's key. All preceeding elements are bucket names. Therefore, the path must contain at least 2 elements (1 bucket, and the key).
func Recover ¶
func Recover(err *error)
Recover recovers from a panic caused by one of the MustXXX() functions.
It is intended to be used in a defer statement. The error that caused the panic is assigned to *err.
Types ¶
type BucketParent ¶
type BucketParent interface { CreateBucketIfNotExists([]byte) (*bbolt.Bucket, error) Bucket([]byte) *bbolt.Bucket DeleteBucket([]byte) error }
BucketParent is an interface for things that contain buckets.
type PanicSentinel ¶
type PanicSentinel struct { // Cause is the error that caused the panic. Cause error }
PanicSentinel is a wrapper value used to identify panic's that are caused by one of the MustXXX() functions.