Skip to content

Latest commit

 

History

History
206 lines (124 loc) · 4.87 KB

couchbeam_changes.md

File metadata and controls

206 lines (124 loc) · 4.87 KB

Module couchbeam_changes

Function Index

cancel_stream/1
follow/1
follow/2Stream changes to a pid.
follow_once/1
follow_once/2fetch all changes at once using a normal or longpoll connections.
stream_next/1

Function Details

cancel_stream/1

cancel_stream(Ref) -> any()

follow/1


follow(Db::db()) -> {ok, StreamRef::atom()} | {error, term()}

follow/2


follow(Db::db(), Options::changes_options()) -> {ok, StreamRef::atom()} | {error, term()}

Stream changes to a pid

Db : a db record

Client : pid or callback where to send changes events where events are The pid receive these events:

{change, StartRef, {done, Lastseq::integer()}
Connection terminated or you got all changes
{change, StartRef, Row :: ejson_object()}
Line of change
{error, LastSeq::integer(), Msg::term()}
Got an error, connection is closed when an error happend.

LastSeq is the last sequence of changes.

While the callbac could be like:


       fun({done, LastSeq}) ->
           ok;
       fun({done, LastSeq}) ->
           ok;
       fun({done, LastSeq}) ->
           ok.
>Options :: changes_stream_options() [continuous
     | longpoll
     | normal
     | include_docs
     | {since, integer() | now}
     | {timeout, integer()}
     | heartbeat | {heartbeat, integer()}
     | {filter, string()} | {filter, string(), list({string(), string() | integer()})}
     | {view, string()},
     | {docids, list))},
     | {stream_to, pid()},
     | {async, once | normal}]
  • continuous | longpoll | normal: set the type of changes feed to get

  • include_doc: if you want to include the doc in the line of change

  • {timeout, Timeout::integer()}: timeout

  • heartbeat | {heartbeat, Heartbeat::integer()}: set couchdb to send a heartbeat to maintain connection open

  • {filter, FilterName} | {filter, FilterName, Args::list({key, value})}: set the filter to use with optional arguments

  • {view, ViewName}: use a view function as filter. Note that it requires to set filter special value "_view" to enable this feature.

  • {stream_to, Pid}: the pid where the changes will be sent, by default the current pid. Used for continuous and longpoll connections

Return {ok, StartRef, ChangesPid} or {error, Error}. Ref can be used to disctint all changes from this pid. ChangesPid is the pid of the changes loop process. Can be used to monitor it or kill it when needed.

follow_once/1


follow_once(Db::db()) -> {ok, LastSeq::integer(), Changes::list()} | {error, term()}

follow_once/2


follow_once(Db::db(), Options::changes_options()) -> {ok, LastSeq::integer(), Changes::list()} | {error, term()}

fetch all changes at once using a normal or longpoll connections.

Db : a db record

Options :: changes_options() [
     | longpoll
     | normal
     | include_docs
     | {since, integer() | now}
     | {timeout, integer()}
     | heartbeat | {heartbeat, integer()}
     | {filter, string()}
     | {filter, string(), list({string(), string() | integer()})}
     | {docids, list()))},
     | {stream_to, pid()}
     ]
  • longpoll | normal: set the type of changes feed to get

  • include_docs: if you want to include the doc in the line of change

  • {timeout, Timeout::integer()}: timeout

  • heartbeat | {heartbeat, Heartbeat::integer()}: set couchdb to send a heartbeat to maintain connection open

  • {filter, FilterName} | {filter, FilterName, Args::list({key, value}): set the filter to use with optional arguments

  • {view, ViewName}: use a view function as filter. Note that it requires to set filter special value "_view" to enable this feature.

Result: {ok, LastSeq::integer(), Rows::list()} or {error, LastSeq, Error}. LastSeq is the last sequence of changes.

stream_next/1

stream_next(Ref) -> any()