Key Value Table

Classes

Type Name
class eosio::kv::table::index
Defines an index on an EOSIO Key Value Table.
class eosio::kv::table
Defines an EOSIO Key Value Table.

Functions

Defines

Functions Documentation

function value

void eosio::kv::internal::iterator_base::value(
    void * val,
    void(*)(void *, const void *, std::size_t) deserialize
) const

Returns the value that the iterator points to.

Returns:

The value that the iterator points to.

function value

T eosio::kv::table< T, TableName >::base_iterator::value() const

Returns the value that the iterator points to.

Returns:

The value that the iterator points to.

function find

iterator eosio::kv::table< T, TableName >::index< K >::find(
    const K & key
) const

Search for an existing object in a table by the index, using the given key.

Parameters:

  • key - The key to search for.

Returns:

An iterator to the found object OR the end iterator if the given key was not found.

function exists

bool eosio::kv::table< T, TableName >::index< K >::exists(
    const K & key
) const

Check if a given key exists in the index.

Parameters:

  • key - The key to check for.

Returns:

If the key exists or not.

function operator[]

T eosio::kv::table< T, TableName >::index< K >::operator[](
    const K & key
) const

Get the value for an existing object in a table by the index, using the given key.

Parameters:

  • key - The key to search for.

Returns:

The value corresponding to the key.

function get

std::optional<T> eosio::kv::table< T, TableName >::index< K >::get(
    const K & key
) const

Get the value for an existing object in a table by the index, using the given key.

Parameters:

  • key - The key to search for.

Returns:

A std::optional of the value corresponding to the key.

function begin

iterator eosio::kv::table< T, TableName >::index< K >::begin() const

Returns an iterator to the object with the lowest key (by this index) in the table.

Returns:

An iterator to the object with the lowest key (by this index) in the table.

function end

iterator eosio::kv::table< T, TableName >::index< K >::end() const

Returns an iterator pointing past the end. It does not point to any element, therefore value should not be called on it.

Returns:

An iterator pointing past the end.

function rbegin

reverse_iterator eosio::kv::table< T, TableName >::index< K >::rbegin() const

Returns a reverse iterator to the object with the highest key (by this index) in the table.

Returns:

A reverse iterator to the object with the highest key (by this index) in the table.

function rend

reverse_iterator eosio::kv::table< T, TableName >::index< K >::rend() const

Returns a reverse iterator pointing past the beginning. It does not point to any element, therefore value should not be called on it.

Returns:

A reverse iterator pointing past the beginning.

function lower_bound

iterator eosio::kv::table< T, TableName >::index< K >::lower_bound(
    const K & key
) const

Returns an iterator pointing to the element with the lowest key greater than or equal to the given key.

Returns:

An iterator pointing to the element with the lowest key greater than or equal to the given key.

function upper_bound

iterator eosio::kv::table< T, TableName >::index< K >::upper_bound(
    const K & key
) const

Returns an iterator pointing to the first element greater than the given key.

Returns:

An iterator pointing to the first element greater than the given key.

function range

std::vector<T> eosio::kv::table< T, TableName >::index< K >::range(
    const K & b,
    const K & e
) const

Returns a vector of objects that fall between the specifed range. The range is inclusive, exclusive.

Parameters:

  • begin - The beginning of the range (inclusive).
  • end - The end of the range (exclusive).

Returns:

A vector containing all the objects that fall between the range.

function put

void eosio::kv::table< T, TableName >::put(
    const T & value,
    eosio::name payer
)

Puts a value into the table. If the value already exists, it updates the existing entry. The key is determined from the defined primary index. If the put attempts to store over an existing secondary index, the transaction will be aborted.

Parameters:

  • value - The entry to be stored in the table.
  • payer - The payer for the entry.

function erase

void eosio::kv::table< T, TableName >::erase(
    const T & value
)

Removes a value from the table.

Parameters:

  • key - The key of the value to be removed.

Defines Documentation

define KV_NAMED_INDEX

#define KV_NAMED_INDEX(index_name, member_name) index<EOSIO_CDT_GET_RETURN_T(value_type, member_name)> member_name{eosio::name{index_name}, &value_type::member_name};

Macro to define an index.

This macro allows users to conveniently define an index without having to specify the index template type, as those can be large/unwieldy to type out. It can be used for both primary and secondary indexes.

Parameters:

  • index_name - The index name.
  • member_name - The name of the member pointer used for the index. This also defines the index's C++ variable name.