Skip to content

Latest commit

 

History

History
783 lines (470 loc) · 25 KB

couchbeam.md

File metadata and controls

783 lines (470 loc) · 25 KB

Module couchbeam

Data Types

abstract datatype: doc_stream()


mp_attachments() = {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::function(), Length::integer()} | {Name::binary(), Fun::function(), Length::integer(), Encoding::binary()} | {Name::binary(), Fun::function(), Length::integer(), Type::binary(), Encoding::binary()} | {Name::binary(), {Fun::function(), Acc::any()}, Length::integer()} | {Name::binary(), {Fun::function(), Acc::any()}, Length::integer(), Encoding::binary()} | {Name::binary(), {Fun::function(), Acc::any()}, Length::integer(), Type::binary(), Encoding::binary()}

Function Index

all_dbs/1get list of databases on a CouchDB node.
all_dbs/2get list of databases on a CouchDB node with optional filter.
compact/1Compaction compresses the database file by removing unused sections created during updates.
compact/2Like compact/1 but this compacts the view index from the current version of the design document.
copy_doc/2duplicate a document using the doc API.
copy_doc/3copy a doc to a destination.
create_db/2Create a database and a client for connectiong to it.
create_db/3Create a database and a client for connectiong to it.
create_db/4Create a database and a client for connectiong to it.
db_exists/2test if db with dbname exists on the CouchDB node.
db_info/1get database info.
delete_attachment/3delete a document attachment.
delete_attachment/4delete a document attachment.
delete_db/1delete database.
delete_db/2delete database.
delete_doc/2delete a document.
delete_doc/3delete a document 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_docs/2delete a list of documents.
delete_docs/3delete 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.
design_info/2
doc_exists/2test if doc with uuid exists in the given db.
end_doc_stream/1stop to receive the multipart response of the doc api and close the connection.
ensure_full_commit/1commit all docs in memory.
ensure_full_commit/2commit all docs in memory.
fetch_attachment/3fetch a document attachment.
fetch_attachment/4fetch a document attachment Options are
  • stream: to start streaming an attachment. the function return {ok, Ref} where is a ref to the attachment
  • Other options that can be sent using the REST API
.
get_missing_revs/2get missing revisions.
get_uuid/1Get one uuid from the server.
get_uuids/2Get a list of uuids from the server.
lookup_doc_rev/2get the last revision of the document.
lookup_doc_rev/3
open_db/2Create a client for connection to a database.
open_db/3Create a client for connection to a database.
open_doc/2open a document.
open_doc/3open a document Params is a list of query argument.
open_or_create_db/2Create a client for connecting to a database and create the database if needed.
open_or_create_db/3Create a client for connecting to a database and create the database if needed.
open_or_create_db/4Create a client for connecting to a database and create the database if needed.
put_attachment/4put an attachment.
put_attachment/5put an attachment.
replicate/2Handle replication.
replicate/3Handle replication.
replicate/4handle Replication.
save_doc/2save a document.
save_doc/3save a *document A document is a Json object like this one:.
save_doc/4save a *document with all its attacjments A document is a Json object like this one:.
save_docs/2save a list of documents.
save_docs/3save a list of documents.
send_attachment/2send an attachment chunk Msg could be Data, eof to stop sending.
server_connection/0Create a server for connectiong to a CouchDB node.
server_connection/1
server_connection/2Create a server for connectiong to a CouchDB node.
server_connection/4Create a server for connectiong to a CouchDB node.
server_info/1Get Information from the server.
stream_attachment/1fetch an attachment chunk.
stream_doc/1stream the multipart response of the doc API.
view_cleanup/1

Function Details

all_dbs/1


all_dbs(Server::server()) -> {ok, iolist()}

get list of databases on a CouchDB node

all_dbs/2


all_dbs(Server::server(), Options::view_options()) -> {ok, iolist()}

get list of databases on a CouchDB node with optional filter

compact/1


compact(Db::db()) -> ok | {error, term()}

Compaction compresses the database file by removing unused sections created during updates. See http://wiki.apache.org/couchdb/Compaction for more informations

compact/2


compact(Db::db(), ViewName::string()) -> ok | {error, term()}

