zoukankan      html  css  js  c++  java
  • Secondary Indices

    Secondary Indices

      EOSIO has the ability to sort tables by up to 16 indices.  A table's struct cannot be modified when it has data in it.

    1、添加第二列索引 member 和 getter。

      The secondary index needs to be numeric field, so a uint64_t was chosen for the age variable

      

    2、Add secondary index to `addresses` table configuration

    typedef eosio::multi_index<"people"_n, person, 
    indexed_by<"byage"_n, const_mem_fun<person, uint64_t, &person::get_secondary_1>>
      > address_index;

      1) indexed_by 是一个 struct.

      2) first parameter set name of index as "byage"

      3) the second type parameter as a function call operator should extract a const value as an index key.

    3、compile & deploy

    eosio-cpp -o addressbook.wasm addressbook.cpp --abigen
    
    cleos set contract addressbook /home/ubuntu/contracts/addressbook

    4、Test

    cleos push action addressbook upsert '["alice", "alice", "liddell", 9, "123 drink me way", "wonderland", "amsterdam"]' -p alice@active
    
    cleos push action addressbook upsert '["bob", "bob", "is a guy", 49, "doesnt exist", "somewhere", "someplace"]' -p bob@active

      查看一下插入结果,注意--upper 10 是指定上限,即只查看索引值小于10的row.

    cleos get table addressbook addressbook people --upper 10 
    --key-type i64 
    --index 2

      上面命令会看到结果 

      

    参考:https://developers.eos.io/eosio-home/docs/secondary-indices

  • 相关阅读:
    寿司点餐系统Sprint1总结
    寿司点餐系统一周总结
    对点餐APP现阶段开发的问题
    寿司点餐系统11.16
    Sprint
    R扩展包
    实验8 SQLite数据库操作
    实验7 BindService模拟通信
    实验6 在应用程序中播放音频和视频
    实验5 数独游戏界面设计
  • 原文地址:https://www.cnblogs.com/tekkaman/p/10006482.html
Copyright © 2011-2022 走看看