eos icon indicating copy to clipboard operation
eos copied to clipboard

How to get single record from table.

Open 26rahulsingh opened this issue 8 years ago • 2 comments

Can anyone help me, I'm trying to get single row (record) from table but get_table_rows api return all the record. how can I get single record based on some condition match from table.

-l will limit the record but my requirement is to get a single record from table based on condition match. for example - tableData = { rows: [{'age': 20, 'name': 'rahul''}, {'age': 18, 'name': 'prachi'}, {'age': 22, 'name': 'ram'}] }; from this table how can i get only "prachi" row record. Can anyone please elaborate.

26rahulsingh avatar Nov 22 '18 09:11 26rahulsingh

Set limit to 1

jafri avatar Nov 25 '18 18:11 jafri

Since multi_index tables may not have string indexes, you will need to provide another field on which to search. One possible secondary index type is ripemd160. You may store the ripemd160 hash of your 'name' field as a secondary index and use that value as an argument to --lower-bound and --upper-bound. Together with the --index and --key-type arguments, you can find what you are searching for using get_table_rows.

jgiszczak avatar Dec 20 '18 21:12 jgiszczak