Documentation ¶
Overview ¶
Package badger provides an instrumented wrapper around a badger database.
Index ¶
- type DB
- func (db *DB) Backup(ctx context.Context, wr io.Writer) error
- func (db *DB) Close() error
- func (db *DB) Ping() error
- func (db *DB) Restore(ctx context.Context, rd io.Reader) error
- func (db *DB) Update(ctx context.Context, fn func(ctx context.Context, txn *Txn) error) error
- func (db *DB) View(ctx context.Context, fn func(ctx context.Context, txn *Txn) error) error
- type Item
- type Option
- type Txn
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 ¶
Open a badger database using the provided options. Uses badger.DefaultOptions storing data in a "badger" directory.
func (*DB) Update ¶
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.
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 WithEncryptionKey ¶
WithEncryptionKey sets the key to use to encrypt data at rest on the filesystem.
func WithEncryptionKeyRotationDuration ¶
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 ¶
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 ¶
Get looks for key and returns corresponding Item. If key is not found, ErrKeyNotFound is returned.
func (*Txn) Set ¶
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.