couchbeam (couchbeam v2.0.0)

View Source

Summary

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.

Create a database and a client for connectiong to it.

test if db with dbname exists on the CouchDB node

get database info

delete database

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

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

Create a client for connection to a database

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

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

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

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

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

db/0

-type db() :: #db{server :: server(), name :: binary(), options :: list()}.

doc/0

-type doc() :: ejson_object().

doc_stream/0

-opaque doc_stream()

ejson_object/0

-type ejson_object() :: map().

mp_attachment/0

-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()}.

mp_attachments/0

-type mp_attachments() :: [mp_attachment()].

server/0

-type server() :: #server{url :: term(), options :: list()}.

Functions

all_dbs(Server)

-spec all_dbs(server()) -> {ok, [binary()]} | {error, term()}.

get list of databases on a CouchDB node

all_dbs(Server, Options)

-spec all_dbs(server(), list()) -> {ok, [binary()]} | {error, term()}.

get list of databases on a CouchDB node with optional filter

compact(Db)

-spec compact(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(Db, DesignName)

-spec compact(db(), binary() | 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(Db, Doc)

duplicate a document using the doc API

copy_doc(Db, Doc, Dest)

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(Server, DbName)

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

Create a database and a client for connectiong to it.

create_db(Server, DbName, Options)

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

Create a database and a client for connectiong to it.

create_db(Server, DbName0, Options, Params)

-spec create_db(server(), binary() | string(), list(), list()) -> {ok, db()} | {error, term()}.

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(Server, DbName)

-spec db_exists(server(), binary() | string()) -> boolean().

test if db with dbname exists on the CouchDB node

db_info(Db)

-spec db_info(db()) -> {ok, map()} | {error, term()}.

get database info

delete_attachment(Db, Doc, Name)

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

delete a document attachment

delete_attachment(Db, DocOrDocId, Name, Options)

-spec delete_attachment(db(), map() | binary() | string(), binary() | string(), list()) ->
                           {ok, map()} | {error, term()}.

delete a document attachment

delete_db(Db)

Equivalent to delete_db(Server, DbName).

delete database

delete_db(Server, DbName)

-spec delete_db(server(), binary() | string()) -> {ok, map()} | {error, term()}.

delete database

delete_doc(Db, Doc)

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

delete a document

delete_doc(Db, Doc, Options)

-spec delete_doc(db(), map(), list()) -> {ok, list()} | {error, term()}.

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(Db, Docs)

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

delete a list of documents

delete_docs(Db, Docs, Options)

-spec delete_docs(db(), [map()], list()) -> {ok, list()} | {error, term()}.

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(Db, DesignName)

doc_exists(Db, DocId)

-spec doc_exists(db(), binary() | string()) -> boolean().

test if doc with uuid exists in the given db

end_doc_stream(_)

-spec end_doc_stream(doc_stream()) -> ok.

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

ensure_full_commit(Db)

Equivalent to ensure_full_commit(Db, []).

commit all docs in memory

ensure_full_commit(Db, Options)

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

commit all docs in memory

fetch_attachment(Db, DocId, Name)

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

fetch a document attachment

fetch_attachment(Db, DocId, Name, Options0)

-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

find(Db, Selector, Params)

-spec find(Db :: db(), Selector :: doc(), Params :: list()) -> {ok, Doc :: doc()} | {error, any()}.

get_missing_revs(Db, IdRevs)

-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_uuid(Server)

-spec get_uuid(server()) -> [binary()].

Get one uuid from the server

get_uuids(Server, Count)

-spec get_uuids(server(), integer()) -> [binary()].

Get a list of uuids from the server

lookup_doc_rev(Db, DocId)

get the last revision of the document

lookup_doc_rev(Db, DocId, Params)

open_db(Server, DbName)

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

Create a client for connection to a database

open_db(Server, DbName, Options)

-spec open_db(server(), binary() | string(), list()) -> {ok, db()}.

Create a client for connection to a database

open_doc(Db, DocId)

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

open a document

open_doc(Db, DocId, Params)

-spec open_doc(db(), binary() | string(), list()) -> {ok, map()} | {error, term()}.

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

open_or_create_db(Server, DbName)

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(Server, DbName, Options)

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(Server, DbName0, Options, Params)

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

put_attachment(Db, DocId, Name, Body)

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

put an attachment

put_attachment(Db, DocId, Name, Body, Options)

-spec put_attachment(db(), binary() | string(), binary() | string(), iodata() | fun(), list()) ->
                        {ok, map()} | {error, term()}.

put an attachment

replicate(Server, RepObj)

-spec replicate(server(), map()) -> {ok, map()} | {error, term()}.

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(Server, Source, Target)

-spec replicate(server(), binary() | string(), binary() | string()) -> {ok, map()} | {error, term()}.

Handle replication.

replicate(Server, Source, Target, Options)

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}]).

save_doc(Db, Doc)

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

save a document

save_doc(Db, Doc, Options)

-spec save_doc(db(), map(), list()) -> {ok, map()} | {error, term()}.

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(Db, Doc, Atts, Options)

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

save_docs(Db, Docs)

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

save a list of documents

save_docs(Db, Docs, Options)

-spec save_docs(db(), [map()], list()) -> {ok, list()} | {error, term()}.

save a list of documents

send_attachment(Ref, Msg)

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

server_connection()

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

Create a server for connectiong to a CouchDB node

server_connection(URL)

server_connection(URL, Options0)

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

Create a server for connectiong to a CouchDB node

server_connection(Host, Port, Prefix, OptionsList)

-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:PortPrefix

If ssl is set https is used.

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

server_info(Server)

-spec server_info(server()) -> {ok, map()} | {error, term()}.

Get Information from the server

stream_attachment(Ref)

-spec stream_attachment(pid()) -> {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_attachment(Db, DocId, Name)

-spec stream_attachment(db(), binary(), binary()) -> {ok, pid()} | {error, term()}.

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.

stream_doc(_)

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

view_cleanup(Db)