Skip to content

xerions/ecto_subscribe

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

EctoSubscribe

ecto_subscribe allows to subscribe on change a model.

Usage

You can define your ecto model and use subscribe macro:

import Ecto.Subscribe.Api

defmodule MyModel do
  use Ecto.Model

  subscribe(repo: MyRepo)
  schema "user" do
    field :name,    :string
    field :old, :integer
  end
end

After this tell to the ecto_subscribe about your repo and subcribe on event with:

Ecto.Subscribe.init(MyRepo)
Ecto.Subscribe.Api.subscribe(MyRepo, MyModel, "old > 20", [adapter: Ecto.Subscribe.Adapter.Log actions: [:create]])

When any event will occur, ecto_subscribe will write to log this.

ecto_subcribe supports following adapters:

  • Ecto.Subscribe.Adapter.Log - writes ecto changeset to the log;
  • Ecto.Subscribe.Adapter.Remote - sends ecto changeset via rpc to the given node.

ecto_subscribe supports following actions:

  • create - occurs after inserting of new data which matched with condition of subscription;
  • delete - occurs after deleting of data which matched with condition of subscription;
  • update - occurs after updating of data which matched with condition of subscription.

If actions option not given, subscription will be created for all three events.

Testing

For running unut tests execute:

MIX_ENV=pg mix test

or

MIX_ENV=mysql mix test

About

Ecto plugin for possibility to have generic subscription on data

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages