barrel_bql_live (barrel v1.0.1)

View Source

A live BQL query: one process per SUBSCRIBE statement, pushing the initial snapshot and then add/change/remove deltas to its owner.

Two signal sources funnel into one idempotent refresh: - barrel_query_sub fires when a commit's NEW body matches the query (trie-prefiltered centrally). It never fires on deletes and never for rows that STOP matching, so it can only drive add/change. - a push-mode changes stream (from the snapshot's last_seq) covers the rest: deletes and unmatches for ids in the matched set. When the plan has no engine where (unconstrained or id-only subscriptions), query_sub has nothing to match on and the stream drives adds too.

refresh re-reads the document and re-checks it with barrel_query:match/2 (plus the plan's id bounds and residual conditions), which also neutralizes false positives from query_sub's own matcher.

Messages to the owner (Ref is the subscription reference): {bql_rows, Ref, [Row]} snapshot chunks {bql_ready, Ref, #{count, last_seq}} {bql_change, Ref, #{action := add | change, id, rev, row}} {bql_change, Ref, #{action := remove, id}} {bql_error, Ref, Reason} then the process exits

LIMIT caps the initial snapshot only; deltas are unbounded events. Owner death tears the query down; callers that need crash signals monitor the returned pid.

Summary

Functions

handle_call(Request, From, State)

handle_cast(Msg, State)

handle_continue(_, State)

handle_info(Info, State)

init(_)

start_link(Args)

terminate(Reason, State)