Filter transactions based on the relation and event type.
Summary
Functions
Returns true when every key/value in unwatched_records is present in record.
Returns true if the transaction includes a DELETE on the given relation.
Returns a list of changes for the given table name and type (optional)
Returns a list of subscribed changes
Drops events whose changed columns are entirely within unwatched_changes.
Drops events whose new (or old, for deletes) record fully matches unwatched_records.
Returns true when the change's table matches table_name (atom or string).
Returns true if the transaction includes an INSERT on the given relation.
Diffs two records into a map of field => %{old_value, new_value} containing
only the fields whose value changed.
Builds a %{column_name => type} map from a list of Relation.Column structs.
Predicate to check if the filter matches the transaction.
Parse a string representing a relation filter to a Filter struct.
Returns true when the change record matches the requested type (:insert | :update | :delete).
Returns true when the app's subscriptions include the change's table (or :all_tables).
Returns true when the change targets table and the app subscribes to it.
Returns true if the event has at least one changed column outside unwatched_changes.
Returns true if the transaction includes an UPDATE on the given relation.
Returns true when the event's record is not a full match against unwatched_records.
Functions
Returns true when every key/value in unwatched_records is present in record.
Returns true if the transaction includes a DELETE on the given relation.
Returns a list of changes for the given table name and type (optional)
Returns a list of subscribed changes
Drops events whose changed columns are entirely within unwatched_changes.
Drops events whose new (or old, for deletes) record fully matches unwatched_records.
Returns true when the change's table matches table_name (atom or string).
Returns true if the transaction includes an INSERT on the given relation.
Diffs two records into a map of field => %{old_value, new_value} containing
only the fields whose value changed.
Builds a %{column_name => type} map from a list of Relation.Column structs.
Predicate to check if the filter matches the transaction.
Examples
iex> txn = %Transaction{changes: [
...> %WalEx.Changes.NewRecord{
...> columns: [
...> %WalEx.Decoder.Messages.Relation.Column{flags: [:key], name: "id", type: "int8", type_modifier: 4294967295},
...> %WalEx.Decoder.Messages.Relation.Column{flags: [], name: "details", type: "text", type_modifier: 4294967295},
...> %WalEx.Decoder.Messages.Relation.Column{flags: [], name: "user_id", type: "int8", type_modifier: 4294967295}
...> ],
...> commit_timestamp: nil,
...> record: %{"details" => "The SCSI system is down, program the haptic microchip so we can back up the SAS circuit!", "id" => "14", "user_id" => "1"},
...> schema: "public",
...> table: "todos",
...> type: "INSERT"
...> }
...> ]}
iex> matches?(%{event: "*", relation: "*"}, txn)
true
iex> matches?(%{event: "INSERT", relation: "*"}, txn)
true
iex> matches?(%{event: "UPDATE", relation: "*"}, txn)
false
iex> matches?(%{event: "INSERT", relation: "public"}, txn)
true
iex> matches?(%{event: "INSERT", relation: "myschema"}, txn)
false
iex> matches?(%{event: "INSERT", relation: "public:todos"}, txn)
true
iex> matches?(%{event: "INSERT", relation: "myschema:users"}, txn)
false
Parse a string representing a relation filter to a Filter struct.
Examples
iex> parse_relation_filter("public:users")
{:ok, %Filter{schema: "public", table: "users", condition: nil}}
iex> parse_relation_filter("public")
{:ok, %Filter{schema: "public", table: nil, condition: nil}}
iex> parse_relation_filter("")
{:ok, %Filter{schema: nil, table: nil, condition: nil}}
iex> parse_relation_filter("public:users:bad")
{:error, "malformed relation filter"}
Returns true when the change record matches the requested type (:insert | :update | :delete).
Returns true when the app's subscriptions include the change's table (or :all_tables).
Returns true when the change targets table and the app subscribes to it.
Returns true if the event has at least one changed column outside unwatched_changes.
Returns true if the transaction includes an UPDATE on the given relation.
Returns true when the event's record is not a full match against unwatched_records.