badger

package
v1.9.1 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2021 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package badger provides an instrumented wrapper around a badger database.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DB

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

The DB type represents the badger DB connection and is the main entrypoint for querying and manipulating data.

func Open

func Open(opts ...Option) (*DB, error)

Open a badger database using the provided options. Uses badger.DefaultOptions storing data in a "badger" directory.

func (*DB) Backup

func (db *DB) Backup(ctx context.Context, wr io.Writer) error

Backup writes a full backup to the provided io.Writer implementation.

func (*DB) Close

func (db *DB) Close() error

Close the connection to the database.

func (*DB) Ping

func (db *DB) Ping() error

Ping syncs the badger database to determine everything is working as expected.

func (*DB) Restore

func (db *DB) Restore(ctx context.Context, rd io.Reader) error

Restore the database to the dump provided in the io.Reader implementation.

func (*DB) Update

func (db *DB) Update(ctx context.Context, fn func(ctx context.Context, txn *Txn) error) error

Update executes a function, creating and managing a read-write transaction for the user. Error returned by the function is relayed by the Update method. Update cannot be used with managed transactions.

func (*DB) View

func (db *DB) View(ctx context.Context, fn func(ctx context.Context, txn *Txn) error) error

View executes a function creating and managing a read-only transaction for the user. Error returned by the function is relayed by the View method. If View is used with managed transactions, it would assume a read timestamp of MaxUint64.

type Item

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

The Item type represents a key/value item stored in the database.

func (*Item) Value

func (item *Item) Value(ctx context.Context, fn func(ctx context.Context, value []byte) error) error

Value retrieves the value of the item from the value log.

This method must be called within a transaction. Calling it outside a transaction is considered undefined behavior. If an iterator is being used, then Item.Value() is defined in the current iteration only, because items are reused.

If you need to use a value outside a transaction, please use Item.ValueCopy instead, or copy it yourself. Value might change once discard or commit is called. Use ValueCopy if you want to do a Set after Get.

type Option

type Option func(opts *badger.Options)

The Option type is a function that modifies the badger configuration.

func WithDir

func WithDir(dir string) Option

WithDir sets the location on disk badger will write data.

func WithEncryptionKey

func WithEncryptionKey(key []byte) Option

WithEncryptionKey sets the key to use to encrypt data at rest on the filesystem.

func WithEncryptionKeyRotationDuration

func WithEncryptionKeyRotationDuration(dur time.Duration) Option

WithEncryptionKeyRotationDuration sets how often to change the generated encryption key.

type Txn

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

The Txn type represents a database transaction, and is used to query and modify data.

func (*Txn) Delete

func (txn *Txn) Delete(ctx context.Context, key []byte) error

Delete deletes a key.

This is done by adding a delete marker for the key at commit timestamp. Any reads happening before this timestamp would be unaffected. Any reads after this commit would see the deletion.

The current transaction keeps a reference to the key byte slice argument. Users must not modify the key until the end of the transaction.

func (*Txn) Get

func (txn *Txn) Get(ctx context.Context, key []byte) (*Item, error)

Get looks for key and returns corresponding Item. If key is not found, ErrKeyNotFound is returned.

func (*Txn) Set

func (txn *Txn) Set(ctx context.Context, key, value []byte) error

Set adds a key-value pair to the database. It will return ErrReadOnlyTxn if update flag was set to false when creating the transaction.

The current transaction keeps a reference to the key and val byte slice arguments. Users must not modify key and val until the end of the transaction.

Jump to

Keyboard shortcuts

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