View Source Watching without a schema

Since ecto supports working with tables withoun needed a schema, you may also want to create EctoWatch watchers without needing to create a schema like so:

  # setup
  {EctoWatch,
   repo: MyApp.Repo,
   pub_sub: MyApp.PubSub,
   watchers: [
    {
      %{
        table_name: "comments",
        primary_key: :ID,
        columns: [:title, :body, :author_id, :post_id],
        column_map: %{body: :bodyContent},
        association_columns: [:author_id, :post_id]
      }, :updated, extra_columns: [:post_id], label: :comment_updated_custom
    }
   ]}

Everything works the same as with a schema, though make sure to specify your association columns if you want to subscribe to an association column.

To subscribe to the newly created watcher use the label that you set before:

EctoWatch.subscribe(:comment_updated_custom)

Supported keys for configuring a table without a schema:

  • schema_prefix (optional, defaults to public)
  • table_name (required)
  • primary_key (optional, defaults to id)
  • columns (optional, defaults to [])
  • column_map (optional, defaults to %{})
  • association_columns (optional, defaults to [])