View Source EctoWatch (EctoWatch v0.12.1)

A library to allow you to easily get notifications about database changes directly from PostgreSQL.

Summary

Functions

Returns a specification to start this module under a supervisor.

Returns details about a watcher for reflection purposes

Callback implementation for Supervisor.init/1.

Subscribe to notifications from watchers.

Unsubscribe from notifications from watchers that you previously subscribe. It receives the same params for subscribe/2.

Types

@type watcher_identifier() :: {atom(), atom()} | atom()

Functions

Returns a specification to start this module under a supervisor.

See Supervisor.

Link to this function

details(watcher_identifier)

View Source
@spec details(watcher_identifier()) :: %{
  repo_mod: module(),
  schema_definition: %{
    schema_prefix: binary(),
    table_name: binary(),
    primary_key: binary(),
    columns: [atom()],
    association_columns: [atom()],
    label: term()
  },
  function_name: binary(),
  trigger_name: binary(),
  notify_channel: binary()
}

Returns details about a watcher for reflection purposes

For example if you need to know what the function/triggers are in the database.

Examples:

iex> EctoWatch.subscribe({Comment, :updated})

Or for a label:

iex> EctoWatch.subscribe(:comment_updated_custom)

Callback implementation for Supervisor.init/1.

Link to this function

subscribe(watcher_identifier, id \\ nil)

View Source
@spec subscribe(watcher_identifier(), term()) :: :ok | {:error, term()}

Subscribe to notifications from watchers.

Examples:

iex> EctoWatch.subscribe({Comment, :updated})

When subscribing to a watcher with the label option specified as :comment_updated_custom:

iex> EctoWatch.subscribe(:comment_updated_custom)

You can subscribe to notifications just from specific primary key values:

iex> EctoWatch.subscribe({Comment, :updated}, user_id)

Or you can subscribe to notifications just from a specific foreign column (**the column must be in the watcher's extra_columns list):

iex> EctoWatch.subscribe({Comment, :updated}, {:post_id, post_id})
Link to this function

subscribe(schema_mod_or_label, update_type, id)

View Source
This function is deprecated. subscribe/3 was removed in version 0.8.0. See the updated documentation.
Link to this function

unsubscribe(watcher_identifier, id \\ nil)

View Source
@spec unsubscribe(watcher_identifier(), term()) :: :ok | {:error, term()}

Unsubscribe from notifications from watchers that you previously subscribe. It receives the same params for subscribe/2.

Examples:

iex> EctoWatch.unsubscribe({Comment, :updated})
iex> EctoWatch.unsubscribe({Comment, :updated}, {:post_id, post_id})