kv

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2024 License: BSD-3-Clause Imports: 4 Imported by: 3

Documentation

Overview

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

This section is empty.

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

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

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

	// ForEach iterates over all the items in the bucket in an 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 New

func New(path string) (DB, error)

New 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