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
Functions
Returns a specification to start this module under a supervisor.
See Supervisor
.
@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
.
@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})
@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})