# `PhoenixKit.Modules.DB.Listener`
[🔗](https://github.com/BeamLabEU/phoenix_kit/blob/v1.7.87/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`

Returns a specification to start this module under a supervisor.

See `Supervisor`.

# `ensure_started`

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`

Starts the listener process.

# `subscribe`

Subscribe to changes for a specific table.

# `subscribe_all`

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

# `unsubscribe`

Unsubscribe from changes for a specific table.

# `unsubscribe_all`

Unsubscribe from all table changes.

---

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