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 ¶
- type BDB
- func (bdb *BDB) Close() error
- func (bdb *BDB) Decode(key []byte, value interface{}) error
- func (bdb *BDB) Delete(key []byte) error
- func (bdb *BDB) Encode(key []byte, value interface{}) error
- func (bdb *BDB) ForEach(fn func(k, v []byte) error) error
- func (bdb *BDB) Get(key []byte) (value []byte)
- func (bdb *BDB) GetE(key []byte) (value []byte, err error)
- func (bdb *BDB) GetKeys() (keys [][]byte)
- func (bdb *BDB) GetKeysE() (keys [][]byte, err error)
- func (bdb *BDB) Ping() error
- func (bdb *BDB) Put(key, value []byte) error
- func (bdb *BDB) PutV(value []byte) (key []byte, err error)
- func (bdb *BDB) Scan(prefix []byte, fn func(k, v []byte) error) error
- type DB
- func (db *DB) Close() error
- func (db *DB) CreateBucket(bucket []byte) error
- func (db *DB) Decode(bucket, key []byte, value interface{}) error
- func (db *DB) Delete(bucket, key []byte) error
- func (db *DB) DeleteBucket(bucket []byte) error
- func (db *DB) Encode(bucket, key []byte, value interface{}) error
- func (db *DB) ForEach(bucket []byte, fn func(k, v []byte) error) error
- func (db *DB) Get(bucket, key []byte) (value []byte)
- func (db *DB) GetBuckets() (buckets [][]byte)
- func (db *DB) GetBucketsE() (buckets [][]byte, err error)
- func (db *DB) GetE(bucket, key []byte) (value []byte, err error)
- func (db *DB) GetKeys(bucket []byte) (keys [][]byte)
- func (db *DB) GetKeysE(bucket []byte) (keys [][]byte, err error)
- func (db *DB) Ping() error
- func (db *DB) Put(bucket, key, value []byte) error
- func (db *DB) PutV(bucket, value []byte) (key []byte, err error)
- func (db *DB) Scan(bucket, prefix []byte, fn func(k, v []byte) error) error
- func (db *DB) WriteTo(w io.Writer) (n int64, err error)
- type ErrBucketNotFound
- type ErrKeyNotFound
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 ¶
OpenBucket performs the same process as Open however only one bucket is usable in subsequent calls to Put, Get etc
func (*BDB) Close ¶
Close releases all database resources and closes the file. This call will block while any open transactions complete.
func (*BDB) Decode ¶
Decode retrieves and decodes a value set by Encode into the provided pointer value.
func (*BDB) Delete ¶
Delete removes the specified key. This process is wrapped in a read/write transaction.
func (*BDB) Encode ¶
Encode encodes the provided value using "encoding/gob" then writes the resulting byte slice to the provided key
func (*BDB) Get ¶
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 ¶
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) Put ¶
Put sets the specified key in the bucket opened to the provided value. This process is wrapped in a read/write transaction.
type DB ¶
type DB struct {
// contains filtered or unexported fields
}
func Open ¶
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 ¶
Close releases all database resources and closes the file. This call will block while any open transactions complete.
func (*DB) CreateBucket ¶
DeleteBucket removes the specified bucket. This also deletes all keys contained in the bucket and any nested buckets.
func (*DB) Decode ¶
Decode retrieves and decodes a value set by Encode into the provided pointer value.
func (*DB) Delete ¶
Delete removes the specified key in the chosen bucket. This process is wrapped in a read/write transaction.
func (*DB) DeleteBucket ¶
DeleteBucket removes the specified bucket. This also deletes all keys contained in the bucket and any nested buckets.
func (*DB) Encode ¶
Encode encodes the provided value using "encoding/gob" then writes the resulting byte slice to the provided key
func (*DB) Get ¶
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) GetBucketsE ¶
func (*DB) GetE ¶
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) Put ¶
Put sets the specified key in the chosen bucket to the provided value. This process is wrapped in a read/write transaction.
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