NuDB Logo

PrevUpHomeNext

basic_store::fetch

Fetch a value.

template<
    class Callback>
void
fetch(
    void const* key,
    Callback&& callback,
    error_code& ec);

The function checks the database for the specified key, and invokes the callback if it is found. If the key is not found, ec is set to error::key_not_found. If any other errors occur, ec is set to the corresponding error.

Requirements

The database must be open.

Thread safety

Safe to call concurrently with any function except close.

Remarks

If the implementation encounters an error while committing data to the database, this function will immediately return with ec set to the error which occurred. All subsequent calls to fetch will return the same error until the database is closed.

Parameters

key

A pointer to a memory buffer of at least key_size() bytes, containing the key to be searched for.

callback

A function which will be called with the value data if the fetch is successful. The equivalent signature must be:

void callback(
    void const* buffer, // A buffer holding the value
    std::size_t size    // The size of the value in bytes
);

The buffer provided to the callback remains valid until the callback returns, ownership is not transferred.

ec

Set to the error, if any occurred.


PrevUpHomeNext