多索引表 multi_index示例
Posted thefist11
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了多索引表 multi_index示例相关的知识,希望对你有一定的参考价值。
1. Template parameters
- TableName - name of the table
- T - type of the data stored inside the table
- Indices - secondary indices for the table, up to 16 indices is supported her
eosio::multi_index< TableName, T, Indices >::multi_index(
name code, //Account that owns table
uint64_t scope //Scope identifier within the code hierarchy
...
)
1.1 示例
eg.
#include <eosiolib/eosio.hpp>
using namespace eosio;
class mycontract: contract {
struct record {
uint64_t primary;
uint64_t secondary_1;
uint128_t secondary_2;
checksum256 secondary_3;
double secondary_4;
long double secondary_5;
uint64_t primary_key() const { return primary; }
uint64_t get_secondary_1() const { return secondary_1; }
uint128_t get_secondary_2() const { return secondary_2; }
checksum256 get_secondary_3() const { return secondary_3; }
double get_secondary_4() const { return secondary_4; }
long double get_secondary_5() const { return secondary_5; }
};
public:
mycontract(name receiver, name code, datastream<const char*> ds):contract(receiver, code, ds){}
void myaction() {
auto code = _self;
auto scope = _self;
multi_index<"mytable"_n, record,
indexed_by< "bysecondary1"_n, const_mem_fun<record, uint64_t, &record::get_secondary_1> >,
indexed_by< "bysecondary2"_n, const_mem_fun<record, uint128_t, &record::get_secondary_2> >,
indexed_by< "bysecondary3"_n, const_mem_fun<record, checksum256, &record::get_secondary_3> >,
indexed_by< "bysecondary4"_n, const_mem_fun<record, double, &record::get_secondary_4> >,
indexed_by< "bysecondary5"_n, const_mem_fun<record, long double, &record::get_secondary_5> >
> table( code, scope);
}
}
EOSIO_DISPATCH( mycontract, (myaction) )
以上是关于多索引表 multi_index示例的主要内容,如果未能解决你的问题,请参考以下文章