lmdbenv

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package lmdbenv implements several utilities for working with LMDB databases.

Index

Constants

View Source
const (
	DefaultDirMask  = 0775
	DefaultFileMask = 0664
	DefaultMapSize  = 1 * datasize.GB
	DefaultMaxDBs   = 64
)

Variables

This section is empty.

Functions

func DBIExists

func DBIExists(txn *lmdb.Txn, dbiName string) (bool, error)

func IsEmpty

func IsEmpty(txn *lmdb.Txn, dbi lmdb.DBI) (bool, error)

IsEmpty checks if a database is empty

func New

func New(path string, flags uint) (*lmdb.Env, error)

New creates an LMDB Env suitable for generating a filter platform production LMDB test database. The returned env must be closed after use.

func NewWithOptions

func NewWithOptions(path string, opt Options) (*lmdb.Env, error)

NewWithOptions creates an LMDB Env suitable for generating a filter platform production LMDB test database using given options. The returned env must be closed after use.

func ReadDBINames

func ReadDBINames(txn *lmdb.Txn) ([]string, error)

ReadDBINames reads all DBI names from the root database

func TestEnv

func TestEnv(f TestEnvFunc) error

TestEnv creates a temporary LMDB database and calls the given test function with the temporary LMDB Env. Any error returned by this function is returned unmodified to the caller.

func TestTxn

func TestTxn(f TestTxnFunc) error

TestTxn creates a temporary LMDB database and calls the given test function with a write transaction and a new DBI that will be rolled back on return. This is a convenience wrapper around TestEnv(). Any error returned by this function is returned unmodified to the caller.

Types

type KV

type KV struct {
	Key, Val []byte
}

func ReadDBI

func ReadDBI(txn *lmdb.Txn, dbi lmdb.DBI) ([]KV, error)

ReadDBI reads all values in a DBI and returns them as a slice. This is useful for tests.

type KVString

type KVString struct {
	Key, Val string
}

func ReadDBIString

func ReadDBIString(txn *lmdb.Txn, dbi lmdb.DBI) ([]KVString, error)

ReadDBIString is a wrapper around ReadDBI() that returns all values as strings instead of []byte.

type Options

type Options struct {
	DirMask  os.FileMode       `yaml:"dir_mask"`
	FileMask os.FileMode       `yaml:"file_mask"`
	MapSize  datasize.ByteSize `yaml:"map_size"`
	MaxDBs   int               `yaml:"max_dbs"`
	NoSubdir bool              `yaml:"no_subdir"`
	Create   bool              `yaml:"create"`
	EnvFlags uint              `yaml:"-"` // Too dangerous for direct yaml support
}

Options are used for NewWithOptions, allowing a user to override them This type is also used for the yaml config file.

func (Options) WithDefaults

func (o Options) WithDefaults() Options

WithDefaults returns new Options with defaults set for values that were not set

type TestEnvFunc

type TestEnvFunc func(env *lmdb.Env) error

type TestTxnFunc

type TestTxnFunc func(txn *lmdb.Txn, dbi lmdb.DBI) error

Directories

Path Synopsis
Package stats implements a Prometheus Collector for LMDBs
Package stats implements a Prometheus Collector for LMDBs
Package strategy implements various LMDB data insert strategies.
Package strategy implements various LMDB data insert strategies.

Jump to

Keyboard shortcuts

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