kv

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2024 License: BSD-3-Clause Imports: 18 Imported by: 0

Documentation

Overview

Blob is a wrapper around libpurb.Purb

Package Kv defines the abstraction for a key/value database.

The package also implements a default database implementation that is using bbolt as the engine (https://github.com/etcd-io/bbolt).

Documentation Last Review: 08.10.2020

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decode

func Decode(purb *libpurb.Purb, blob []byte) ([]byte, error)

Decode decodes a blob into a slice of bytes

func Encode

func Encode(purb *libpurb.Purb, data []byte) ([]byte, error)

Encode encodes a slice of bytes into a blob

func NewBlob

func NewBlob(path string) *libpurb.Purb

NewBlob creates a new blob

func NewKeysLoader

func NewKeysLoader(path string) fileLoader

NewKeyLoader creates a new key file loader using the given file path.

Types

type Bucket

type Bucket interface {
	// Get reads the key from the bucket and returns the value, or nil if the
	// key does not exist.
	Get(key []byte) ([]byte, error)

	// Set assigns the value to the provided key.
	Set(key, value []byte) error

	// Delete deletes the key from the bucket.
	Delete(key []byte) error

	// ForEach iterates over all the items in the bucket in a unspecified order.
	// The iteration stops when the callback returns an error.
	ForEach(func(k, v []byte) error) error

	// Scan iterates over every key that matches the prefix in an order
	// determined by the implementation. The iteration stops when the callback
	// returns an error.
	Scan(prefix []byte, fn func(k, v []byte) error) error
}

Bucket is a general interface to operate on a database bucket.

type DB

type DB interface {
	// View executes the provided read-only transaction in the context of the
	// database.
	View(fn func(ReadableTx) error) error

	// Update executes the provided writable transaction in the context of the
	// database.
	Update(fn func(WritableTx) error) error

	// Close closes the database and free the resources.
	Close() error
}

DB is a general interface to operate over a key/value database.

func NewDB

func NewDB(path string, purbIsOn bool) (DB, error)

NewDB opens a new database to the given file.

type ReadableTx

type ReadableTx interface {
	// GetBucket returns the bucket of the given name if it exists, otherwise it
	// returns nil.
	GetBucket(name []byte) Bucket
}

ReadableTx allows one to perform read-only atomic operations on the database.

type WritableTx

type WritableTx interface {
	store.Transaction

	ReadableTx

	// GetBucketOrCreate returns the bucket of the given name if it exists, or
	// it creates it.
	GetBucketOrCreate(name []byte) (Bucket, error)
}

WritableTx allows one to perform atomic operations on the database.

Directories

Path Synopsis
Package controller implements a CLI controller for the key/value database.
Package controller implements a CLI controller for the key/value database.

Jump to

Keyboard shortcuts

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