PhoenixKitDb.PubSub (PhoenixKitDb v0.1.0)

Copy Markdown View Source

Topic constants and subscribe/broadcast helpers for the DB module, backed by PhoenixKit.PubSub.Manager (the shared in-process PubSub server).

The Postgres LISTEN/NOTIFY channel itself (pubsub_changes) is internal to PhoenixKitDb.Listener — these helpers wrap the per-LiveView fan-out that the Listener performs after parsing each notification.

Topics

  • topic_all/0 — every mutation, regardless of table. Used by the Index page (table-list refresh) and the Activity page (live feed).
  • topic_table/2 — mutations for one specific schema.table. Used by the Show page so a busy unrelated table doesn't refresh the row preview.

Events

Messages are {:table_changed, schema, table, operation, row_id} tuples. operation is "INSERT" / "UPDATE" / "DELETE" (or "UNKNOWN" for a malformed payload). row_id may be nil when the underlying row has neither a uuid nor an id column.

Summary

Types

PubSub topic name.

Functions

Broadcasts a :table_changed message on a topic.

Subscribes the calling process to the given topic.

Topic that fans out every mutation across every watched table.

Topic scoped to a single schema.table pair.

Unsubscribes the calling process from the given topic.

Types

topic()

@type topic() :: String.t()

PubSub topic name.

Functions

broadcast(topic, message)

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

Broadcasts a :table_changed message on a topic.

subscribe(topic)

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

Subscribes the calling process to the given topic.

topic_all()

@spec topic_all() :: topic()

Topic that fans out every mutation across every watched table.

topic_table(schema, table)

@spec topic_table(String.t(), String.t()) :: topic()

Topic scoped to a single schema.table pair.

unsubscribe(topic)

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

Unsubscribes the calling process from the given topic.