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:
- The
DB.ListenerGenServer running (started via Application supervisor) - A notification trigger on the table being viewed
Use ensure_trigger/2 to set up the trigger for a table.
Summary
Functions
Aggregated Postgres stats for all user tables.
Disable the DB explorer module.
Enable the DB explorer module.
Whether the DB explorer module is enabled.
Ensures the notification function exists and creates a trigger on the table.
Fetches a single row by ID from a table. Returns {:ok, row_map} or {:error, :not_found}.
Returns configuration metadata for the admin dashboard card.
Checks if a table has a notification trigger installed.
Lists tables + stats with pagination and search.
Lists all tables that have notification triggers installed.
Removes all notification triggers from all tables.
Removes the notification trigger from a table.
Returns table metadata and row preview.
Functions
Aggregated Postgres stats for all user tables.
Disable the DB explorer module.
Enable the DB explorer module.
Whether the DB explorer module is enabled.
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.
Fetches a single row by ID from a table. Returns {:ok, row_map} or {:error, :not_found}.
Returns configuration metadata for the admin dashboard card.
Checks if a table has a notification trigger installed.
Lists tables + stats with pagination and search.
Lists all tables that have notification triggers installed.
Removes all notification triggers from all tables.
Removes the notification trigger from a table.
Returns table metadata and row preview.