benoitc / couchbeam

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

Multi document fetching in single call #25

Closed sendtopms closed 13 years ago

sendtopms commented 14 years ago

I am looking to use API which is described in the wiki http://wiki.apache.org/couchdb/HTTP_view_API under section "Querying Options" I want to use POST with keys "multiple keys" to retrive in single call. Is it available?

benoitc commented 14 years ago

Yes just provide just provide keys as param. (sent from iphone)

sendtopms commented 14 years ago

Can you elaborate? Is it part of couchbeam_db open_doc?

benoitc commented 14 years ago

No use views and pass keys as param.

sendtopms commented 14 years ago

Yea I figured out and thanks. I need to pass '_all_docs' as View Name. May be clear version (compare to one in Test case) for showing this example is here, Keys = [{"keys", [<<"item/2009/12/24/1261680528">>, <<"item/2009/12/24/1261680599">>]}], VResults5 = couchbeam_db:query_view(dbref, '_all_docs', Keys), VResults6 = couchbeam_view:fetch_view (VResults5),

Note: here dbref is the named reference to couchbeam process.

benoitc commented 14 years ago

sorry was only on iphone yesterday. For all docs you can also use :

Pid =couchbeam_db:all_docs(dbref, Keys)
Results = couchbeam_view:fetch_view (Pid).

But right doc need to be improved. Thanks

benoitc commented 13 years ago

Fixed in last head, couchbeam implements fold & foreach functions now. Ex:

Fun = fun(Row, AttIn) -> [Row|AttIn] end,
Att = couchbeam_view:fold(View, Fun),

Tid =  ets:new(couchbeam_test, [set, private]),
Fun1 = fun({Row}) -> 
    Key = proplists:get_value(<<"key">>, Row),
    true = ets:insert(Tid, {Key, Row})
end,
couchbeam_view:foreach(View, Fun1),

Thanks for the feedback :)