Documentation ¶
Overview ¶
Package bh provides some helper classes for convenience of using github.com/boltdb/bolt package. All wrapper classes will use their friend wrapper classes whenever possible. All returned errors are with call stackes using github.com/golangplus/errors.
Index ¶
- Variables
- type Bucket
- func (b Bucket) CreateBucketIfNotExists(folders [][]byte) (Bucket, error)
- func (b Bucket) Cursor() Cursor
- func (b Bucket) Delete(k [][]byte) error
- func (b Bucket) ForEach(folders [][]byte, f func(k, v bytesp.Slice) error) error
- func (b Bucket) ForEachGob(folders [][]byte, f func(bytesp.Slice, interface{}) error) error
- func (b Bucket) GobValue(k [][]byte, f func(interface{}) error) error
- func (b Bucket) NextSequence() (uint64, error)
- func (b Bucket) OpenBucket(folders [][]byte, f func(Bucket) error) error
- func (b Bucket) Put(k [][]byte, v []byte) error
- func (b Bucket) PutGob(k [][]byte, v interface{}) error
- func (b Bucket) Tx() Tx
- func (b Bucket) Value(k [][]byte, f func(bytesp.Slice) error) error
- type Cursor
- type DB
- type RefCountBox
- type Tx
- func (tx Tx) Bucket(folders [][]byte, f func(Bucket) error) error
- func (tx Tx) Commit() error
- func (tx Tx) CopyFile(path string, mode os.FileMode) error
- func (tx Tx) CreateBucketIfNotExists(folders [][]byte) (Bucket, error)
- func (tx Tx) Cursor(folders [][]byte, f func(Cursor) error) error
- func (tx Tx) DB() DB
- func (tx Tx) Delete(k [][]byte) error
- func (tx Tx) ForEach(folders [][]byte, f func(Bucket, bytesp.Slice, bytesp.Slice) error) error
- func (tx Tx) ForEachGob(folders [][]byte, f func(Bucket, bytesp.Slice, interface{}) error) error
- func (tx Tx) GobValue(k [][]byte, f func(interface{}) error) error
- func (tx Tx) Put(k [][]byte, v []byte) error
- func (tx Tx) PutGob(k [][]byte, v interface{}) error
- func (tx Tx) Rollback() error
- func (tx Tx) Update(k [][]byte, f func(bytesp.Slice) (bytesp.Slice, error)) error
- func (tx Tx) Value(k [][]byte, f func(v bytesp.Slice) error) error
- func (tx *Tx) WriteTo(w io.Writer) (int64, error)
Constants ¶
This section is empty.
Variables ¶
var ErrBoxDataPathNotSpecified = errors.New("DataPath func of RefCountBox was not specified")
Functions ¶
This section is empty.
Types ¶
type Bucket ¶
A wrapper to *bolt.Bucket.
func (Bucket) CreateBucketIfNotExists ¶
CreateBucketIfNotExists creates a new bucket if it doesn't already exist and returns a reference to it. Returns an error if the bucket name is blank, or if the bucket name is too long. The bucket instance is only valid for the lifetime of the transaction.
func (Bucket) Cursor ¶
Cursor creates a cursor associated with the bucket. The cursor is only valid as long as the transaction is open. Do not use a cursor after the transaction is closed.
func (Bucket) Delete ¶
Delete removes a key from the bucket. If the key does not exist then nothing is done and a nil error is returned. Returns an error if the bucket was created from a read-only transaction.
func (Bucket) ForEach ¶
ForEach executes a function for each key/value pair in a bucket. If the provided function returns an error then the iteration is stopped and the error is returned to the caller. The provided function must not modify the bucket; this will result in undefined behavior.
func (Bucket) ForEachGob ¶
ForEachGob iterates each values of a folder, returns a Gob decoded object.
func (Bucket) NextSequence ¶
NextSequence returns an autoincrementing integer for the bucket.
func (Bucket) OpenBucket ¶
Bucket retrieves a nested bucket by name. Returns nil if the bucket does not exist. The bucket instance is only valid for the lifetime of the transaction. folders can be empty, in which case the b itself is sent to f.
func (Bucket) Put ¶
Put sets the value for a key in the bucket. If the key exist then its previous value will be overwritten. Supplied value must remain valid for the life of the transaction. Returns an error if the bucket was created from a read-only transaction, if the key is blank, if the key is too large, or if the value is too large.
type Cursor ¶
A wrapper to *bolt.Cursor.
type DB ¶
A wrapper to *bolt.DB.
func Open ¶
Open creates and opens a database at the given path. If the file does not exist then it will be created automatically. Passing in nil options will cause Bolt to open the database with the default options.
type RefCountBox ¶
type RefCountBox struct { sync.Mutex // The path to the bolt database file. DataPath func() string // Used to open a bolt DB. If not specified, bh.Open with 0644 mode and // default options will be used. OpenFunc func(path string) (DB, error) // contains filtered or unexported fields }
RefCountBox is a structure maintaining a reference-count guarded instance of DB.
func (*RefCountBox) Alloc ¶
func (b *RefCountBox) Alloc() (DB, error)
Alloc opens a DB if not openned yet. It adds a reference if already openned.
func (*RefCountBox) Free ¶
func (b *RefCountBox) Free()
Free decreases the reference count. It close the DB if the count reaches zero.
type Tx ¶
A wrapper to *bolt.Tx.
func (Tx) Commit ¶
Commit writes all changes to disk and updates the meta page. Returns an error if a disk write error occurs, or if Commit is called on a read-only transaction.
func (Tx) CopyFile ¶
CopyFile copies the entire database to file at the given path. A reader transaction is maintained during the copy so it is safe to continue using the database while a copy is in progress.
func (Tx) CreateBucketIfNotExists ¶
CreateBucketIfNotExists creates a new bucket if it doesn't already exist. Returns an error if the bucket name is blank, or if the bucket name is too long. The bucket instance is only valid for the lifetime of the transaction.
func (Tx) ForEachGob ¶
ForEach iterates over all key values of a folder, decode non-nil values using gob.
func (Tx) Put ¶
Put sets the value for a key in the transaction. If the key exist then its previous value will be overwritten. Supplied value must remain valid for the life of the transaction. Returns an error if the bucket was created from a read-only transaction, if the key is blank, if the key is too large, or if the value is too large.
func (Tx) Rollback ¶
Rollback closes the transaction and ignores all previous updates. Read-only transactions must be rolled back and not committed.
func (Tx) Update ¶
Updates fetches the current value and updates to a new value. If a nil value is returned by f, the item is deleted.