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

Resource class for MDB_dbi handles. More...

#include <lmdb++.h>

Public Member Functions

 dbi () noexcept
 Constructor.
 
 dbi (const MDB_dbi handle) noexcept
 Constructor.
 
 ~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 std::string_view key, std::string_view &data)
 Retrieves a key/value pair from this database.
 
bool put (MDB_txn *const txn, const std::string_view key, std::string_view data, const unsigned int flags=default_put_flags)
 Stores a key/value pair into this database.
 
bool del (MDB_txn *const txn, const std::string_view key)
 Removes a key from this database.
 
bool del (MDB_txn *const txn, const std::string_view key, const std::string_view val)
 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 {(std::numeric_limits<MDB_dbi>::max)()}
 

Detailed Description

Constructor & Destructor Documentation

◆ dbi() [1/2]

lmdb::dbi::dbi ( )
inlinenoexcept

Constructor.

Note
Creates an uninitialized dbi instance. You must move or move-assign a valid dbi instance onto it before you can use it.

◆ dbi() [2/2]

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

Constructor.

Parameters
handlea valid MDB_dbi handle

◆ ~dbi()

lmdb::dbi::~dbi ( )
inlinenoexcept

Destructor.

Member Function Documentation

◆ del() [1/2]

bool lmdb::dbi::del ( MDB_txn *const txn,
const std::string_view key )
inline

Removes a key from this database.

Parameters
txna transaction handle
key
Exceptions
lmdb::erroron failure

◆ del() [2/2]

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

Removes a key/value pair from this database.

Parameters
txna transaction handle
key
val
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()

bool lmdb::dbi::get ( MDB_txn *const txn,
const std::string_view key,
std::string_view & 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()

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

◆ operator MDB_dbi()

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

Returns the underlying MDB_dbi handle.

◆ put()

bool lmdb::dbi::put ( MDB_txn *const txn,
const std::string_view key,
std::string_view 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 {(std::numeric_limits<MDB_dbi>::max)()}
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: