Skip to content
This repository was archived by the owner on Aug 2, 2022. It is now read-only.

Commit 30200a3

Browse files
authored
Merge pull request #1004 from EOSIO/update_kv_examples
updted kv examples
2 parents dc745b6 + 4050ba6 commit 30200a3

File tree

3 files changed

+21
-18
lines changed

3 files changed

+21
-18
lines changed

examples/kv_addr_book/include/kv_addr_book.hpp

+15-14
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,44 @@
11
#include <eosio/eosio.hpp>
2+
#include <eosio/table.hpp>
23

34
// this structure defines the data stored in the kv::table
45
struct person {
56
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;
1011
std::pair<std::string, std::string> country_personal_id;
1112

1213
eosio::name get_account_name() const {
1314
return account_name;
1415
}
1516
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
1718
return std::get<1>(first_name);
1819
}
1920
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
2122
return std::get<1>(last_name);
2223
}
2324
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
2526
return std::get<1>(street_city_state_cntry);
2627
}
2728
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
2930
return std::get<2>(street_city_state_cntry);
3031
}
3132
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
3334
return std::get<3>(street_city_state_cntry);
3435
}
3536
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
3738
return std::get<4>(street_city_state_cntry);
3839
}
3940
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
4142
return std::get<1>(personal_id);
4243
}
4344
};
@@ -86,13 +87,13 @@ class [[eosio::contract]] kv_addr_book : public eosio::contract {
8687
// index, and by providing as the first property one that has unique values
8788
// it ensures the uniques of the values combined (including non-unique ones)
8889
// 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 {
9091
eosio::name{"firstname"_n},
9192
&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 {
9394
eosio::name{"lastname"_n},
9495
&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 {
9697
eosio::name{"persid"_n},
9798
&person::personal_id};
9899
// non-unique index defined using the KV_NAMED_INDEX macro

examples/kv_table_tests/src/kvtest.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include <eosio/eosio.hpp>
22
#include <eosio/asset.hpp>
3+
#include <eosio/table.hpp>
34

45
extern "C" __attribute__((eosio_wasm_import)) void set_kv_parameters_packed(const void* params, uint32_t size);
56

examples/kv_todo/include/kv_todo.hpp

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
#include <eosio/eosio.hpp>
22
#include <eosio/system.hpp>
3+
#include <eosio/table.hpp>
34
using namespace eosio;
45

56
struct todo_entry {
67
std::string uuid;
7-
eosio::non_unique<eosio::name, std::string> account_name;
8-
eosio::non_unique<std::string, std::string> task;
9-
eosio::non_unique<bool, std::string> checked;
10-
eosio::non_unique<uint32_t, std::string> created;
8+
std::tuple<eosio::name, std::string> account_name;
9+
std::tuple<std::string, std::string> task;
10+
std::tuple<bool, std::string> checked;
11+
std::tuple<uint32_t, std::string> created;
1112

1213
std::string get_uuid() const { return uuid; }
1314
eosio::name get_account_name() const { return std::get<0>(account_name); }

0 commit comments

Comments
 (0)