Skip to content

Commit

Permalink
doc_exists/2
Browse files Browse the repository at this point in the history
  • Loading branch information
loxs authored and benoitc committed Jan 9, 2011
1 parent eeb4a9c commit 2b0cbf4
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/couchbeam.erl
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
delete_db/1, delete_db/2,
db_info/1,
save_doc/2, save_doc/3,
doc_exists/2,
open_doc/2, open_doc/3,
delete_doc/2, delete_doc/3,
save_docs/2, save_docs/3, delete_docs/2, delete_docs/3,
Expand Down Expand Up @@ -361,6 +362,16 @@ db_info(#db{server=Server, name=DbName, options=IbrowseOpts}) ->
Error
end.

%% @doc test if doc with uuid exists in the given db
%% @spec doc_exists(db(), string()) -> boolean()
doc_exists(#db{server=Server, options=IbrowseOpts}=Db, DocId) ->
DocId1 = couchbeam_util:encode_docid(DocId),
Url = make_url(Server, doc_url(Db, DocId1), []),
case request(head, Url, ["200"], IbrowseOpts) of
{ok, _, _, _} -> true;
_Error -> false
end.

%% @doc open a document
%% @equiv open_doc(Db, DocId, [])
open_doc(Db, DocId) ->
Expand Down

0 comments on commit 2b0cbf4

Please sign in to comment.