Module couchdb_documents


The couchdb_documents module contains functionality listed under CouchDB API Reference section 1.4.1.

Description

The couchdb_documents module contains functionality listed under CouchDB API Reference section 1.4.1.

Documents are CouchDB’s central data structure. The idea behind a document is, unsurprisingly, that of a real-world document – a sheet of paper such as an invoice, a recipe, or a business card. We already learned that CouchDB uses the JSON format to store documents.

Function Index

delete/2Deletes a list of documents if you want to make sure the doc it emptied on delete, use the option {empty_on_delete, true} or pass a doc with just _id and _rev members.
delete/3Deletes a list of documents if you want to make sure the doc it emptied on delete, use the option {empty_on_delete, true} or pass a doc with just _id and _rev members.
exists/2test if doc with uuid exists in the given db.
get/2Get a document.
get/3Get a document Params is a list of query arguments.See CouchDB API Reference 1.4.1.
lookup_rev/2get the last revision of the document.
lookup_rev/3
save/2save a document.
save/3save a *document A document is a Json object like this one:.
save/4save a *document with all its attacjments A document is a Json object like this one:.

Function Details

delete/2

delete(Db, Document) -> any()

Deletes a list of documents if you want to make sure the doc it emptied on delete, use the option {empty_on_delete, true} or pass a doc with just _id and _rev members.

delete/3

delete(Db::db(), Document::map() | list(), Options::list()) -> {ok, _Result} | {error, _Error}

Deletes a list of documents if you want to make sure the doc it emptied on delete, use the option {empty_on_delete, true} or pass a doc with just _id and _rev members.

exists/2

exists(Db::db(), DocId::binary()) -> boolean()

test if doc with uuid exists in the given db

get/2

get(Db, DocId) -> any()

Equivalent to open_doc(Db, DocId, []).

Get a document

get/3

get(Db::db(), DocId::binary(), Params::list()) -> {ok, map()} | {error, term()}

Get a document Params is a list of query arguments.See CouchDB API Reference 1.4.1

Note: The attachment option is still here but should be considered not supported as use of the couchdb_attachments module is favoured.

lookup_rev/2

lookup_rev(Db, DocId) -> any()

get the last revision of the document

lookup_rev/3

lookup_rev(Db, DocId, Params) -> any()

save/2

save(Db, Doc) -> any()

Equivalent to save(Db, Doc, []).

save a document

save/3

save(Db::db(), Doc, Options::list()) -> {ok, Doc1} | {error, Error}

save a *document A document is a Json object like this one:

          {[
           {<<"_id">>, <<"myid">>},
           {<<"title">>, <<"test">>}
       ]}
Options are arguments passed to the request. This function return a new document with last revision and a docid. If _id isn't specified in document it will be created. Id is created by extracting an uuid from the couchdb node.

save/4

save(Db::db(), Doc::doc(), Atts::mp_attachments(), Options::list()) -> {ok, doc()} | {error, term()}

save a *document with all its attacjments A document is a Json object like this one:

          {[
           {<<"_id">>, <<"myid">>},
           {<<"title">>, <<"test">>}
       ]}

Options are arguments passed to the request. This function return a new document with last revision and a docid. If _id isn't specified in document it will be created. Id is created by extracting an uuid from the couchdb node.

If the attachments is not empty, the doc will be sent as multipart. Attachments are passed as a list of the following tuples:

- {Name :: binary(), Bin :: binary()} - {Name :: binary(), Bin :: binary(), Encoding :: binary()} - { Name :: binary(), Bin :: binary(), Type :: binary(), Encoding :: binary()} - { Name :: binary(), {file, Path :: string()}} - { Name :: binary(), {file, Path :: string()}, Encoding :: binary()} - { Name :: binary(), Fun :: fun(), Length :: integer()} - { Name :: binary(), Fun :: fun(), Length :: integer(), Encoding :: binary()} - {Name :: binary(), Fun :: fun(), Length :: integer(), Type :: binary(), Encoding :: binary()} - { Name :: binary(), {Fun :: fun(), Acc :: any()}, Length :: integer()} - { Name :: binary(), {Fun :: fun(), Acc :: any()}, Length :: integer(), Encoding :: binary()} - { Name :: binary(), {Fun :: fun(), Acc :: any()}, Length :: integer(), Type :: binary(), Encoding :: binary()}.

where Type` is the content-type of the attachments (detected in other case) and `Encoding` the encoding of the attachments: `<<"identity">> if normal or <<"gzip">> if the attachments is gzipped.


erlang logo

Made with EDoc-S