# `PhoenixKit.Modules.DB.Listener`
[🔗](https://github.com/BeamLabEU/phoenix_kit/blob/v1.7.63/lib/modules/db/listener.ex#L1)

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

This process uses Postgrex to establish a separate connection to PostgreSQL
and listens for notifications on the `phoenix_kit_db_changes` channel.

When a notification is received, it broadcasts via PubSub so LiveViews can
update in real-time.

## Usage

Since PhoenixKit is a library, the Listener is started lazily on first use.
Call `ensure_started/0` before subscribing, or use the subscribe functions
which will ensure it's started automatically.

# `child_spec`
[🔗](https://github.com/BeamLabEU/phoenix_kit/blob/v1.7.63/lib/modules/db/listener.ex#L18)

Returns a specification to start this module under a supervisor.

See `Supervisor`.

# `ensure_started`
[🔗](https://github.com/BeamLabEU/phoenix_kit/blob/v1.7.63/lib/modules/db/listener.ex#L44)

Ensures the Listener is started. Called automatically by subscribe functions.

The Listener is normally started by PhoenixKit.Supervisor. This function
is a safety check that logs a warning if the Listener isn't running.

Returns `:ok` if running, or `:ok` with a warning log if not (subscriptions
will still work but won't receive notifications until the Listener starts).

# `start_link`
[🔗](https://github.com/BeamLabEU/phoenix_kit/blob/v1.7.63/lib/modules/db/listener.ex#L31)

Starts the listener process.

# `subscribe`
[🔗](https://github.com/BeamLabEU/phoenix_kit/blob/v1.7.63/lib/modules/db/listener.ex#L62)

Subscribe to changes for a specific table.

# `subscribe_all`
[🔗](https://github.com/BeamLabEU/phoenix_kit/blob/v1.7.63/lib/modules/db/listener.ex#L77)

Subscribe to all table changes (for the index page).

# `unsubscribe`
[🔗](https://github.com/BeamLabEU/phoenix_kit/blob/v1.7.63/lib/modules/db/listener.ex#L70)

Unsubscribe from changes for a specific table.

# `unsubscribe_all`
[🔗](https://github.com/BeamLabEU/phoenix_kit/blob/v1.7.63/lib/modules/db/listener.ex#L85)

Unsubscribe from all table changes.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
