ubolt

package module
v1.5.5 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2021 License: MIT Imports: 7 Imported by: 2

README

ubolt

Go Report Card Godoc coverage report tag LICENSE

ubolt is a convenience wrapper around various github.com/etcd-io/bbolt/bbolt calls.

Documentation

Overview

Package ubolt wraps various calls from "go.etcd.io/bbolt" to make basic use simpler and quicker.

Various calls such as Get, Put etc are automatically wrapped in transactions to ensure consistency.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BDB

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

func OpenBucket

func OpenBucket(path string, bucket []byte) (*BDB, error)

OpenBucket performs the same process as Open however only one bucket is usable in subsequent calls to Put, Get etc

func (*BDB) Close

func (bdb *BDB) Close() error

Close releases all database resources and closes the file. This call will block while any open transactions complete.

func (*BDB) Decode

func (bdb *BDB) Decode(key []byte, value interface{}) error

Decode retrieves and decodes a value set by Encode into the provided pointer value.

func (*BDB) Delete

func (bdb *BDB) Delete(key []byte) error

Delete removes the specified key. This process is wrapped in a read/write transaction.

func (*BDB) Encode

func (bdb *BDB) Encode(key []byte, value interface{}) error

Encode encodes the provided value using "encoding/gob" then writes the resulting byte slice to the provided key

func (*BDB) ForEach

func (bdb *BDB) ForEach(fn func(k, v []byte) error) error

func (*BDB) Get

func (bdb *BDB) Get(key []byte) (value []byte)

Get retrieves the specified key and returns the value. The value returned may be nil which indicates the key was not found.

func (*BDB) GetE

func (bdb *BDB) GetE(key []byte) (value []byte, err error)

GetE retrieves the specified key and returns the value and an error. The returned error is non-nil if a failure occurred, which includes if the key was not found.

func (*BDB) GetKeys

func (bdb *BDB) GetKeys() (keys [][]byte)

func (*BDB) GetKeysE

func (bdb *BDB) GetKeysE() (keys [][]byte, err error)

func (*BDB) Ping

func (bdb *BDB) Ping() error

Ping tests the database by attempting to retrieve a list of buckets.

func (*BDB) Put

func (bdb *BDB) Put(key, value []byte) error

Put sets the specified key in the bucket opened to the provided value. This process is wrapped in a read/write transaction.

func (*BDB) PutV

func (bdb *BDB) PutV(value []byte) (key []byte, err error)

PutV sets a key based on an auto-incrementing value for the key.

func (*BDB) Scan

func (bdb *BDB) Scan(prefix []byte, fn func(k, v []byte) error) error

type DB

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

func Open

func Open(path string) (*DB, error)

Open creates and opens a database at the given path. If the file does not exist it will be created automatically. The database is opened with a file-mode of 0600 and a timeout of 5 seconds

func (*DB) Close

func (db *DB) Close() error

Close releases all database resources and closes the file. This call will block while any open transactions complete.

func (*DB) CreateBucket

func (db *DB) CreateBucket(bucket []byte) error

DeleteBucket removes the specified bucket. This also deletes all keys contained in the bucket and any nested buckets.

func (*DB) Decode

func (db *DB) Decode(bucket, key []byte, value interface{}) error

Decode retrieves and decodes a value set by Encode into the provided pointer value.

func (*DB) Delete

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

Delete removes the specified key in the chosen bucket. This process is wrapped in a read/write transaction.

func (*DB) DeleteBucket

func (db *DB) DeleteBucket(bucket []byte) error

DeleteBucket removes the specified bucket. This also deletes all keys contained in the bucket and any nested buckets.

func (*DB) Encode

func (db *DB) Encode(bucket, key []byte, value interface{}) error

Encode encodes the provided value using "encoding/gob" then writes the resulting byte slice to the provided key

func (*DB) ForEach

func (db *DB) ForEach(bucket []byte, fn func(k, v []byte) error) error

func (*DB) Get

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

Get retrieves the specified key from the chosen bucket and returns the value. The value returned may be nil which indicates the bucket or key was not found.

func (*DB) GetBuckets

func (db *DB) GetBuckets() (buckets [][]byte)

func (*DB) GetBucketsE

func (db *DB) GetBucketsE() (buckets [][]byte, err error)

func (*DB) GetE

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

GetE retrieves the specified key from the chosen bucket and returns the value and an error. The returned error is non-nil if a failure occurred, which includes if the bucket or key was not found.

func (*DB) GetKeys

func (db *DB) GetKeys(bucket []byte) (keys [][]byte)

func (*DB) GetKeysE

func (db *DB) GetKeysE(bucket []byte) (keys [][]byte, err error)

func (*DB) Ping

func (db *DB) Ping() error

Ping tests the database by attempting to retrieve a list of buckets.

func (*DB) Put

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

Put sets the specified key in the chosen bucket to the provided value. This process is wrapped in a read/write transaction.

func (*DB) PutV

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

PutV sets a key based on an auto-incrementing value for the key.

func (*DB) Scan

func (db *DB) Scan(bucket, prefix []byte, fn func(k, v []byte) error) error

func (*DB) WriteTo

func (db *DB) WriteTo(w io.Writer) (n int64, err error)

type ErrBucketNotFound

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

ErrBucketNotFound is returned when the bucket requested was not found.

func (ErrBucketNotFound) Error

func (bnf ErrBucketNotFound) Error() string

Error returns the formatted configuration error.

func (ErrBucketNotFound) Is

func (bnf ErrBucketNotFound) Is(target error) bool

Is allows testing using errors.Is

type ErrKeyNotFound

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

ErrKeyNotFound is returned when the key requested was not found

func (ErrKeyNotFound) Error

func (knf ErrKeyNotFound) Error() string

Error returns the formatted configuration error.

func (ErrKeyNotFound) Is

func (knf ErrKeyNotFound) Is(target error) bool

Is allows testing using errors.Is

Jump to

Keyboard shortcuts

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