WalEx.TransactionFilter (WalEx v4.5.0)

View Source

Filter transactions based on the relation and event type.

Summary

Functions

contains_unwatched_records?(record, unwatched_records)

delete_event?(relation, txn)

filter_changes(transaction, table, type, app_name)

Returns a list of changes for the given table name and type (optional)

filter_subscribed(transaction, app_name)

Returns a list of subscribed changes

filter_unwatched_fields(events, unwatched_changes)

filter_unwatched_records(events, unwatched_records)

has_table?(arg1, table_name)

insert_event?(relation, txn)

map_changes(old_record, new_record)

map_columns(columns)

matches?(arg1, arg2)

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_relation_filter(relation)

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"}

record_type?(arg1, arg2)

subscribes?(map, app_name)

subscribes_to_table?(change, table, app_name)

unwatched_fields?(arg1, unwatched_changes)

update_event?(relation, txn)

watched_record?(arg1, unwatched_records)