Composable query builder for filtering events from the store.
A query is a list of items, each specifying event types and/or tags that must match. Multiple items act as a union (OR): any event matching at least one item is returned. Within an item, types and tags are ANDed.
Options
after_position– return only events appended after this store position.limit– cap the number of returned events (0 = no limit).reverse– return events in reverse chronological order.
Example
alias Counterpoint.Query
alias MyApp.Events.{OrderPlaced, OrderCancelled}
# Fetch the last 1 event for a specific order, newest first
Query.new()
|> Query.add_item(types: [OrderPlaced, OrderCancelled], tags: ["order_id:123"])
|> Query.reverse()
|> Query.limit(1)
Summary
Functions
Add a filter item to the query.
Return only events appended after position.
Limit results to at most n events (0 = unlimited).
Create a new empty query.
Return events in reverse chronological order.
Types
Functions
Add a filter item to the query.
Options
:types– list of event modules (or type-string binaries) to match.:tags– list of tag strings to match.
Both default to [] (match anything for that field).
Return only events appended after position.
Limit results to at most n events (0 = unlimited).
Create a new empty query.
Return events in reverse chronological order.