MDBX Containers
Loading...
Searching...
No Matches
mdbxc::BaseTable Class Reference

Base class providing common functionality for MDBX database access. More...

#include <BaseTable.hpp>

Inheritance diagram for mdbxc::BaseTable:
mdbxc::KeyValueTable< KeyT, ValueT >

Public Member Functions

 BaseTable (std::shared_ptr< Connection > connection, std::string name, MDBX_db_flags_t flags)
 Construct the database table accessor.
 
virtual ~BaseTable ()=default
 
bool is_connected () const
 Checks if the connection is currently active.
 
void connect ()
 Connects to the MDBX environment if not already connected.
 
void disconnect ()
 Disconnects the MDBX environment.
 
void begin (TransactionMode mode=TransactionMode::WRITABLE)
 Begins a manual transaction (must be committed or rolled back later).
 
void commit ()
 Commits the current manual transaction.
 
void rollback ()
 Rolls back the current manual transaction.
 
template<typename Func>
void execute_in_transaction (Func operation, TransactionMode mode=TransactionMode::WRITABLE)
 Executes an operation inside an automatic transaction.
 

Protected Member Functions

MDBX_txn * thread_txn () const
 Returns the transaction bound to the current thread, if any.
 
MDBX_dbi handle () const
 Gets the raw DBI handle.
 

Protected Attributes

std::shared_ptr< Connectionm_connection
 Shared connection to MDBX environment.
 
MDBX_dbi m_dbi {}
 DBI handle for the opened table.
 

Detailed Description

Base class providing common functionality for MDBX database access.

Opens or creates a table (DBI handle) and offers basic transaction management. Not thread-safe for simultaneous operations on the same instance.

Definition at line 16 of file BaseTable.hpp.

Constructor & Destructor Documentation

◆ BaseTable()

mdbxc::BaseTable::BaseTable ( std::shared_ptr< Connection > connection,
std::string name,
MDBX_db_flags_t flags )
inlineexplicit

Construct the database table accessor.

Parameters
connectionShared MDBX connection.
nameName of the table (used as DBI name).
flagsDBI flags (e.g., MDBX_CREATE).

Definition at line 22 of file BaseTable.hpp.

◆ ~BaseTable()

virtual mdbxc::BaseTable::~BaseTable ( )
virtualdefault

Member Function Documentation

◆ begin()

void mdbxc::BaseTable::begin ( TransactionMode mode = TransactionMode::WRITABLE)
inline

Begins a manual transaction (must be committed or rolled back later).

Parameters
modeThe transaction mode (default: WRITABLE).
Exceptions
MdbxExceptionif the transaction is already started or if beginning fails.

Definition at line 54 of file BaseTable.hpp.

◆ commit()

void mdbxc::BaseTable::commit ( )
inline

Commits the current manual transaction.

Exceptions
MdbxExceptionif no transaction is active or commit/reset fails.

Definition at line 60 of file BaseTable.hpp.

◆ connect()

void mdbxc::BaseTable::connect ( )
inline

Connects to the MDBX environment if not already connected.

Definition at line 42 of file BaseTable.hpp.

◆ disconnect()

void mdbxc::BaseTable::disconnect ( )
inline

Disconnects the MDBX environment.

Definition at line 47 of file BaseTable.hpp.

◆ execute_in_transaction()

template<typename Func>
void mdbxc::BaseTable::execute_in_transaction ( Func operation,
TransactionMode mode = TransactionMode::WRITABLE )
inline

Executes an operation inside an automatic transaction.

Parameters
operationThe function to execute.
modeThe transaction mode (default: WRITABLE).
Exceptions
MdbxExceptionif an error occurs during execution.

Definition at line 75 of file BaseTable.hpp.

◆ handle()

MDBX_dbi mdbxc::BaseTable::handle ( ) const
inlineprotected

Gets the raw DBI handle.

Definition at line 99 of file BaseTable.hpp.

◆ is_connected()

bool mdbxc::BaseTable::is_connected ( ) const
inline

Checks if the connection is currently active.

Definition at line 37 of file BaseTable.hpp.

◆ rollback()

void mdbxc::BaseTable::rollback ( )
inline

Rolls back the current manual transaction.

Exceptions
MdbxExceptionif no transaction is active or rollback/reset fails.

Definition at line 66 of file BaseTable.hpp.

◆ thread_txn()

MDBX_txn * mdbxc::BaseTable::thread_txn ( ) const
inlineprotected

Returns the transaction bound to the current thread, if any.

Returns
Pointer to the MDBX transaction or nullptr.

Definition at line 94 of file BaseTable.hpp.

Member Data Documentation

◆ m_connection

std::shared_ptr<Connection> mdbxc::BaseTable::m_connection
protected

Shared connection to MDBX environment.

Definition at line 89 of file BaseTable.hpp.

◆ m_dbi

MDBX_dbi mdbxc::BaseTable::m_dbi {}
protected

DBI handle for the opened table.

Definition at line 90 of file BaseTable.hpp.


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