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

Database helpers for PhoenixKit.

Provides metadata, stats, and paginated previews for Postgres tables so the
admin UI can browse data without exposing full SQL access.

## Live Updates

The DB module supports real-time updates via PostgreSQL LISTEN/NOTIFY.
When a table is being viewed, changes to that table trigger automatic refreshes.

This requires:
1. The `DB.Listener` GenServer running (started via Application supervisor)
2. A notification trigger on the table being viewed

Use `ensure_trigger/2` to set up the trigger for a table.

# `database_stats`

Aggregated Postgres stats for all user tables.

# `disable_system`

Disable the DB explorer module.

# `enable_system`

Enable the DB explorer module.

# `enabled?`

Whether the DB explorer module is enabled.

# `ensure_trigger`

Ensures the notification function exists and creates a trigger on the table.

This sets up PostgreSQL LISTEN/NOTIFY for live updates. The trigger fires
on INSERT, UPDATE, or DELETE and sends a notification to the
`phoenix_kit_db_changes` channel.

Returns `:ok` on success or `{:error, reason}` on failure.

# `fetch_row`

Fetches a single row by ID from a table.
Returns {:ok, row_map} or {:error, :not_found}.

# `get_config`

Returns configuration metadata for the admin dashboard card.

# `has_trigger?`

Checks if a table has a notification trigger installed.

# `list_tables`

Lists tables + stats with pagination and search.

# `list_triggered_tables`

Lists all tables that have notification triggers installed.

# `remove_all_triggers`

Removes all notification triggers from all tables.

# `remove_trigger`

Removes the notification trigger from a table.

# `table_preview`

Returns table metadata and row preview.

---

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