2#ifndef _MDBX_CONTAINERS_CONNECTION_HPP_INCLUDED
3#define _MDBX_CONTAINERS_CONNECTION_HPP_INCLUDED
30 static std::shared_ptr<Connection>
create(
const Config& config);
86# if __cplusplus >= 201703L
87 using config_t = std::optional<Config>;
98 void cleanup(
bool use_throw =
true);
107#ifdef MDBX_CONTAINERS_HEADER_ONLY
Parameters used by Connection to create the MDBX environment.
std::shared_ptr< Transaction > current_txn() const
Returns the transaction associated with the current thread.
bool is_connected() const
Checks whether the environment is currently open.
MDBX_env * m_env
Pointer to the MDBX environment handle.
Transaction transaction(TransactionMode mode=TransactionMode::WRITABLE)
Creates a RAII transaction object.
MDBX_env * env_handle() noexcept
Returns the environment handle.
void begin(TransactionMode mode=TransactionMode::WRITABLE)
Begins a manual transaction (must be committed or rolled back later).
void disconnect()
Disconnects from the MDBX environment and releases resources.
std::unique_ptr< Config > config_t
void db_init()
Initializes MDBX environment and opens a read-only transaction.
void rollback()
Rolls back the current manual transaction.
config_t m_config
Database configuration object.
Connection()=default
Default constructor.
void cleanup(bool use_throw=true)
Safely closes the environment and aborts transaction if needed.
void connect()
Connects to the database using the current configuration.
void configure(const Config &config)
Sets the MDBX configuration (must be called before connect()).
~Connection()
Destructor. Closes the MDBX environment and aborts any open transactions.
std::mutex m_mdbx_mutex
Mutex for thread-safe access.
void commit()
Commits the current manual transaction.
static std::shared_ptr< Connection > create(const Config &config)
Creates and connects a new shared Connection instance.
void initialize()
Initializes the environment and sets up read-only transaction.
std::unordered_map< std::thread::id, std::shared_ptr< Transaction > > m_transactions
Associates MDBX transactions with threads.
TransactionMode
Specifies the access mode of a transaction.
@ WRITABLE
Writable transaction (allows inserts, updates, deletes).