PhoenixKitDb.Listener (PhoenixKitDb v0.1.0)

Copy Markdown View Source

GenServer that listens for PostgreSQL NOTIFY events for live table updates.

Holds a separate Postgrex.Notifications connection (auto-reconnect on drop) on the phoenix_kit_db_changes channel. When a notification arrives it broadcasts via PhoenixKitDb.PubSub so LiveViews can react in real time.

Started via the PhoenixKit.Module.children/0 callback on PhoenixKitDb, which the host's PhoenixKit.Supervisor consumes when the module is enabled.

Summary

Functions

Returns a specification to start this module under a supervisor.

Ensures the Listener is started. Called automatically by the subscribe helpers. The Listener is normally started by PhoenixKit.Supervisor via this module's children/0 callback; this function logs a warning if it isn't running so a missed startup is observable rather than silent.

Starts the listener process.

Subscribe to changes for a specific table.

Subscribe to all table changes (Index + Activity pages).

Unsubscribe from changes for a specific table.

Unsubscribe from all table changes.

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

ensure_started()

@spec ensure_started() :: :ok

Ensures the Listener is started. Called automatically by the subscribe helpers. The Listener is normally started by PhoenixKit.Supervisor via this module's children/0 callback; this function logs a warning if it isn't running so a missed startup is observable rather than silent.

start_link(opts \\ [])

@spec start_link(keyword()) :: GenServer.on_start()

Starts the listener process.

subscribe(schema, table)

@spec subscribe(String.t(), String.t()) :: :ok | {:error, term()}

Subscribe to changes for a specific table.

subscribe_all()

@spec subscribe_all() :: :ok | {:error, term()}

Subscribe to all table changes (Index + Activity pages).

unsubscribe(schema, table)

@spec unsubscribe(String.t(), String.t()) :: :ok | {:error, term()}

Unsubscribe from changes for a specific table.

unsubscribe_all()

@spec unsubscribe_all() :: :ok | {:error, term()}

Unsubscribe from all table changes.