cheerfulstoic / ecto_watch

EctoWatch allows you to easily get notifications about database changes directly from PostgreSQL.
201 stars 7 forks source link

add: Allow watchers without an ecto schema #18

Closed cheerfulstoic closed 4 months ago

cheerfulstoic commented 4 months ago

Fixes #16

From the new README section:


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],
        association_columns: [:author_id, :post_id]
      }, :updated, extra_columns: [:post_id]
    }
   ]}

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.

Supported keys for configuring a table without a schema: