badgerd

package module
v0.0.0-...-c3f5c77 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package badgerd provides a BadgerDB driver for go-shelve.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Open

func Open(opts badger.Options) (*badger.DB, error)

Open is a wrapper around badger.Open.

Types

type Store

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

Store is a BadgerDB driver for shelve.Shelf.

func New

func New(db *badger.DB) (*Store, error)

New creates a new BadgerDB store.

func NewDefault

func NewDefault(path string) (*Store, error)

NewDefault creates a new BadgerDB store with sensible default values.

func (*Store) Close

func (s *Store) Close() error

Close closes the underlying BadgerDB database.

func (*Store) Delete

func (s *Store) Delete(key []byte) error

Delete removes a key-value pair from the store.

func (*Store) Get

func (s *Store) Get(key []byte) ([]byte, error)

Get retrieves the value associated with a key from the store. If the key is not found, it returns nil.

func (*Store) Has

func (s *Store) Has(key []byte) (bool, error)

Has reports whether a key exists in the store.

func (*Store) Items

func (s *Store) Items(
	start []byte,
	order int,
	fn func(key, value []byte) (bool, error),
) error

Items iterates over key-value pairs in the database, calling fn(k, v) for each pair in the sequence. The iteration stops early if the function fn returns false.

The start parameter specifies the key from which the iteration should start. If the start parameter is nil, the iteration will begin from the first key in the database.

The order parameter specifies the order in which the items should be yielded. A negative value for order will cause the iteration to occur in reverse order.

The key-value pairs are returned in lexicographically sorted order.

The value parameter must only be used inside fn, as it is reused during the iteration.

func (*Store) Len

func (s *Store) Len() int64

Len returns the number of items in the store. It returns -1 if an error occurs.

Warning: BadgerDB doesn't provide a method to count the number of stored items and Len will iterate through the entire DB to retrieve this information.

See: https://discuss.dgraph.io/t/count-of-items-in-db/7549/2

func (*Store) Put

func (s *Store) Put(key, value []byte) error

Put stores a key-value pair in the store. If the key already exists, it overwrites the existing value.

func (*Store) Sync

func (s *Store) Sync() error

Sync synchronizes the underlying BadgerDB database to persistent storage.

Jump to

Keyboard shortcuts

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