couchbeam (couchbeam v2.0.0)
View SourceSummary
Functions
get list of databases on a CouchDB node
get list of databases on a CouchDB node with optional filter
Compaction compresses the database file by removing unused sections created during updates. See http://wiki.apache.org/couchdb/Compaction for more informations
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
duplicate a document using the doc API
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.
Equivalent to create_db(Server, DbName, [], []).
Create a database and a client for connectiong to it.
test if db with dbname exists on the CouchDB node
get database info
delete a document attachment
Equivalent to delete_db(Server, DbName).
delete database
Equivalent to delete_doc(Db, Doc, []).
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.
Equivalent to delete_docs(Db, Docs, []).
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.
test if doc with uuid exists in the given db
stop to receive the multipart response of the doc api and close the connection.
Equivalent to ensure_full_commit(Db, []).
commit all docs in memory
fetch a document attachment Options are
get missing revisions
Get one uuid from the server
Get a list of uuids from the server
get the last revision of the document
Equivalent to open_db(Server, DbName, []).
Create a client for connection to a database
Equivalent to open_doc(Db, DocId, []).
open a document Params is a list of query argument. Have a look in CouchDb API
Equivalent to open_or_create_db(Server, DbName, Options, []).
Create a client for connecting to a database and create the database if needed.
put an attachment
Handle replication. Pass an object containting all informations It allows to pass for example an authentication info
Handle replication.
handle Replication. Allows to pass options with source and target. Source and target can be either simple URI strings or complex document structures with authentication. Options is a Json object. ex
Equivalent to save_doc(Db, Doc, []).
save a *document A document is a Json object like this one
save a *document with all its attacjments A document is a Json object like this one
Equivalent to save_docs(Db, Docs, []).
save a list of documents
send an attachment chunk Msg could be Data, eof to stop sending.
Equivalent to server_connection("127.0.0.1", 5984, "", [], false).
Create a server for connectiong to a CouchDB node
Get Information from the server
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
stream the multipart response of the doc API. Use this function when you get {ok, {multipart, State}} from the function couchbeam:open_doc/3.
Types
-type doc() :: ejson_object().
-opaque doc_stream()
-type ejson_object() :: map().
-type mp_attachment() :: {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()}.
-type mp_attachments() :: [mp_attachment()].
Functions
get list of databases on a CouchDB node
get list of databases on a CouchDB node with optional filter
Compaction compresses the database file by removing unused sections created during updates. See http://wiki.apache.org/couchdb/Compaction for more informations
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
duplicate a document using the doc API
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.
Equivalent to create_db(Server, DbName, [], []).
Create a database and a client for connectiong to it.
Equivalent to create_db(Server, DbName, Options, []).
Create a database and a client for connectiong to it.
Create a database and a client for connectiong to it.
Connections are made to:
http://Host:PortPrefix/DbNameIf 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.
test if db with dbname exists on the CouchDB node
get database info
Equivalent to delete_attachment(Db, Doc, Name, []).
delete a document attachment
-spec delete_attachment(db(), map() | binary() | string(), binary() | string(), list()) -> {ok, map()} | {error, term()}.
delete a document attachment
Equivalent to delete_db(Server, DbName).
delete database
delete database
Equivalent to delete_doc(Db, Doc, []).
delete a document
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.
Equivalent to delete_docs(Db, Docs, []).
delete a list of documents
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.
test if doc with uuid exists in the given db
-spec end_doc_stream(doc_stream()) -> ok.
stop to receive the multipart response of the doc api and close the connection.
Equivalent to ensure_full_commit(Db, []).
commit all docs in memory
-spec ensure_full_commit(Db :: db(), Options :: list()) -> {ok, InstancestartTime :: binary()} | {error, term()}.
commit all docs in memory
Equivalent to fetch_attachment(Db, DocId, Name, []).
fetch a document attachment
-spec fetch_attachment(db(), list() | binary(), list() | binary(), 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
-spec get_missing_revs(#db{server :: server(), name :: binary(), options :: list()}, [{binary(), [binary()]}]) -> {ok, [{DocId :: binary(), [MissingRev :: binary()], [PossibleAncestor :: binary()]}]} | {error, term()}.
get missing revisions
Get one uuid from the server
Get a list of uuids from the server
get the last revision of the document
Equivalent to open_db(Server, DbName, []).
Create a client for connection to a database
Create a client for connection to a database
Equivalent to open_doc(Db, DocId, []).
open a document
open a document Params is a list of query argument. Have a look in CouchDb API
Equivalent to open_or_create_db(Server, DbName, [], []).
Create a client for connecting to a database and create the database if needed.
Equivalent to open_or_create_db(Server, DbName, Options, []).
Create a client for connecting to a database and create the database if needed.
-spec open_or_create_db(server(), binary() | string(), list(), list()) -> {ok, db()} | {error, term()}.
Create a client for connecting to a database and create the database if needed.
Equivalent to put_attachment(Db, DocId, Name, Body, []).
put an attachment
-spec put_attachment(db(), binary() | string(), binary() | string(), iodata() | fun(), list()) -> {ok, map()} | {error, term()}.
put an attachment
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).
-spec replicate(server(), binary() | string(), binary() | string()) -> {ok, map()} | {error, term()}.
Handle replication.
handle Replication. Allows to pass options with source and target. Source and target can be either simple URI strings or complex document structures with authentication. Options is a Json object. ex:
%% Simple URI replication
Options = [{<<"create_target">>, true}]},
couchbeam:replicate(S, "testdb", "testdb2", Options).
%% Complex replication with authentication
Source = "http://user:pass@remote.com:5984/db",
Target = {[{<<"url">>, <<"http://localhost:5984/target_db">>},
{<<"auth">>, {[{<<"basic">>, {[{<<"username">>, <<"user">>},
{<<"password">>, <<"pass">>}]}}]}}]},
couchbeam:replicate(S, Source, Target, [{<<"continuous">>, true}]).
Equivalent to save_doc(Db, Doc, []).
save a document
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.
-spec save_doc(Db :: db(), doc(), mp_attachments(), Options :: [{binary(), binary() | true}] | binary()) -> {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.
Equivalent to save_docs(Db, Docs, []).
save a list of documents
save a list of documents
send an attachment chunk Msg could be Data, eof to stop sending.
Equivalent to server_connection("127.0.0.1", 5984, "", [], false).
Create a server for connectiong to a CouchDB node
Equivalent to server_connection(Host, Port, "", []).
Create a server for connectiong to a CouchDB node
-spec server_connection(Host :: string(), Port :: non_neg_integer(), Prefix :: binary(), OptionsList :: list()) -> Server :: server().
Create a server for connectiong to a CouchDB node
Connections are made to:
http://Host:PortPrefixIf ssl is set https is used.
For a description of SSL Options, look in the ssl manpage.
Get Information from the server
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
Equivalent to fetch_attachment(Db, DocId, Name, [stream]).
Start streaming an attachment. Returns a reference that can be passed to stream_attachment/1 to receive chunks.
-spec stream_doc(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.