boltdb

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2024 License: MIT Imports: 6 Imported by: 0

README

boltdb

Simple wrapper around BoltDB.

LICENSE

Like the original BoltDB code by Ben Johnson and active maintenance development by etcd.io, this wrapper also uses the MIT license.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidPath      = errors.New("invalid path")
	ErrBucketNotFound   = bbolt.ErrBucketNotFound
	ErrTxNotWritable    = bbolt.ErrTxNotWritable
	ErrDatabaseReadOnly = bbolt.ErrDatabaseReadOnly
)

Functions

func DecodeUint64 added in v1.1.0

func DecodeUint64(valueBytes []byte) uint64

DecodeUint64 decodes a little endian uint64 value

func EncodeUint64 added in v1.1.0

func EncodeUint64(value uint64) []byte

EncodeUint64 stores an uint64 into a byte array using little endian format

Types

type Bucket

type Bucket struct {
	// contains filtered or unexported fields
}

Bucket is an implementation of Bucket within a transaction in BoltDB

func (*Bucket) Bucket

func (bucket *Bucket) Bucket(path []byte) (*Bucket, error)

Bucket returns a bucket on the database (and creates if it does not exist)

func (*Bucket) DB

func (bucket *Bucket) DB() *DB

DB gets the database this bucket belongs to

func (*Bucket) Delete

func (bucket *Bucket) Delete(key []byte) error

Delete deletes a specific key. No error is returned if key is not found

func (*Bucket) DeleteBucket

func (bucket *Bucket) DeleteBucket(path []byte) error

DeleteBucket removes an existing child bucket on the database NOTE: Inner sub-keys and buckets will be also deleted

func (*Bucket) DeleteWithPrefix

func (bucket *Bucket) DeleteWithPrefix(keyPrefix []byte) error

DeleteWithPrefix deletes a set of keys

func (*Bucket) ForEach

func (bucket *Bucket) ForEach(cb ForEachCallback) error

ForEach calls a callback for all the keys within the bucket

func (*Bucket) ForEachWithKeyPrefix

func (bucket *Bucket) ForEachWithKeyPrefix(keyPrefix []byte, cb ForEachCallback) error

ForEachWithKeyPrefix calls a callback for all the keys starting with the provided prefix within the bucket

func (*Bucket) Get

func (bucket *Bucket) Get(key []byte) []byte

Get returns the value of a key in a bucket or nil if not found

func (*Bucket) Name

func (bucket *Bucket) Name() []byte

Name returns the bucket name

func (*Bucket) NextSequence

func (bucket *Bucket) NextSequence() (uint64, error)

NextSequence returns an autoincrement integer for the bucket

func (*Bucket) Put

func (bucket *Bucket) Put(key []byte, value []byte) error

Put stores a key/value pair in the bucket

func (*Bucket) Stats

func (bucket *Bucket) Stats() BucketStats

func (*Bucket) TX

func (bucket *Bucket) TX() *TX

TX gets the transaction this bucket belongs to

type BucketStats

type BucketStats = bbolt.BucketStats

type DB

type DB struct {
	// contains filtered or unexported fields
}

DB represents a database connection to BoltDB

func New

func New(filename string) (*DB, error)

New returns a new database wrapper. If the database does not exist, it will be created.

func NewWithOptions added in v1.1.0

func NewWithOptions(filename string, opts Options) (*DB, error)

NewWithOptions returns a new database wrapper using the provided options.

func (*DB) Close

func (db *DB) Close()

Close closes the database connection

func (*DB) Delete added in v1.1.0

func (db *DB) Delete(bucket []byte, key []byte) error

Delete deletes a specific key in the specified bucket. No error is returned if key is not found

func (*DB) Get added in v1.1.0

func (db *DB) Get(bucket []byte, key []byte) ([]byte, error)

Get returns the value of a key in the specified bucket or nil if not found

func (*DB) Put added in v1.1.0

func (db *DB) Put(bucket []byte, key []byte, value []byte) error

Put stores a key/value pair in the specified bucket

func (*DB) WithTx

func (db *DB) WithTx(cb WithTxCallback, readOnly bool) error

WithTx initiates a transaction and calls a callback

type ForEachCallback

type ForEachCallback func(bucket *Bucket, key []byte, value []byte) (stop bool, err error)

ForEachCallback is a callback that is called for every key found in the given request NOTE: If value == nil, then they key points to a child bucket

type Options added in v1.1.0

type Options struct {
	ReadOnly    bool
	DirFileMode os.FileMode
	DbFileMode  os.FileMode
}

Options specified a set of options when creating/opening the database

type TX

type TX struct {
	// contains filtered or unexported fields
}

TX represents a read-write or read-only transaction in BoltDB

func (*TX) Bucket

func (tx *TX) Bucket(path []byte) (*Bucket, error)

Bucket returns a bucket on the database (and creates if it does not exist)

func (*TX) DB

func (tx *TX) DB() *DB

DB gets the database this transaction belongs to

func (*TX) DeleteBucket

func (tx *TX) DeleteBucket(path []byte) error

DeleteBucket removes an existing child bucket on the database NOTE: Inner sub-keys and buckets will be also deleted

func (*TX) ReadOnly

func (tx *TX) ReadOnly() bool

ReadOnly returns if the transaction is read-write or read-only

type WithTxCallback

type WithTxCallback func(tx *TX) error

WithTxCallback is a callback to be called after the transaction is initiated

Jump to

Keyboard shortcuts

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