bboltd

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

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

Go to latest
Published: Sep 23, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package bboltd provides a BBoltDB driver for go-shelve.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Open

func Open(path string, mode os.FileMode, options *bbolt.Options) (*bbolt.DB, error)

Open opens an existing BoltDB store. It is a wrapper around bbolt.Open.

Types

type Store

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

Store is a BoltDB driver for shelve.Shelf.

func New

func New(db *bbolt.DB, bucket []byte) (*Store, error)

New creates a new BoltDB store. The bucket is created if it doesn't exist.

func NewDefault

func NewDefault(path string, bucket []byte) (*Store, error)

NewDefault creates a new BoltDB store with sensible default values. The bucket is created if it doesn't exist.

func (*Store) Close

func (s *Store) Close() error

Close closes the underlying BoltDB database.

func (*Store) Delete

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

Delete removes a key 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.

func (*Store) Len

func (s *Store) Len() int64

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

func (*Store) Put

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

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

func (*Store) Sync

func (s *Store) Sync() error

Sync synchronizes the BoltDB contents to persistent storage.

Jump to

Keyboard shortcuts

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