db

package
v0.0.0-...-868bdbc Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2020 License: AGPL-3.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BadgerDB

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

BadgerDB ...

func NewBadgerDB

func NewBadgerDB(valueDir string, dir string) (*BadgerDB, error)

NewBadgerDB ...

func NewBadgerDBWithOpts

func NewBadgerDBWithOpts(valueDir string, dir string, opts badger.Options) (*BadgerDB, error)

NewBadgerDBWithOpts ...

func (*BadgerDB) BadgerIterator

func (db *BadgerDB) BadgerIterator() (*badger.Iterator, error)

BadgerIterator ...

func (*BadgerDB) Close

func (db *BadgerDB) Close()

func (*BadgerDB) Delete

func (db *BadgerDB) Delete([]byte)

func (*BadgerDB) DeleteSync

func (db *BadgerDB) DeleteSync([]byte)

func (*BadgerDB) Get

func (db *BadgerDB) Get(key []byte) []byte

func (*BadgerDB) GetBadgerDB

func (db *BadgerDB) GetBadgerDB() *badger.DB

GetBadgerDB ...

func (*BadgerDB) Has

func (db *BadgerDB) Has(key []byte) bool

func (*BadgerDB) Iterator

func (db *BadgerDB) Iterator(start, end []byte) Iterator

func (*BadgerDB) Print

func (db *BadgerDB) Print()

func (*BadgerDB) Set

func (db *BadgerDB) Set(key []byte, value []byte)

func (*BadgerDB) SetSync

func (db *BadgerDB) SetSync(key []byte, value []byte)

type Batch

type Batch interface {
	SetDeleter
	Write()
	WriteSync()
}

type DB

type DB interface {

	// Get returns nil if key doesn't exist.
	// CONTRACT: key, value readonly []byte
	Get([]byte) []byte

	// Has checks if a key exists.
	// CONTRACT: key, value readonly []byte
	Has(key []byte) bool

	// Set sets the key.
	// CONTRACT: key, value readonly []byte
	Set([]byte, []byte)
	SetSync([]byte, []byte)

	// Delete deletes the key.
	// CONTRACT: key readonly []byte
	Delete([]byte)
	DeleteSync([]byte)

	// Iterate over a domain of keys in ascending order. End is exclusive.
	// Start must be less than end, or the Iterator is invalid.
	// If end is nil, iterates up to the last item (inclusive).
	// CONTRACT: No writes may happen within a domain while an iterator exists over it.
	// CONTRACT: start, end readonly []byte
	Iterator(start, end []byte) Iterator

	// Closes the connection.
	Close()

	// For debugging
	Print()

	GetBadgerDB() *badger.DB

	BadgerIterator() (*badger.Iterator, error)
}

DB ... A nil key is interpreted as an empty byteslice.

func NewDB

func NewDB(name string, backend DBType, dir string) DB

NewDB creates a new database of type backend with the given name. NOTE: function panics if:

  • backend is unknown (not registered)
  • creator function, provided during registration, returns error

type DBType

type DBType string

DBType ...

const (
	// GoLevelDBBackend ..
	GoLevelDBBackend DBType = "goleveldb"
	// GoBadgerBackend ...
	GoBadgerBackend DBType = "badger"
)

type Iterator

type Iterator interface {

	// The start & end (exclusive) limits to iterate over.
	// If end < start, then the Iterator goes in reverse order.
	//
	// A domain of ([]byte{12, 13}, []byte{12, 14}) will iterate
	// over anything with the prefix []byte{12, 13}.
	//
	// The smallest key is the empty byte array []byte{} - see BeginningKey().
	// The largest key is the nil byte array []byte(nil) - see EndingKey().
	// CONTRACT: start, end readonly []byte
	Domain() (start []byte, end []byte)

	// Valid returns whether the current position is valid.
	// Once invalid, an Iterator is forever invalid.
	Valid() bool

	// Next moves the iterator to the next sequential key in the database, as
	// defined by order of iteration.
	//
	// If Valid returns false, this method will panic.
	Next()

	// Key returns the key of the cursor.
	// If Valid returns false, this method will panic.
	// CONTRACT: key readonly []byte
	Key() (key []byte)

	// Value returns the value of the cursor.
	// If Valid returns false, this method will panic.
	// CONTRACT: value readonly []byte
	Value() (value []byte)

	// Close releases the Iterator.
	Close()
}

Usage:

var itr Iterator = ... defer itr.Close()

for ; itr.Valid(); itr.Next() {
	k, v := itr.Key(); itr.Value()
	// ...
}

type SetDeleter

type SetDeleter interface {
	Set(key, value []byte) // CONTRACT: key, value readonly []byte
	Delete(key []byte)     // CONTRACT: key readonly []byte
}

Jump to

Keyboard shortcuts

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