wrap

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2025 License: BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Overview

Package wrap provides a thin, opinionated abstraction for the most common LMDB operations.

Index

Constants

View Source
const MapSize = 10 * 1 << 30 // 10 GB

Variables

View Source
var (
	ErrDuplicateDbName = errors.New("duplicate database name")
	ErrDbNameNotFound  = errors.New("database name not found")
	ErrDBClosed        = errors.New("database is closed")
	ErrEmptyKey        = errors.New("empty key")
)

Functions

This section is empty.

Types

type DB

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

DB represents a simple LMDB database wrapper.

func New

func New(dirPath string, dbNames []string) (*DB, int, error)

New creates (or opens) an LMDB environment at the specified directory path and initializes the given databases. If the directory does not exist, it will be created. Remember to call Close() on the returned DB to cleanly shut down the environment. Returns the DB pointer, the number of stale readers cleared, and any error.

func (*DB) Close

func (db *DB) Close()

Close cleanly shuts down the LMDB environment.

func (*DB) Delete

func (db *DB) Delete(dbName string, key []byte) error

Delete removes a key/value pair from the database.

func (*DB) GetDBis added in v1.1.0

func (db *DB) GetDBis() map[string]lmdb.DBI

GetDBis returns a copy of database names to DBI handle mappings.

func (*DB) Read

func (db *DB) Read(dbName string, key []byte) ([]byte, error)

Read retrieves a value from the database.

func (*DB) Update added in v1.1.0

func (db *DB) Update(op lmdb.TxnOp) error

Update sends an LMDB operation to the update goroutine and waits for the result.

Usage:

err := db.Update(func(txn *lmdb.Txn) error {
	dbi := db.GetDBis()["users"]
	data, err := txn.Get(dbi, []byte("user:123"))
	if err != nil {
		return err
	}
	if !shouldUpdate(data) {
		return nil
	}
	return txn.Put(dbi, []byte("user:123"), update(data), 0)
})

func (*DB) Write

func (db *DB) Write(dbName string, key, value []byte) error

Write inserts a key/value pair into the database.

Jump to

Keyboard shortcuts

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