On 25 February 2012 02:37, Vinayak Pawar <span dir="ltr"><<a href="mailto:vinayakapawar@gmail.com">vinayakapawar@gmail.com</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<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>
</blockquote><div><br>Yes, if you want to use a record for the value part, this is unavoidable.<br> <br></div><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<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></blockquote><div><br>Nothing is wrong really.<br> <br>
</div><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><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? </div>
</blockquote><div><br>No.<br> <br></div><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div>store values in JSON form?</div></blockquote><div><br>
Yes, or a simple list of {tag, value} tuples.<br>
<br>cheers<br>Chandru<br><br></div></div>