<html><head></head><body bgcolor="#FFFFFF"><div>You can try something like this:</div><div><br></div><div>Key = term(),</div><div>Value =[{Key :: atom(), Value :: term()]</div><div><br></div><div>With this approach you can dynamically manage fields in your Value. Of course some extra business logic and helper functions are needed.</div>
<div><br></div><div><br><br>Sent from my iPhone</div><div><br>On 25.02.2012, at 6:37, Vinayak Pawar <<a href="mailto:vinayakapawar@gmail.com">vinayakapawar@gmail.com</a>> wrote:<br><br></div><div></div><blockquote type="cite">
<div><div>Hi,</div><div><br></div><div>I've a key-value store. The value part is a tuple stored using <font face="'courier new', monospace">term_to_binary()</font>.</div><div> </div><div><font face="'courier new', monospace"> -record(some_rec, {e1, e2}).</font></div>
<div><font face="'courier new', monospace"><br></font></div><div><font face="'courier new', monospace"> Rec = #some_rec{e1 = E1, e2 = E2}</font></div><div><font face="'courier new', monospace"> kv_store:put(Key, term_to_binary(Rec)).</font></div>
<div><br></div><div>I access the values in this key-value store as below:</div><div><br></div><div><font face="'courier new', monospace"> case kv_store:get(Key) of</font></div><div><font face="'courier new', monospace"> {ok, Bin} -></font></div>
<div><font face="'courier new', monospace"> #some_rec{} = Rec = binary_to_term(Bin),</font></div><div><font face="'courier new', monospace"> do_some_work(Rec);</font></div><div><font face="'courier new', monospace"><br>
</font></div><div><font face="'courier new', monospace"> false -></font></div><div><font face="'courier new', monospace"> do_something_else(Key)</font></div><div><font face="'courier new', monospace"> end.</font></div>
<div><br></div><div>Now there is change in my tuple structure. A new element/field is been added to it:</div><div><br></div><div><font face="'courier new', monospace"> -record(some_rec, {e1, e2, <font color="#ff0000">e3</font>}).</font></div>
<div><br></div><div>Henceforth tuples with this new structure will get stored in the KV store.</div><div><br></div><div>This means, everytime I change the tuple structure, I need to run through each key-value pair that has been stored using older tuple structure and update the value part to be in sync with new tuple structure?</div>
<div><br></div><div>This gives a hint that I'm doing something wrong in the way I store the values in schema-less KV store. Can you please help me figure out what is wrong?</div><div><br></div><div>Question: is it possible to store values in KV store so that I don't have to update the KV store whenever there is change in tuple structure? store values in JSON form?</div>
<div><br></div><div>Regards,</div><div>Vinayak</div>
</div></blockquote><blockquote type="cite"><div><span>_______________________________________________</span><br><span>erlang-questions mailing list</span><br><span><a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a></span><br>
<span><a href="http://erlang.org/mailman/listinfo/erlang-questions">http://erlang.org/mailman/listinfo/erlang-questions</a></span><br></div></blockquote></body></html>