Is there a way to query table with the value of a particular data field (for example, a token value) when using 'get_table rpc'? Only users whose token value is greater than 30 are output.
2 Answers
You can use get_table_rows
with index_position
, key_type
, and encode_type
options or use get_table_by_scope
with other options like lower_bound
, upper_bound
, limit
, and reverse
I will leave links to those API and one to cleos get table which uses the same API and should help you get a grasp of their usage.
-
Thank you for your reply. But are there any examples that are clearly visible?– TabyCommented Feb 26, 2019 at 7:57
No, you can't. You can make a query with a value only when its index exists. For example, if you want to find token balance larger than some amount, its multi_index would be like this:
struct [[eosio::table]] accounts {
name owner; // eosio.token doesn't have this field, because owner is scope
asset balance;
uint64_t primary_key() const { return owner.value; }
uint64_t by_balance() const { return static_cast<uint64_t>(balance.amount); }
};
typedef eosio::multi_index<"accounts"_n, accounts,
indexed_by<"balance"_n, const_mem_fun<accounts, uint64_t, &accounts::by_balance>>
> accounts_index;