barrel_query_sub (barrel_docdb v1.1.1)
View Sourcebarrel_query_sub - Query-based subscription manager
Manages query-based subscriptions for document changes. Subscribers receive notifications when documents matching their queries are modified.
Uses path optimization: only evaluates the full query when a change affects paths referenced by the query.
Example:
Query = #{where => [{path, [<<"type">>], <<"user">>}]},
{ok, SubRef} = barrel_query_sub:subscribe(DbRef, Query, self()),
receive
{barrel_query_change, DbName, #{id := DocId}} -> ok
end,
ok = barrel_query_sub:unsubscribe(SubRef)Subscriptions are ephemeral - tied to subscriber process lifetime.
Summary
Functions
Notify query subscribers about a document change Called by barrel_db_server after document modifications. Only evaluates queries whose path patterns match the changed paths.
Start the query subscription manager
Stop the query subscription manager
Subscribe to document changes matching a query Returns a subscription reference that can be used to unsubscribe. The query must be a valid barrel_query specification.
Unsubscribe using the subscription reference
Types
-type att_info() :: #{name := binary(), content_type := binary(), length := non_neg_integer(), digest := binary(), chunked => boolean(), chunk_size => pos_integer(), chunk_count => pos_integer()}.
-type change() :: map().
-type db_name() :: binary().
-type docid() :: binary().
-type revid() :: binary().
-type seq() :: barrel_hlc:timestamp().
-type seq_string() :: binary().
-type view_name() :: binary().
Functions
Notify query subscribers about a document change Called by barrel_db_server after document modifications. Only evaluates queries whose path patterns match the changed paths.
Start the query subscription manager
-spec stop() -> ok.
Stop the query subscription manager
-spec subscribe(db_name(), barrel_query:query_spec(), pid()) -> {ok, reference()} | {error, term()}.
Subscribe to document changes matching a query Returns a subscription reference that can be used to unsubscribe. The query must be a valid barrel_query specification.
-spec unsubscribe(reference()) -> ok.
Unsubscribe using the subscription reference