cancel_stream/1 | |
follow/1 | |
follow/2 | Stream changes to a pid. |
follow_once/1 | |
follow_once/2 | fetch all changes at once using a normal or longpoll connections. |
stream_next/1 |
cancel_stream(Ref) -> any()
follow(Db::db()) -> {ok, StreamRef::atom()} | {error, term()}
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:
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(Db::db()) -> {ok, LastSeq::integer(), Changes::list()} | {error, term()}
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(Ref) -> any()