lmdb++
Loading...
Searching...
No Matches
lmdb::dbi Class Reference

Resource class for MDB_dbi handles. More...

#include <lmdb++.h>

Public Member Functions

 dbi (const MDB_dbi handle) noexcept
 Constructor.
 dbi (dbi &&other) noexcept
 Move constructor.
dbioperator= (dbi &&other) noexcept
 Move assignment operator.
 ~dbi () noexcept
 Destructor.
 operator MDB_dbi () const noexcept
 Returns the underlying MDB_dbi handle.
MDB_dbi handle () const noexcept
 Returns the underlying MDB_dbi handle.
MDB_stat stat (MDB_txn *const txn) const
 Returns statistics for this database.
unsigned int flags (MDB_txn *const txn) const
 Retrieves the flags for this database handle.
std::size_t size (MDB_txn *const txn) const
 Returns the number of records in this database.
void drop (MDB_txn *const txn, const bool del=false)
dbiset_compare (MDB_txn *const txn, MDB_cmp_func *const cmp=nullptr)
 Sets a custom key comparison function for this database.
bool get (MDB_txn *const txn, const val &key, val &data)
 Retrieves a key/value pair from this database.
template<typename K>
bool get (MDB_txn *const txn, const K &key) const
 Retrieves a key from this database.
template<typename K, typename V>
bool get (MDB_txn *const txn, const K &key, V &val) const
 Retrieves a key/value pair from this database.
template<typename V>
bool get (MDB_txn *const txn, const char *const key, V &val) const
 Retrieves a key/value pair from this database.
bool put (MDB_txn *const txn, const val &key, val &data, const unsigned int flags=default_put_flags)
 Stores a key/value pair into this database.
template<typename K>
bool put (MDB_txn *const txn, const K &key, const unsigned int flags=default_put_flags)
 Stores a key into this database.
template<typename K, typename V>
bool put (MDB_txn *const txn, const K &key, const V &val, const unsigned int flags=default_put_flags)
 Stores a key/value pair into this database.
template<typename V>
bool put (MDB_txn *const txn, const char *const key, const V &val, const unsigned int flags=default_put_flags)
 Stores a key/value pair into this database.
bool put (MDB_txn *const txn, const char *const key, const char *const val, const unsigned int flags=default_put_flags)
 Stores a key/value pair into this database.
bool del (MDB_txn *const txn, const val &key)
 Removes a key/value pair from this database.
template<typename K>
bool del (MDB_txn *const txn, const K &key)
 Removes a key/value pair from this database.

Static Public Member Functions

static dbi open (MDB_txn *const txn, const char *const name=nullptr, const unsigned int flags=default_flags)
 Opens a database handle.

Static Public Attributes

static constexpr unsigned int default_flags = 0
static constexpr unsigned int default_put_flags = 0

Protected Attributes

MDB_dbi _handle {0}

Detailed Description

Resource class for MDB_dbi handles.

Note
Instances of this class are movable, but not copyable.
See also
http://symas.com/mdb/doc/group__mdb.html#gadbe68a06c448dfb62da16443d251a78b

Constructor & Destructor Documentation

◆ dbi() [1/2]

lmdb::dbi::dbi ( const MDB_dbi handle)
inlinenoexcept

Constructor.

Parameters
handlea valid MDB_dbi handle

◆ dbi() [2/2]

lmdb::dbi::dbi ( dbi && other)
inlinenoexcept

Move constructor.

◆ ~dbi()

lmdb::dbi::~dbi ( )
inlinenoexcept

Destructor.

Member Function Documentation

◆ del() [1/2]

template<typename K>
bool lmdb::dbi::del ( MDB_txn *const txn,
const K & key )
inline

Removes a key/value pair from this database.

Parameters
txna transaction handle
key
Exceptions
lmdb::erroron failure

◆ del() [2/2]

bool lmdb::dbi::del ( MDB_txn *const txn,
const val & key )
inline

Removes a key/value pair from this database.

Parameters
txna transaction handle
key
Exceptions
lmdb::erroron failure

◆ drop()

void lmdb::dbi::drop ( MDB_txn *const txn,
const bool del = false )
inline
Parameters
txna transaction handle
del
Exceptions
lmdb::erroron failure

◆ flags()

unsigned int lmdb::dbi::flags ( MDB_txn *const txn) const
inline

Retrieves the flags for this database handle.

Parameters
txna transaction handle
Exceptions
lmdb::erroron failure

◆ get() [1/4]

