barrel_att (barrel_docdb v1.1.1)

View Source

Attachment API for barrel_docdb

Provides a higher-level API for attachment operations. Uses barrel_att_store for storage with BlobDB.

Summary

Functions

Delete all attachments for a document

List all attachment names for a document

Create attachment info from data

Store an attachment with options (sync, content_type, origin_hlc, expected_digest; see the blob backend).

Validate attachment name

Types

att_info/0

-type att_info() ::
          #{name := binary(),
            content_type := binary(),
            length := non_neg_integer(),
            digest := binary(),
            chunked => boolean(),
            chunk_size => pos_integer(),
            chunk_count => pos_integer()}.

change/0

-type change() :: map().

db_config/0

-type db_config() :: #{path => string(), store => module(), atom() => term()}.

db_name/0

-type db_name() :: binary().

db_ref/0

-type db_ref() :: pid() | atom().

doc/0

-type doc() :: #{binary() => term()}.

doc_info/0

-type doc_info() :: #{id := docid(), rev := revid(), deleted := boolean(), revtree := revtree()}.

docid/0

-type docid() :: binary().

endpoint/0

-type endpoint() :: db_name() | {node(), db_name()} | {module(), term()}.

rep_options/0

-type rep_options() ::
          #{continuous => boolean(),
            since => seq_string(),
            filter => fun((doc()) -> boolean()),
            atom() => term()}.

rev_info/0

-type rev_info() ::
          #{id := revid(),
            parent := revid() | undefined,
            deleted := boolean(),
            attachments => #{binary() => att_info()}}.

revid/0

-type revid() :: binary().

revtree/0

-type revtree() :: #{revid() => rev_info()}.

seq/0

-type seq() :: barrel_hlc:timestamp().

seq_string/0

-type seq_string() :: binary().

view_name/0

-type view_name() :: binary().

view_result/0

-type view_result() :: #{key := term(), value := term(), id := docid()}.

Functions

attachment_exists(AttRef, DbName, DocId, AttName)

-spec attachment_exists(barrel_att_store:att_ref(), db_name(), docid(), binary()) -> boolean().

Check if an attachment exists

delete_attachment(AttRef, DbName, DocId, AttName)

-spec delete_attachment(barrel_att_store:att_ref(), db_name(), docid(), binary()) ->
                           ok | {error, term()}.

Delete an attachment

delete_doc_attachments(AttRef, DbName, DocId)

-spec delete_doc_attachments(barrel_att_store:att_ref(), db_name(), docid()) -> ok | {error, term()}.

Delete all attachments for a document

get_attachment(AttRef, DbName, DocId, AttName)

-spec get_attachment(barrel_att_store:att_ref(), db_name(), docid(), binary()) ->
                        {ok, binary()} | {error, not_found} | {error, term()}.

Retrieve an attachment

list_attachments(AttRef, DbName, DocId)

-spec list_attachments(barrel_att_store:att_ref(), db_name(), docid()) -> [binary()].

List all attachment names for a document

make_att_info(AttName, Data, ContentType)

-spec make_att_info(binary(), binary(), binary()) -> att_info().

Create attachment info from data

put_attachment(AttRef, DbName, DocId, AttName, Data)

-spec put_attachment(barrel_att_store:att_ref(), db_name(), docid(), binary(), binary()) ->
                        {ok, att_info()} | {error, term()}.

Store an attachment

put_attachment(AttRef, DbName, DocId, AttName, Data, Opts)

-spec put_attachment(barrel_att_store:att_ref(), db_name(), docid(), binary(), binary(), map()) ->
                        {ok, att_info()} | {ok, ignored} | {error, term()}.

Store an attachment with options (sync, content_type, origin_hlc, expected_digest; see the blob backend).

validate_att_name(Name)

-spec validate_att_name(binary()) -> ok | {error, invalid_att_name}.

Validate attachment name