bboltx

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 26, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package bboltx contains utilities for working with BoltDB databases.

Index

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 Must

func Must(err error)

Must panics if err is non-nil.

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.

func TryBucket

func TryBucket(p BucketParent, path ...[]byte) (b *bbolt.Bucket, ok bool)

TryBucket gets nested buckets with names given by the elements of path.

func Update

func Update(db *bbolt.DB, fn func(tx *bbolt.Tx))

Update runs a write transaction.

func View

func View(db *bbolt.DB, fn func(tx *bbolt.Tx))

View runs a read-only transaction.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL