storage

package
v0.0.0-...-e955a5d Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2020 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BucketRef

type BucketRef struct {
	*DatabaseRef
	Name []byte
}

BucketRef represents a reference by name to a bucketRef in the Bolt DB. Bolt defaultBuckets group together key/value pairs and can also contain other buckets to allow a hierarchical data structure

func (BucketRef) ForEach

func (b BucketRef) ForEach(f func(key KeyRef, value []byte) error) (result logging.Result)

ForEach cycles through each key-value pair in the bucket Note that this is read only

func (BucketRef) GetAs

func (b BucketRef) GetAs(data interface{}) logging.Result

GetAs unmarshals the data stored in the BucketRef into the supplied interface

func (BucketRef) RemoveAll

func (b BucketRef) RemoveAll() (result logging.Result)

RemoveAll removes all key-value pairs from a bucket

func (BucketRef) Size

func (b BucketRef) Size() (int, logging.Result)

Size returns the number of key-value pairs in the bucket

type DatabaseRef

type DatabaseRef struct {
	Name string
	Path string
	// contains filtered or unexported fields
}

DatabaseRef contains a database id

func NewDatabaseRef

func NewDatabaseRef(locationFileName, defaultName string) DatabaseRef

NewDatabaseRef checks if a file containing the db location is present in the executable directory. If the file is present and the path it contains is valid then a new DatabaseRef is created based on that path. If the file is not present or the path is not valid then then the executable directory and default name will be used.

func (*DatabaseRef) AddDefaultBucket

func (dbRef *DatabaseRef) AddDefaultBucket(name []byte) BucketRef

AddDefaultBucket adds to the list of buckets automatically created at the root of the database at initialisation

func (*DatabaseRef) Dump

func (dbRef *DatabaseRef) Dump() (object *frjson.Object, result logging.Result)

Dump will read all of the database's decrypted contents into a JSON object

func (*DatabaseRef) Initialise

func (dbRef *DatabaseRef) Initialise(object *frjson.Object) logging.Result

Initialise initialises the database and stores the object (if not nil) in the root of the database

func (*DatabaseRef) Initialised

func (dbRef *DatabaseRef) Initialised() bool

Initialised returns true if the database has been initialised; otherwise false is returned

func (*DatabaseRef) Remove

func (dbRef *DatabaseRef) Remove() logging.Result

Remove completely removes the database

func (*DatabaseRef) SetPath

func (dbRef *DatabaseRef) SetPath(path string) logging.Result

SetPath sets the path and\or name used by the database

func (*DatabaseRef) Update

func (dbRef *DatabaseRef) Update(object *frjson.Object) logging.Result

Update stores the object in the root of the database Each JSON object will be represented by a db bucketRef with the object's value pairs as entries in the bucketRef. The defaultBuckets and entries will be created if they do not exist already. The JSON structure will be added to the root bucketRef, which can only contain other defaultBuckets and therefore the JSON structure should only contain objects in its root. Any value pairs will be ignored.

type KeyRef

type KeyRef struct {
	Name   []byte
	Bucket *BucketRef
}

KeyRef is a reference to a named key in a bucket

func (KeyRef) GetAs

func (key KeyRef) GetAs(value interface{}) (result logging.Result)

GetAs will read the entry at the given key. The entry will be read into value, which must be a pointer to the same type as the entry

func (KeyRef) Put

func (key KeyRef) Put(value interface{}) (result logging.Result)

Put will update/insert the entry at the given key

func (KeyRef) Remove

func (key KeyRef) Remove() (result logging.Result)

Remove removes the key reference

type MissingDBKeyError

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

MissingDBKeyError is an error used to report a missing key in a database

func (MissingDBKeyError) Error

func (e MissingDBKeyError) Error() string

Error satisfies the error interface

Jump to

Keyboard shortcuts

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