badger

package
v0.7.5 Latest Latest
Warning

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

Go to latest
Published: May 14, 2024 License: Apache-2.0 Imports: 8 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 is a basic threadsafe key-value store.

func NewBadgerDB

func NewBadgerDB(ctx context.Context, path string, options *Options) (*BadgerDB, error)

NewBadgerDB creates a new BadgerDB. It takes a path, like path/to/db, where the database will be stored.

func (*BadgerDB) BeginTransaction

func (d *BadgerDB) BeginTransaction() kv.Transaction

BeginTransaction creates a new transaction.

func (*BadgerDB) Close

func (d *BadgerDB) Close() error

Close closes the underlying database.

func (*BadgerDB) Delete

func (d *BadgerDB) Delete(key []byte) error

Delete deletes a value from the database.

func (*BadgerDB) Get

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

Get retrieves a value from the database.

func (*BadgerDB) Set

func (d *BadgerDB) Set(key, val []byte) error

Set sets a value in the database.

type Options

type Options struct {
	// GuaranteeFSync guarantees that all writes to the wal are fsynced before
	// attempting to be written to the LSM tree.
	GuaranteeFSync bool

	// GarbageCollectionInterval is the interval at which the garbage collector
	// runs.
	GarbageCollectionInterval time.Duration

	// Logger is the logger to use for the database.
	Logger log.Logger

	// GarbageCollectionDiscardRatio is the ratio at which the garbage collector discards
	// old versions of a value.  It must be between 0 and 1.
	// Lower values will have a higher performance hit, but will use less disk space.
	GarbageCollectionDiscardRatio float64
}

Options are options for the BadgerDB. These get translated into Badger's options. We provide this abstraction layer since Badger has a lot of options, and I don't want future users of this to worry about all of them.

type Transaction

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

a Transaction is a basic wrapper around a badger to handle commits and rollbacks

func (*Transaction) Commit

func (t *Transaction) Commit() error

func (*Transaction) Delete

func (t *Transaction) Delete(key []byte) error

func (*Transaction) Discard

func (t *Transaction) Discard()

func (*Transaction) Get

func (t *Transaction) Get(key []byte) ([]byte, error)

func (*Transaction) Set

func (t *Transaction) Set(key, val []byte) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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