|
1 | 1 | #include <eosio/eosio.hpp>
|
| 2 | +#include <eosio/table.hpp> |
2 | 3 |
|
3 | 4 | // this structure defines the data stored in the kv::table
|
4 | 5 | struct person {
|
5 | 6 | eosio::name account_name;
|
6 |
| - eosio::non_unique<eosio::name, std::string> first_name; |
7 |
| - eosio::non_unique<eosio::name, std::string> last_name; |
8 |
| - eosio::non_unique<eosio::name, std::string, std::string, std::string, std::string> street_city_state_cntry; |
9 |
| - eosio::non_unique<eosio::name, std::string> personal_id; |
| 7 | + std::tuple<eosio::name, std::string> first_name; |
| 8 | + std::tuple<eosio::name, std::string> last_name; |
| 9 | + std::tuple<eosio::name, std::string, std::string, std::string, std::string> street_city_state_cntry; |
| 10 | + std::tuple<eosio::name, std::string> personal_id; |
10 | 11 | std::pair<std::string, std::string> country_personal_id;
|
11 | 12 |
|
12 | 13 | eosio::name get_account_name() const {
|
13 | 14 | return account_name;
|
14 | 15 | }
|
15 | 16 | std::string get_first_name() const {
|
16 |
| - // from the non_unique tuple we extract the value with key 1, the first name |
| 17 | + // from the tuple we extract the value with key 1, the first name |
17 | 18 | return std::get<1>(first_name);
|
18 | 19 | }
|
19 | 20 | std::string get_last_name() const {
|
20 |
| - // from the non_unique tuple we extract the value with key 1, the last name |
| 21 | + // from the tuple we extract the value with key 1, the last name |
21 | 22 | return std::get<1>(last_name);
|
22 | 23 | }
|
23 | 24 | std::string get_street() const {
|
24 |
| - // from the non_unique tuple we extract the value with key 1, the street |
| 25 | + // from the tuple we extract the value with key 1, the street |
25 | 26 | return std::get<1>(street_city_state_cntry);
|
26 | 27 | }
|
27 | 28 | std::string get_city() const {
|
28 |
| - // from the non_unique tuple we extract the value with key 2, the city |
| 29 | + // from the tuple we extract the value with key 2, the city |
29 | 30 | return std::get<2>(street_city_state_cntry);
|
30 | 31 | }
|
31 | 32 | std::string get_state() const {
|
32 |
| - // from the non_unique tuple we extract the value with key 3, the state |
| 33 | + // from the tuple we extract the value with key 3, the state |
33 | 34 | return std::get<3>(street_city_state_cntry);
|
34 | 35 | }
|
35 | 36 | std::string get_country() const {
|
36 |
| - // from the non_unique tuple we extract the value with key 4, the country |
| 37 | + // from the tuple we extract the value with key 4, the country |
37 | 38 | return std::get<4>(street_city_state_cntry);
|
38 | 39 | }
|
39 | 40 | std::string get_personal_id() const {
|
40 |
| - // from the non_unique tuple we extract the value with key 1, the personal id |
| 41 | + // from the tuple we extract the value with key 1, the personal id |
41 | 42 | return std::get<1>(personal_id);
|
42 | 43 | }
|
43 | 44 | };
|
@@ -86,13 +87,13 @@ class [[eosio::contract]] kv_addr_book : public eosio::contract {
|
86 | 87 | // index, and by providing as the first property one that has unique values
|
87 | 88 | // it ensures the uniques of the values combined (including non-unique ones)
|
88 | 89 | // 3. the rest of the properties are the ones wanted to be indexed non-uniquely
|
89 |
| - index<eosio::non_unique<eosio::name, std::string>> first_name_idx { |
| 90 | + index<std::tuple<eosio::name, std::string>> first_name_idx { |
90 | 91 | eosio::name{"firstname"_n},
|
91 | 92 | &person::first_name};
|
92 |
| - index<eosio::non_unique<eosio::name, std::string>> last_name_idx { |
| 93 | + index<std::tuple<eosio::name, std::string>> last_name_idx { |
93 | 94 | eosio::name{"lastname"_n},
|
94 | 95 | &person::last_name};
|
95 |
| - index<eosio::non_unique<eosio::name, std::string>> personal_id_idx { |
| 96 | + index<std::tuple<eosio::name, std::string>> personal_id_idx { |
96 | 97 | eosio::name{"persid"_n},
|
97 | 98 | &person::personal_id};
|
98 | 99 | // non-unique index defined using the KV_NAMED_INDEX macro
|
|
0 commit comments