Documentation
¶
Overview ¶
Package wrap provides a thin, opinionated abstraction for the most common LMDB operations.
Index ¶
- Constants
- Variables
- type DB
- func (db *DB) Close()
- func (db *DB) Delete(dbName string, key []byte) error
- func (db *DB) GetDBis() map[string]lmdb.DBI
- func (db *DB) Read(dbName string, key []byte) ([]byte, error)
- func (db *DB) Update(op lmdb.TxnOp) error
- func (db *DB) View(op lmdb.TxnOp) error
- func (db *DB) Write(dbName string, key, value []byte) error
Constants ¶
View Source
const ( MaxNamedDBs = 128 // If you need more, you probably shouldn't be using LMDB. MapSize = 10 * 1 << 30 // 10 GB )
Variables ¶
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 ¶
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) GetDBis ¶ added in v1.1.0
GetDBis returns a copy of database names to DBI handle mappings.
func (*DB) Update ¶ added in v1.1.0
Update runs an LMDB transaction.
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)
})
Click to show internal directories.
Click to hide internal directories.