template<typename V>
bool lmdb::dbi::get ( MDB_txn *const txn,
const char *const key,
V & val ) const
inline

Retrieves a key/value pair from this database.

Parameters
txna transaction handle
keya NUL-terminated string key
val
Exceptions
lmdb::erroron failure

◆ get() [2/4]

template<typename K>
bool lmdb::dbi::get ( MDB_txn *const txn,
const K & key ) const
inline

Retrieves a key from this database.

Parameters
txna transaction handle
key
Exceptions
lmdb::erroron failure

◆ get() [3/4]

template<typename K, typename V>
bool lmdb::dbi::get ( MDB_txn *const txn,
const K & key,
V & val ) const
inline

Retrieves a key/value pair from this database.

Parameters
txna transaction handle
key
val
Exceptions
lmdb::erroron failure

◆ get() [4/4]

bool lmdb::dbi::get ( MDB_txn *const txn,
const val & key,
val & data )
inline

Retrieves a key/value pair from this database.

Parameters
txna transaction handle
key
data
Exceptions
lmdb::erroron failure

◆ handle()

MDB_dbi lmdb::dbi::handle ( ) const
inlinenoexcept

Returns the underlying MDB_dbi handle.

◆ open()

dbi lmdb::dbi::open ( MDB_txn *const txn,
const char *const name = nullptr,
const unsigned int flags = default_flags )
inlinestatic

Opens a database handle.

Parameters
txnthe transaction handle
name
flags
Exceptions
lmdb::erroron failure

◆ operator MDB_dbi()

lmdb::dbi::operator MDB_dbi ( ) const
inlinenoexcept

Returns the underlying MDB_dbi handle.

◆ operator=()

dbi & lmdb::dbi::operator= ( dbi && other)
inlinenoexcept

Move assignment operator.

◆ put() [1/5]

bool lmdb::dbi::put ( MDB_txn *const txn,
const char *const key,
const char *const val,
const unsigned int flags = default_put_flags )
inline

Stores a key/value pair into this database.

Parameters
txna transaction handle
keya NUL-terminated string key
vala NUL-terminated string key
flags
Exceptions
lmdb::erroron failure

◆ put() [2/5]

template<typename V>
bool lmdb::dbi::put ( MDB_txn *const txn,
const char *const key,
const V & val,
const unsigned int flags = default_put_flags )
inline

Stores a key/value pair into this database.

Parameters
txna transaction handle
keya NUL-terminated string key
val
flags
Exceptions
lmdb::erroron failure

◆ put() [3/5]

template<typename K>
bool lmdb::dbi::put ( MDB_txn *const txn,
const K & key,
const unsigned int flags = default_put_flags )
inline

Stores a key into this database.

Parameters
txna transaction handle
key
flags
Exceptions
lmdb::erroron failure

◆ put() [4/5]

template<typename K, typename V>
bool lmdb::dbi::put ( MDB_txn *const txn,
const K & key,
const V & val,
const unsigned int flags = default_put_flags )
inline

Stores a key/value pair into this database.

Parameters
txna transaction handle
key
val
flags
Exceptions
lmdb::erroron failure

◆ put() [5/5]

bool lmdb::dbi::put ( MDB_txn *const txn,
const val & key,
val & data,
const unsigned int flags = default_put_flags )
inline

Stores a key/value pair into this database.

Parameters
txna transaction handle
key
data
flags
Exceptions
lmdb::erroron failure

◆ set_compare()

dbi & lmdb::dbi::set_compare ( MDB_txn *const txn,
MDB_cmp_func *const cmp = nullptr )
inline

Sets a custom key comparison function for this database.

Parameters
txna transaction handle
cmpthe comparison function
Exceptions
lmdb::erroron failure

◆ size()

std::size_t lmdb::dbi::size ( MDB_txn *const txn) const
inline

Returns the number of records in this database.

Parameters
txna transaction handle
Exceptions
lmdb::erroron failure

◆ stat()

MDB_stat lmdb::dbi::stat ( MDB_txn *const txn) const
inline

Returns statistics for this database.

Parameters
txna transaction handle
Exceptions
lmdb::erroron failure

Member Data Documentation

◆ _handle

MDB_dbi lmdb::dbi::_handle {0}
protected

◆ default_flags

unsigned int lmdb::dbi::default_flags = 0
staticconstexpr

◆ default_put_flags

unsigned int lmdb::dbi::default_put_flags = 0
staticconstexpr

The documentation for this class was generated from the following file: