Key Value Map

Constructor for the iterator type. More...

Classes

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

Functions

Detailed Description

Defines an EOSIO Key Value Table. Function to decrement the iterator to the next element (sorted in lexicographic order). Function to increment the iterator to the next element (sorted in lexicographic order). Function to advance the iterator to the element past the last element of the map's key value pairs. Function to advance the iterator to the beginning of the map's key value pairs. This will take a key_type key and find the value that exactly matches that key. This will take a key_type key and find the value that is strictly greater than that key. This will take a key_type key and find the value that is equal to or greater than that key. Utility function to see if the iterator is valid or is pointing at end or one past the last or first element.

Parameters:

  • owner This is the owner of the table object.

If no element is greater than or equal to the key the iterator will now hold end.

Parameters:

  • key This is the key which you wish to query with.

If no element is strictly greater than the key the iterator will now hold end.

Parameters:

  • key This is the key which you wish to query with.

If no element is equal to the key the iterator will now hold end.

Parameters:

  • key This is the key which you wish to query with.

Note this is the prefix operator, i.e. ++it, the it++ operator is explicitly missing because of performance issues. If you increment past the last element this iterator will then be invalid and point to end. Note this is the prefix operator, i.e. --it, the it-- operator is explicitly missing because of performance issues. If you decrement past the first element this iterator will then be invalid and point to end. EOSIO Key Value API provides a C++ interface to the EOSIO Key Value database. Key Value Tables require 1 primary index, of any type that can be serialized to a binary representation. Key Value Tables support 0 or more secondary index, of any type that can be serialized to a binary representation. Indexes must be a member variable or a member function.

Template parameters:

  • T - the type of the data stored as the value of the table

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.