eos icon indicating copy to clipboard operation
eos copied to clipboard

Requesting support for string type primary key for DB

Open ZeroPointThree17 opened this issue 8 years ago • 2 comments

The following code gives an error because the DB does not support a string primary key:

#include <eosiolib/eosio.hpp>
#include <eosiolib/print.hpp>

using namespace eosio;
using namespace std;

class testc : contract {
    using contract::contract;

private:
    // @abi table
    struct user_type {
        string email_encrypted;
        string password_hashed;
        string isConfirmed;

        string primary_key(){ return email_encrypted; }
        EOSLIB_SERIALIZE( user_type, (email_encrypted)(password_hashed)(isConfirmed) )
    };

    typedef multi_index<N(user_table), user_type> user_table;

public:
    testc( account_name self ) : contract(self){}

    void add_update_user( string user ){

        require_auth(N(appaccount));
        user_table utable(_self,_self);
        utable.get(user);

   }
};

EOSIO_ABI( testc, (add_update_user) )

Error returned when compiled is:

testc.cpp:30:20: error: no viable conversion from 'string' (aka
      'basic_string<char, char_traits<char>, allocator<char> >') to 'uint64_t'
      (aka 'unsigned long long')
        utable.get(user);
                   ^~~~

... can support for string type primary key for DB be implemented? I suspect a lot of dapps may find this useful as it is a functionality that would fit for many use cases.

ZeroPointThree17 avatar Apr 15 '18 06:04 ZeroPointThree17

did you fix it ? i have the same issue

hama avatar Aug 01 '18 08:08 hama

string primary key is currently not supported. There are plans to add it in the future.

heifner avatar Aug 01 '18 13:08 heifner