WalEx.Event (WalEx v4.8.0)

Copy Markdown View Source

User-facing change event struct.

Each replicated row change is cast into a %WalEx.Event{} containing the table (name), kind (type: :insert | :update | :delete), record(s), changed fields (for updates), commit timestamp, LSN, and source metadata.

Host modules use WalEx.Event, name: MyApp to gain the on_insert/4, on_update/4, on_delete/4, and on_event/2 macros from WalEx.Event.Dsl.

Summary

Functions

Installs the WalEx.Event.Dsl macros (on_insert/4, on_update/4, on_delete/4, on_event/2) and filter_events/1,4 helpers into the calling module, bound to the given :name (WalEx app instance).

Casts a WalEx.Changes.{NewRecord,UpdatedRecord,DeletedRecord} into an Event struct, attaching source metadata for app_name. Returns nil for unrecognised inputs.

Casts every change in a list (typically txn.changes) to an Event for app_name.

Filter out events by table and type (optional) from transaction and cast to Event struct

Types

t()

@type t() :: %WalEx.Event{
  changes: map() | nil,
  lsn: {integer(), integer()},
  name: atom(),
  new_record: map() | nil,
  old_record: map() | nil,
  source: WalEx.Event.Source.t(),
  timestamp: DateTime.t(),
  type: :insert | :update | :delete
}

Functions

__using__(opts)

(macro)

Installs the WalEx.Event.Dsl macros (on_insert/4, on_update/4, on_delete/4, on_event/2) and filter_events/1,4 helpers into the calling module, bound to the given :name (WalEx app instance).

cast(arg1, app_name)

Casts a WalEx.Changes.{NewRecord,UpdatedRecord,DeletedRecord} into an Event struct, attaching source metadata for app_name. Returns nil for unrecognised inputs.

cast_events(changes, app_name)

Casts every change in a list (typically txn.changes) to an Event for app_name.

filter_and_cast(app_name, txn)

Filter out events by table and type (optional) from transaction and cast to Event struct

filter_and_cast(app_name, txn, table, type, arg5)

lsn_to_string(arg)

@spec lsn_to_string({integer(), integer()}) :: String.t()