Like compact/1 but this compacts the view index from the current version of the design document. See http://wiki.apache.org/couchdb/Compaction#View_compaction for more informations

copy_doc/2

copy_doc(Db, Doc) -> any()

duplicate a document using the doc API

copy_doc/3

copy_doc(Db, Doc, Dest) -> any()

copy a doc to a destination. If the destination exist it will use the last revision, in other case a new doc is created with the the current doc revision.

create_db/2

create_db(Server, DbName) -> any()

Equivalent to create_db(Server, DbName, [], []).

Create a database and a client for connectiong to it.

create_db/3

create_db(Server, DbName, Options) -> any()

Equivalent to create_db(Server, DbName, Options, []).

Create a database and a client for connectiong to it.

create_db/4


create_db(Server::server(), DbName::string(), Options::optionList(), Params::list()) -> {ok, db() | {error, Error}}

Create a database and a client for connectiong to it.

Connections are made to:

          http://Host:PortPrefix/DbName

If ssl is set https is used. See server_connections for options. Params is a list of optionnal query argument you want to pass to the db. Useful for bigcouch for example.

db_exists/2


db_exists(Server::server(), DbName::string()) -> boolean()

test if db with dbname exists on the CouchDB node

db_info/1


db_info(Db::db()) -> {ok, iolist() | {error, Error}}

get database info

delete_attachment/3

delete_attachment(Db, Doc, Name) -> any()

Equivalent to delete_attachment(Db, Doc, Name, []).

delete a document attachment

delete_attachment/4

delete_attachment(Db, DocOrDocId, Name, Options) -> any()

delete a document attachment

delete_db/1

delete_db(Db) -> any()

Equivalent to delete_db(Server, DbName).

delete database

delete_db/2


delete_db(Server::server(), DbName) -> {ok, iolist() | {error, Error}}

delete database

delete_doc/2

delete_doc(Db, Doc) -> any()

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

delete a document

delete_doc/3


delete_doc(Db, Doc, Options) -> {ok, Result} | {error, Error}

delete a document 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_docs/2

delete_docs(Db, Docs) -> any()

Equivalent to delete_docs(Db, Docs, []).

delete a list of documents

delete_docs/3


delete_docs(Db::db(), Docs::list(), Options::list()) -> {ok, Result} | {error, Error}

delete 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.

design_info/2

design_info(Db, DesignName) -> any()

doc_exists/2


doc_exists(Db::db(), DocId::string()) -> boolean()

test if doc with uuid exists in the given db

end_doc_stream/1


end_doc_stream(X1::doc_stream()) -> ok

stop to receive the multipart response of the doc api and close the connection.

ensure_full_commit/1

ensure_full_commit(Db) -> any()

Equivalent to ensure_full_commit(Db, []).

commit all docs in memory

ensure_full_commit/2


ensure_full_commit(Db::db(), Options::list()) -> {ok, InstancestartTime::binary()} | {error, term()}

commit all docs in memory

fetch_attachment/3

fetch_attachment(Db, DocId, Name) -> any()

Equivalent to fetch_attachment(Db, DocId, Name, []).

fetch a document attachment

fetch_attachment/4


fetch_attachment(Db::db(), DocId::string(), Name::string(), Options0::list()) -> {ok, binary()} | {ok, atom()} | {error, term()}

fetch a document attachment Options are

  • stream: to start streaming an attachment. the function return {ok, Ref} where is a ref to the attachment

  • Other options that can be sent using the REST API

get_missing_revs/2


