lmdb++
Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Attributes | List of all members
lmdb::dbi Class Reference

Resource class for MDB_dbi handles. More...

#include <lmdb++.h>

Public Member Functions

 dbi (const MDB_dbi handle) noexcept
 Constructor. More...
 
 dbi (dbi &&other) noexcept
 Move constructor. More...
 
dbioperator= (dbi &&other) noexcept
 Move assignment operator. More...
 
 ~dbi () noexcept
 Destructor. More...
 
 operator MDB_dbi () const noexcept
 Returns the underlying MDB_dbi handle. More...
 
MDB_dbi handle () const noexcept
 Returns the underlying MDB_dbi handle. More...
 
MDB_stat stat (MDB_txn *const txn) const
 Returns statistics for this database. More...
 
unsigned int flags (MDB_txn *const txn) const
 Retrieves the flags for this database handle. More...
 
std::size_t size (MDB_txn *const txn) const
 Returns the number of records in this database. More...
 
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. More...
 
template<typename K >
bool get (MDB_txn *const txn, const K &key) const
 Retrieves a key from this database. More...
 
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. More...
 
template<typename V >
bool get (MDB_txn *const txn, const char *const key, V &val) const
 Retrieves a key/value pair from this database. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
template<typename K >
bool del (MDB_txn *const txn, const K &key)
 Removes a key/value pair from this database. More...
 

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. More...
 

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

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

Constructor.

Parameters
handlea valid MDB_dbi handle
lmdb::dbi::dbi ( dbi &&  other)
inlinenoexcept

Move constructor.

lmdb::dbi::~dbi ( )
inlinenoexcept

Destructor.

Member Function Documentation

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
void lmdb::dbi::drop ( MDB_txn *const  txn,
const bool  del = false 
)
inline
Parameters
txna transaction handle
del
Exceptions
lmdb::erroron failure
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
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
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
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
MDB_dbi lmdb::dbi::handle ( ) const
inlinenoexcept

Returns the underlying MDB_dbi handle.

static 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
lmdb::dbi::operator MDB_dbi ( ) const
inlinenoexcept

Returns the underlying MDB_dbi handle.

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

Move assignment operator.

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
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
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
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
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
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
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

MDB_dbi lmdb::dbi::_handle {0}
protected
constexpr unsigned int lmdb::dbi::default_flags = 0
static
constexpr unsigned int lmdb::dbi::default_put_flags = 0
static

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