1
votes

How would one create a simple Riak CRDT Map containing a Register name username and value test? I am looking at this documentation here but don't understand how XPath and name of the register in a map are connected.

Here is what I will like to do: create/update a Map with Register name username and value test (under bucket type mapbucket, bucket uinfo, key test1). Here is how Erlang client will do that (not tested - modified copy-paste from another code I wrote):

  Map = riakc_map:new(),
  Map1 = riakc_map:update({<<"username">>, register},
                         fun(R) -> riakc_register:set(<<"test">>, R) end,
                         Map),
  {ok, Pid} = riakc_pb_socket:start_link("127.0.0.1", 8087),
  riakc_pb_socket:update_type(Pid,{<<"mapbucket">>,<<"uinfo">>},"test1",riakc_map:to_op(Map1))

I searched github code repository, but couldn't find any example of doing it in Haskell Riak client. I will very much appreciate it if any one with familiarity with Haskell Riak client, and CRDT ops could provide pointers on how to do something like above.

1

1 Answers

1
votes

I figured out how to do this. xpath in Map seems to be a recursive selector to access fields deeply buried in another map within map. So, for top-level field within a map, xpath will be just that fieldname. Thus, the solution becomes:

-- get the connection to 127.0.0.1:8087
conn <- connect defaultClient 

-- xpath here is just "username" fieldname - we use RegisterSet operation
-- Alternatively, for xpath value, you can do: ("username" :| []), especially, if
-- passing it as argument in a function
let op = "username" `mapUpdate` RegisterSet "test" 


-- send off the above operation to create/update the map
sendModify conn "mapbucket" "uinfo" "test1" [op]