get_missing_revs(Db::#db{}, IdRevs::[{binary(), [binary()]}]) -> {ok, [{DocId::binary(), [MissingRev::binary()], [PossibleAncestor::binary()]}]} | {error, term()}

get missing revisions

get_uuid/1


get_uuid(Server::server()) -> lists()

Get one uuid from the server

get_uuids/2


get_uuids(Server::server(), Count::integer()) -> lists()

Get a list of uuids from the server

lookup_doc_rev/2

lookup_doc_rev(Db, DocId) -> any()

get the last revision of the document

lookup_doc_rev/3

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

open_db/2

open_db(Server, DbName) -> any()

Equivalent to open_db(Server, DbName, []).

Create a client for connection to a database

open_db/3


open_db(Server::server(), DbName::string(), Options::optionList()) -> {ok, db()}

Create a client for connection to a database

open_doc/2

open_doc(Db, DocId) -> any()

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

open a document

open_doc/3


open_doc(Db::db(), DocId::string(), Params::list()) -> {ok, Doc} | {error, Error}

open a document Params is a list of query argument. Have a look in CouchDb API

open_or_create_db/2

open_or_create_db(Server, DbName) -> any()

Equivalent to open_or_create_db(Server, DbName, [], []).

Create a client for connecting to a database and create the database if needed.

open_or_create_db/3

open_or_create_db(Server, DbName, Options) -> any()

Equivalent to open_or_create_db(Server, DbName, Options, []).

Create a client for connecting to a database and create the database if needed.

open_or_create_db/4


open_or_create_db(Server::server(), DbName0::string(), Options::list(), Params::list()) -> {ok, db() | {error, Error}}

Create a client for connecting to a database and create the database if needed.

put_attachment/4

put_attachment(Db, DocId, Name, Body) -> any()

Equivalent to put_attachment(Db, DocId, Name, Body, []).

put an attachment

put_attachment/5


put_attachment(Db::db(), DocId::string(), Name::string(), Body::body(), Option::optionList()) -> {ok, iolist()}

put an attachment

replicate/2


replicate(Server::server(), RepObj::{list()}) -> {ok, Result} | {error, Error}

Handle replication. Pass an object containting all informations It allows to pass for example an authentication info

  RepObj = {[
  {<<"source">>, <<"sourcedb">>},
  {<<"target">>, <<"targetdb">>},
  {<<"create_target">>, true}
  ]}
  replicate(Server, RepObj).

replicate/3


replicate(Server::server(), Source::string(), Target::target()) -> {ok, Result} | {error, Error}

Handle replication.

replicate/4

replicate(Server, Source, Target, Options) -> any()

handle Replication. Allows to pass options with source and target. Options is a Json object. ex:

  Options = [{<<"create_target">>, true}]}
  couchbeam:replicate(S, "testdb", "testdb2", Options).

save_doc/2

save_doc(Db, Doc) -> any()

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

save a document

save_doc/3


save_doc(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_doc/4


save_doc(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.

save_docs/2

save_docs(Db, Docs) -> any()

Equivalent to save_docs(Db, Docs, []).

save a list of documents

save_docs/3


save_docs(Db::db(), Docs::list(), Options::list()) -> {ok, Result} | {error, Error}

save a list of documents

send_attachment/2

send_attachment(Ref, Msg) -> any()

send an attachment chunk Msg could be Data, eof to stop sending.

server_connection/0

server_connection() -> any()

Equivalent to server_connection("127.0.0.1", 5984, "", [], false).

Create a server for connectiong to a CouchDB node

server_connection/1

server_connection(URL) -> any()

server_connection/2

server_connection(URL, Options) -> any()

Equivalent to server_connection(Host, Port, "", []).

Create a server for connectiong to a CouchDB node

server_connection/4


server_connection(Host::string(), Port::non_neg_integer(), Prefix::string(), OptionsList::list()) -> Server::server()

Create a server for connectiong to a CouchDB node

Connections are made to:

          http://Host:PortPrefix

If ssl is set https is used.

For a description of SSL Options, look in the ssl manpage.

server_info/1


server_info(Server::server()) -> {ok, iolist()}

Get Information from the server

stream_attachment/1


stream_attachment(Ref::atom()) -> {ok, binary()} | done | {error, term()}

fetch an attachment chunk. Use this function when you pass the stream option to the couchbeam:fetch_attachment/4 function. This function return the following response:

done
You got all the attachment
{ok, binary()}
Part of the attachment
{error, term()}
n error occurred

stream_doc/1


stream_doc(X1::doc_stream()) -> {doc, doc()} | {att, Name::binary(), doc_stream()} | {att_body, Name::binary(), Chunk::binary(), doc_stream()} | {att_eof, Name::binary(), doc_stream()} | eof | {error, term()}

stream the multipart response of the doc API. Use this function when you get {ok, {multipart, State}} from the function couchbeam:open_doc/3.

view_cleanup/1

view_cleanup(Db) -> any()