db

package
v0.0.0-...-fba379b Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2022 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const MaxBuckets = math.MaxUint16 - (8 * 256)

MaxBuckets is the maximum amount of buckets

Variables

View Source
var (
	// ErrReadOnly happens when a someone tries to write into the database when it is read-only mode.
	ErrReadOnly = errors.New("cannot make changes to database, since it is in read-only mode")

	// ErrKeyLength happens when creating a key which length is 0, such that appending a bucket prefix
	// would be quite dumb.
	ErrKeyLength = errors.New("the key length cannot be 0")

	// ErrNotFound happens when a wanted key-value pair doesn't exist.
	ErrNotFound = errors.New("the key was not found")

	// ErrBucketName happens when the wanted bucket name is too short.
	ErrBucketName = errors.New("the bucket name is too short")

	// ErrValDontMatch happens when deleting a key from the replication bucket. This means that
	// that the key-value pair which the user wants to delete is already out-of-date and thus shouldn't
	// be deleted.
	ErrValDontMatch = errors.New("values don't match")
)

Functions

This section is empty.

Types

type Bucket

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

Bucket is a collection of records in the database

func (*Bucket) Delete

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

Delete delets a key from the bucket

func (*Bucket) Get

func (b *Bucket) Get(key []byte) ([]byte, error)

Get gets a key from the bucket

func (*Bucket) Set

func (b *Bucket) Set(key []byte, data []byte) error

Set places a key into the bucket

type DB

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

DB represents the database

func NewDatabase

func NewDatabase(path string, ronly bool) (*DB, error)

NewDatabase returns a new instance of a database

func (*DB) Bucket

func (d *DB) Bucket(name string) *Bucket

Bucket is the common method for doing operations on a bucket for example: d.Bucket(defaultBucket).Get(key)

func (*DB) Close

func (d *DB) Close() error

Close closes the database connection

func (*DB) Delete

func (d *DB) Delete(key string) error

Delete removes an entry from the database

func (*DB) DeleteNotBelonging

func (d *DB) DeleteNotBelonging(doesntBelong func(string) bool) error

DeleteNotBelonging deletes all the key-value pairs in which the key matches the doesntBelong function.

func (*DB) DeleteReplicationKey

func (d *DB) DeleteReplicationKey(key, val []byte) error

DeleteReplicationKey deletes the key from the replication queue.

func (*DB) Get

func (d *DB) Get(key string) ([]byte, error)

Get finds a key-value pair from the database

func (*DB) GetLevelDB

func (d *DB) GetLevelDB() *leveldb.DB

GetLevelDB returns a pointer to the underlying levelDB database this is mostly used for testing if buckets really insert into buckets

func (*DB) GetNextReplica

func (d *DB) GetNextReplica() (key, value []byte, err error)

GetNextReplica returns the key-value pair that has changed and has not yet applied to replicas.

func (*DB) Set

func (d *DB) Set(key string, value []byte) error

Set creates a key-value entry in the database

func (*DB) SetOnReplica

func (d *DB) SetOnReplica(key string, val []byte) error

SetOnReplica sets the key to the requested value into the default database

Jump to

Keyboard shortcuts

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