benoitc / couchbeam

Apache CouchDB client in Erlang
Other
242 stars 114 forks source link

add the couchbeam:set_values/2 function. #111

Closed matrixise closed 10 years ago

matrixise commented 10 years ago

With this function, instead of using several times the same function to add some fields to a document, we can use set_values.

Instead of using couchbeam_doc:set_value/3

Doc = {[{<<"content">>, <<"this is a funny doc">>}]}.
Doc1 = couchbeam_doc:set_value(<<"active">>, true, Doc).
Doc2 = couchbeam_doc:set_value(<<"type">>, <<"user">>, Doc1).

You can use couchbeam_doc:set_values/2 Example:

1> Doc = {[{<<"content">>, <<"this is a funny doc">>}]}.
{[{<<"content">>,<<"this is a funny doc">>}]}
2> couchbeam_doc:set_values([{<<"active">>, true}], Doc).
{[{<<"content">>,<<"this is a funny doc">>},{<<"active">>,true}]}
3> couchbeam_doc:set_values([{<<"active">>, true}], Doc).
{[{<<"content">>,<<"this is a funny doc">>},{<<"active">>,true}]}
4> couchbeam_doc:set_values([{<<"active">>, true}, {<<"type">>, <<"user">>}], Doc).
{[{<<"content">>,<<"this is a funny doc">>},
  {<<"active">>,true},
  {<<"type">>,<<"user">>}]}
matrixise commented 10 years ago

Sorry I didn't see that we can use couchbeam_doc:extend