![]() |
MDBX Containers
|
Table storing values of arbitrary type associated with a key. More...
#include <AnyValueTable.hpp>
Public Member Functions | |
| AnyValueTable (std::shared_ptr< Connection > conn, std::string name="any_store", MDBX_db_flags_t flags=MDBX_DB_DEFAULTS|MDBX_CREATE) | |
| Constructs table using existing connection. | |
| AnyValueTable (const Config &cfg, std::string name="any_store", MDBX_db_flags_t flags=MDBX_DB_DEFAULTS|MDBX_CREATE) | |
| Constructs table using configuration. | |
| ~AnyValueTable () override=default | |
| Destructor. | |
| template<class T> | |
| void | set (const KeyT &key, const T &value, MDBX_txn *txn=nullptr) |
| Set value for key, replacing existing value. | |
| template<class T> | |
| void | set (const KeyT &key, const T &value, const Transaction &txn) |
| Set value using external transaction. | |
| template<class T> | |
| bool | insert (const KeyT &key, const T &value, MDBX_txn *txn=nullptr) |
| Insert value if key does not exist. | |
| template<class T> | |
| bool | insert (const KeyT &key, const T &value, const Transaction &txn) |
| Insert value using external transaction. | |
| template<class T, class Fn> | |
| void | update (const KeyT &key, Fn &&fn, bool create_if_missing=false, MDBX_txn *txn=nullptr) |
| Update value using functor. | |
| template<class T, class Fn> | |
| void | update (const KeyT &key, Fn &&fn, bool create_if_missing, const Transaction &txn) |
| Update using external transaction. | |
| template<class T> | |
| T | get (const KeyT &key, MDBX_txn *txn=nullptr) const |
| Retrieve stored value or throw if missing. | |
| template<class T> | |
| T | get (const KeyT &key, const Transaction &txn) const |
| Retrieve using external transaction. | |
| template<class T> | |
| std::pair< bool, T > | find_compat (const KeyT &key, MDBX_txn *txn=nullptr) const |
| Find value by key. | |
| template<class T> | |
| std::pair< bool, T > | find_compat (const KeyT &key, const Transaction &txn) const |
| Find value by key using external transaction (C++11 mode). | |
| template<class T> | |
| T | get_or (const KeyT &key, T default_value, MDBX_txn *txn=nullptr) const |
| Get value or default if missing (C++11 mode). | |
| template<class T> | |
| T | get_or (const KeyT &key, T default_value, const Transaction &txn) const |
| Get value or default using external transaction (C++11 mode). | |
| template<class KT = KeyT> | |
| bool | contains (const KT &key, MDBX_txn *txn=nullptr) const |
| Check if key exists. | |
| bool | contains (const KeyT &key, const Transaction &txn) const |
| Check key existence using external transaction. | |
| bool | erase (const KeyT &key, MDBX_txn *txn=nullptr) |
| Erase key from table. | |
| bool | erase (const KeyT &key, const Transaction &txn) |
| Erase using external transaction. | |
| std::vector< KeyT > | keys (MDBX_txn *txn=nullptr) const |
| List all keys stored in table. | |
| std::vector< KeyT > | keys (const Transaction &txn) const |
| List keys using external transaction. | |
| void | set_type_tag_check (bool enabled) noexcept |
| Enable or disable type-tag checking. | |
Public Member Functions inherited from mdbxc::BaseTable | |
| 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. | |
Private Member Functions | |
| template<typename F> | |
| void | with_transaction (F &&action, TransactionMode mode, MDBX_txn *txn) const |
| template<class T> | |
| bool | put_typed (const KeyT &key, const T &value, bool upsert, MDBX_txn *txn) |
| template<class T> | |
| bool | get_typed (const KeyT &key, T &out, MDBX_txn *txn) const |
| bool | db_contains (const KeyT &key, MDBX_txn *txn) const |
| bool | db_erase (const KeyT &key, MDBX_txn *txn) |
| void | db_list_keys (std::vector< KeyT > &out, MDBX_txn *txn) const |
| template<class T> | |
| MDBX_val | wrap_with_type_tag (const MDBX_val &raw) const |
| template<class T> | |
| MDBX_val | unwrap_and_check_type_tag (const MDBX_val &raw) const |
Private Attributes | |
| bool | m_check_type_tag = false |
| Flag enabling type-tag verification. | |
Additional Inherited Members | |
Protected Member Functions inherited from mdbxc::BaseTable | |
| 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 inherited from mdbxc::BaseTable | |
| std::shared_ptr< Connection > | m_connection |
| Shared connection to MDBX environment. | |
| MDBX_dbi | m_dbi {} |
| DBI handle for the opened table. | |
Table storing values of arbitrary type associated with a key.
| KeyT | Type of the key used to access values. |
Definition at line 17 of file AnyValueTable.hpp.
|
inline |
Constructs table using existing connection.
| conn | Shared connection to the environment. |
| name | Name of the table. |
| flags | Additional MDBX flags. |
Definition at line 23 of file AnyValueTable.hpp.
|
inlineexplicit |
Constructs table using configuration.
| cfg | Configuration settings. |
| name | Name of the table. |
| flags | Additional MDBX flags. |
Definition at line 32 of file AnyValueTable.hpp.
|
overridedefault |
Destructor.
|
inline |
Check key existence using external transaction.
| key | Key to check. |
| txn | Active transaction wrapper. |
true if key is present, otherwise false. Definition at line 254 of file AnyValueTable.hpp.
|
inline |
Check if key exists.
| KT | Key type (defaults to KeyT). |
| key | Key to check. |
| txn | Optional transaction handle. |
true if key is present, otherwise false. Definition at line 244 of file AnyValueTable.hpp.
|
inlineprivate |
Definition at line 349 of file AnyValueTable.hpp.
|
inlineprivate |
Definition at line 359 of file AnyValueTable.hpp.
|
inlineprivate |
Definition at line 369 of file AnyValueTable.hpp.
|
inline |
Erase using external transaction.
| key | Key to remove. |
| txn | Active transaction wrapper. |
true if key was removed, otherwise false. Definition at line 272 of file AnyValueTable.hpp.
|
inline |
Erase key from table.
| key | Key to remove. |
| txn | Optional transaction handle. |
true if key was removed, otherwise false. Definition at line 262 of file AnyValueTable.hpp.
|
inline |
Find value by key using external transaction (C++11 mode).
| T | Expected value type. |
| key | Key to search for. |
| txn | Active transaction wrapper. |
Definition at line 205 of file AnyValueTable.hpp.
|
inline |
Find value by key.
Find value by key returning C++11-compatible result.
| T | Expected value type. |
| key | Key to search for. |
| txn | Optional transaction handle. |
Definition at line 185 of file AnyValueTable.hpp.
|
inline |
Retrieve using external transaction.
Definition at line 127 of file AnyValueTable.hpp.
|
inline |
Retrieve stored value or throw if missing.
| key | Key to look up. |
| txn | Optional transaction handle. |
| std::out_of_range | if key not found. |
| std::bad_cast | if type tag check fails. |
Definition at line 113 of file AnyValueTable.hpp.
|
inline |
Get value or default using external transaction (C++11 mode).
| T | Expected value type. |
| key | Key to look up. |
| default_value | Value returned when key not found. |
| txn | Active transaction wrapper. |
default_value when the key is absent. Definition at line 231 of file AnyValueTable.hpp.
|
inline |
Get value or default if missing (C++11 mode).
| T | Expected value type. |
| key | Key to look up. |
| default_value | Value returned when key not found. |
| txn | Optional transaction handle. |
default_value when the key is absent. Definition at line 216 of file AnyValueTable.hpp.
|
inlineprivate |
Definition at line 337 of file AnyValueTable.hpp.
|
inline |
Insert value using external transaction.
Definition at line 73 of file AnyValueTable.hpp.
|
inline |
Insert value if key does not exist.
Definition at line 63 of file AnyValueTable.hpp.
|
inline |
List keys using external transaction.
| txn | Active transaction wrapper. |
Definition at line 288 of file AnyValueTable.hpp.
|
inline |
List all keys stored in table.
| txn | Optional transaction handle. |
Definition at line 279 of file AnyValueTable.hpp.
|
inlineprivate |
Definition at line 321 of file AnyValueTable.hpp.
|
inline |
Set value using external transaction.
Definition at line 56 of file AnyValueTable.hpp.
|
inline |
Set value for key, replacing existing value.
| T | Type of value. |
| key | Key to update. |
| value | Value to store. |
| txn | Optional transaction handle. |
Definition at line 48 of file AnyValueTable.hpp.
|
inlinenoexcept |
Enable or disable type-tag checking.
| enabled | Enables check when set to true. |
Definition at line 294 of file AnyValueTable.hpp.
|
inlineprivate |
Definition at line 386 of file AnyValueTable.hpp.
|
inline |
Update using external transaction.
Definition at line 101 of file AnyValueTable.hpp.
|
inline |
Update value using functor.
| T | Expected type of stored value. |
| Fn | Functor accepting reference to value. |
| key | Key to modify. |
| fn | Function applied to the value. |
| create_if_missing | Create default value if key is absent. |
| txn | Optional transaction handle. |
Definition at line 85 of file AnyValueTable.hpp.
|
inlineprivate |
Definition at line 300 of file AnyValueTable.hpp.
|
inlineprivate |
Definition at line 380 of file AnyValueTable.hpp.
|
private |
Flag enabling type-tag verification.
Definition at line 297 of file AnyValueTable.hpp.