database

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2023 License: Apache-2.0 Imports: 2 Imported by: 10

Documentation

Index

Constants

View Source
const (
	BadgerMemoryMap = "mmap"
	BadgerFileIO    = "fileio"
)

Badger FileLoadingMode constants.

Variables

View Source
var (
	// ErrNotFound is the type returned on DB implementations if an item does not
	// exist.
	ErrNotFound = errors.New("not found")
	// ErrOpNotSupported is the type returned on DB implementations if an operation
	// is not supported.
	ErrOpNotSupported = errors.New("operation not supported")
)

Functions

func IsErrNotFound

func IsErrNotFound(err error) bool

IsErrNotFound returns true if the cause of the given error is ErrNotFound.

func IsErrOpNotSupported

func IsErrOpNotSupported(err error) bool

IsErrOpNotSupported returns true if the cause of the given error is ErrOpNotSupported.

Types

type DB

type DB interface {
	// Open opens the database available with the given options.
	Open(dataSourceName string, opt ...Option) error
	// Close closes the current database.
	Close() error
	// Get returns the value stored in the given table/bucket and key.
	Get(bucket, key []byte) (ret []byte, err error)
	// Set sets the given value in the given table/bucket and key.
	Set(bucket, key, value []byte) error
	// CmpAndSwap swaps the value at the given bucket and key if the current
	// value is equivalent to the oldValue input. Returns 'true' if the
	// swap was successful and 'false' otherwise.
	CmpAndSwap(bucket, key, oldValue, newValue []byte) ([]byte, bool, error)
	// Del deletes the data in the given table/bucket and key.
	Del(bucket, key []byte) error
	// List returns a list of all the entries in a given table/bucket.
	List(bucket []byte) ([]*Entry, error)
	// Update performs a transaction with multiple read-write commands.
	Update(tx *Tx) error
	// CreateTable creates a table or a bucket in the database.
	CreateTable(bucket []byte) error
	// DeleteTable deletes a table or a bucket in the database.
	DeleteTable(bucket []byte) error
}

DB is a interface to be implemented by the databases.

type Entry

type Entry struct {
	Bucket []byte
	Key    []byte
	Value  []byte
}

Entry is the return value for list commands.

type NotSupportedDB added in v0.4.0

type NotSupportedDB struct{}

NotSupportedDB is a db implementation used on database drivers when the no<driver> tags are used.

func (*NotSupportedDB) Close added in v0.4.0

func (*NotSupportedDB) Close() error

func (*NotSupportedDB) CmpAndSwap added in v0.4.0

func (*NotSupportedDB) CmpAndSwap(bucket, key, oldValue, newValue []byte) ([]byte, bool, error)

func (*NotSupportedDB) CreateTable added in v0.4.0

func (*NotSupportedDB) CreateTable(bucket []byte) error

func (*NotSupportedDB) Del added in v0.4.0

func (*NotSupportedDB) Del(bucket, key []byte) error

func (*NotSupportedDB) DeleteTable added in v0.4.0

func (*NotSupportedDB) DeleteTable(bucket []byte) error

func (*NotSupportedDB) Get added in v0.4.0

func (*NotSupportedDB) Get(bucket, key []byte) (ret []byte, err error)

func (*NotSupportedDB) List added in v0.4.0

func (*NotSupportedDB) List(bucket []byte) ([]*Entry, error)

func (*NotSupportedDB) Open added in v0.4.0

func (*NotSupportedDB) Open(dataSourceName string, opt ...Option) error

func (*NotSupportedDB) Set added in v0.4.0

func (*NotSupportedDB) Set(bucket, key, value []byte) error

func (*NotSupportedDB) Update added in v0.4.0

func (*NotSupportedDB) Update(tx *Tx) error

type Option

type Option func(o *Options) error

Option is the modifier type over Options.

func WithBadgerFileLoadingMode added in v0.3.0

func WithBadgerFileLoadingMode(mode string) Option

WithBadgerFileLoadingMode is a modifier that sets the ValueLogLoadingMode of Badger db.

func WithDatabase

func WithDatabase(db string) Option

WithDatabase is a modifier that sets the Database attribute of Options.

func WithValueDir

func WithValueDir(path string) Option

WithValueDir is a modifier that sets the ValueDir attribute of Options.

type Options

type Options struct {
	Database              string
	ValueDir              string
	BadgerFileLoadingMode string
}

Options are configuration options for the database.

type Tx

type Tx struct {
	Operations []*TxEntry
}

Tx represents a transaction and it's list of multiple TxEntry. Each TxEntry represents a read or write operation on the database.

func (*Tx) Cas

func (tx *Tx) Cas(bucket, key, value []byte)

Cas adds a new compare-and-swap query to the transaction.

func (*Tx) Cmp

func (tx *Tx) Cmp(bucket, key, value []byte)

Cmp adds a new compare-or-rollback query to the transaction.

func (*Tx) CreateTable

func (tx *Tx) CreateTable(bucket []byte)

CreateTable adds a new create query to the transaction.

func (*Tx) Del

func (tx *Tx) Del(bucket, key []byte)

Del adds a new delete query to the transaction.

func (*Tx) DeleteTable

func (tx *Tx) DeleteTable(bucket []byte)

DeleteTable adds a new create query to the transaction.

func (*Tx) Get

func (tx *Tx) Get(bucket, key []byte)

Get adds a new read query to the transaction.

func (*Tx) Set

func (tx *Tx) Set(bucket, key, value []byte)

Set adds a new write query to the transaction.

type TxCmd

type TxCmd int

TxCmd is the type used to represent database command and operations.

const (
	// CreateTable on a TxEntry will represent the creation of a table or
	// bucket on the database.
	CreateTable TxCmd = iota
	// DeleteTable on a TxEntry will represent the deletion of a table or
	// bucket on the database.
	DeleteTable
	// Get on a TxEntry will represent a command to retrieve data from the
	// database.
	Get
	// Set on a TxEntry will represent a command to write data on the
	// database.
	Set
	// Delete on a TxEntry represent a command to delete data on the database.
	Delete
	// CmpAndSwap on a TxEntry will represent a compare and swap operation on
	// the database. It will compare the value read and change it if it's
	// different. The TxEntry will contain the value read.
	CmpAndSwap
	// CmpOrRollback on a TxEntry will represent a read transaction that will
	// compare the values will the ones passed, and if they don't match the
	// transaction will fail
	CmpOrRollback
)

func (TxCmd) String

func (o TxCmd) String() string

String implements the fmt.Stringer interface on TxCmd.

type TxEntry

type TxEntry struct {
	Bucket   []byte
	Key      []byte
	Value    []byte
	CmpValue []byte
	// Where the result of Get or CmpAndSwap txns is stored.
	Result  []byte
	Cmd     TxCmd
	Swapped bool
}

TxEntry is the base elements for the transactions, a TxEntry is a read or write operation on the database.

Jump to

Keyboard shortcuts

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