db

package
v0.5.1-rc7 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2022 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BoltDB

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

func (*BoltDB) Close

func (b *BoltDB) Close() error

Close the database

func (*BoltDB) Delete

func (b *BoltDB) Delete(bucket []byte, key []byte) error

Delete will remove a key/value pair from the bucket

func (*BoltDB) DeleteBucket

func (b *BoltDB) DeleteBucket(bucket []byte) error

DeleteBucket will delete all key/value pairs from a bucket

func (*BoltDB) Get

func (b *BoltDB) Get(bucket []byte, key []byte) (value []byte, err error)

Get will get an entry in the database given a bucket and key

func (*BoltDB) GetBucket

func (b *BoltDB) GetBucket(bucket []byte) (buck *Bucket, err error)

GetBucket will return the contents of a bucket

func (*BoltDB) InitDB

func (b *BoltDB) InitDB(filename string) (err error)

InitDB will open the database

func (*BoltDB) Put

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

Put will write data to a given bucket using the key

type Bucket

type Bucket struct {
	KeyValueList []KeyValue //KeyValueList contains the key/value data for the entry
	// contains filtered or unexported fields
}

Bucket is the structure to store the key/value data and a reference map to pull it.

func NewBucket

func NewBucket() *Bucket

NewBucket creates a new instance of the bucket and initializes the map

func (*Bucket) Delete

func (b *Bucket) Delete(key []byte) (err error)

Delete will remove the value given a key

func (*Bucket) Get

func (b *Bucket) Get(key []byte) (value []byte)

Get will retrieve the value given a key

func (*Bucket) Put

func (b *Bucket) Put(k []byte, v []byte)

Put will store the key / value in the bucket

type DB

type DB interface {
	Close() error                                            // Returns an error if the close fails
	InitDB(filepath string) error                            // Sets up the database, returns error if it fails
	Get(bucket []byte, key []byte) (value []byte, err error) // Get key from database, returns ErrNotFound if the key is not found
	Put(bucket []byte, key []byte, value []byte) error       // Put the value in the database, throws an error if fails
	GetBucket(bucket []byte) (*Bucket, error)                // GetBucket retrieves all the data contained within a bucket
	Delete(bucket []byte, key []byte) error                  // Delete will remove a key/value pair from the bucket
	DeleteBucket(bucket []byte) error                        // DeleteBucket will delete all key/value pairs from a bucket
}

DB defines the interface functions to access the database

type KeyValue

type KeyValue struct {
	Key   []byte
	Value []byte
}

KeyValue holds the key/value data for the entry

type MemoryDB

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

MemoryDB holds the main map of buckets for the in-memory database

func (*MemoryDB) Close

func (b *MemoryDB) Close() error

Close clears out the data and uninitializes the MemoryDB

func (*MemoryDB) Delete

func (b *MemoryDB) Delete(bucket []byte, key []byte) (err error)

Delete will remove a key/value pair from the bucket

func (*MemoryDB) DeleteBucket

func (b *MemoryDB) DeleteBucket(bucket []byte) error

DeleteBucket will delete all key/value pairs from a bucket

func (*MemoryDB) Get

func (b *MemoryDB) Get(bucket []byte, key []byte) (value []byte, err error)

Get will get an entry in the database given a bucket and key

func (*MemoryDB) GetBucket

func (b *MemoryDB) GetBucket(bucket []byte) (buck *Bucket, err error)

GetBucket will return the contents of a bucket

func (*MemoryDB) InitDB

func (b *MemoryDB) InitDB(string) (err error)

InitDB initializes the MemoryDB and must be called prior to use of the object

func (*MemoryDB) Put

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

Put will write data to a given bucket using the key

Jump to

Keyboard shortcuts

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