Persistence API
I already read https://github.com/EOSIO/eos/wiki/Persistence-API.
Now I want to get a record from table and show data by another key different primary key in my web app. Example in table
struct service_rec {
uint64_t pkey; // opaque, will use available_primary_key()
account_name customer; // will create a secondary index on this
uint32_t service_date;
uint32_t odometer;
auto primary_key()const { return pkey; }
account_name get_customer()const { return customer; }
EOSLIB_SERIALIZE( service_rec, (pkey)(customer)(service_date)(odometer) )
};
I want to query by customer and get results to show on my web app. (Now with primary key I can use command cleos get table)
How can I do that ? 🙇
This snipet from the document describes how to use the secondary index.

To query to get a customer using cleos, you need a contract action that takes the customer name as input, and returns the customer record as output. The persistence document focused solely on using the multi-index API, and did not try to cover the requisite actions. You will need to write your own in order to get this to really work and access with cleos. Take a look at the tic_tac_toe example for ways to pass your parameters to your actions.
@rbw3821 I got it. I have written and read many smart contracts. I know how to pass your parameters to my actions but I do not see an example and document about action can return the customer record as output. Can we do that ? 🙇
I dug into this a bit deeper today and it turns out it will not be as direct as I had thought it would be... not yet, anyway. cleos needs to be updated to use the new indexing capabilities. That hasn't happened yet. You can print output from your contract (e.g., see the hello world contract tutorial) and capture it. I'm not sure how much direct external interaction from the WASM code is too much. Another alternative is via a plugin that mirrors the EOSIO database to an external database. I believe the mongo_db_plugin does some of this for test purposes. I'll need to dig into this further to understand what is currently being done.
@rbw3821 I got it. Thank you very much. I will also try to do it 😊