Zurga
Subscribe to events emitted by EctoWatch, and cache the changed row. Use the sync/3 function to update an in-memory row or list of rows using the cached version of the changed row.
This library aims to solve the problem of tracking changes of database rows across processes without causing database stampedes. All possible update paths for each pair of schemas that are connected is determined to avoid brute-forcing through all preloaded associations.
Say you have a Post schema that has many Tags associated through a PostsTags schema and you want to automatically update the Tags for the loaded Posts in a LiveView:
appplication.ex
children: [...,
{EctoSync, repo: TestRepo, watchers: EctoSync.watchers(Post, assocs: [:tags])},
...
]
PostLive.ex
alias MyApp.Posts.{Post, PostsTags}
def mount(params, session, socket) do
posts = list_posts(preload: [:tags])
if connected?(socket) do
EctoSync.subscribe(Post, assocs: [:tags])
end
{:ok, assign(socket, posts: posts)}
end
def handle_info({{PostsTags, _event}, _} = sync_args, socket) do
{:noreply, update(socket, :posts, &EctoSync.sync(&1, sync_args))}
end
If you want to add preloads to the changed row, this is possible by adding a Map like this:
EctoSync.sync(post, sync_args, preloads: %{Tag => [:posts]})
It is still in an early stage of development and has not been tested in production. I would love to get feedback on this package.
Package on hex.pm here:
Documentation:
Repo:
Trending in Announcing
Other Trending Topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ai
- #ecto-query
- #elixirconf-us
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #elixirconf-eu
- #api
- #forms
- #metaprogramming
- #hex










Showing Posts 1 to 3- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
Zurga
Just updated to 0.1.4!
Changes:
:wherefilters are now also supported.:insertevents are broadcast whenever an association has moved to another parent. So if%Post{person_id: 1}was updated to%Post{person_id: 2}, an insert event is published for all processes listening to{{Post, :inserted}, {person_id: 2}}Working on tests for HasThrough, should be supported soon.
Zurga
Version 0.2.0 has been released. It brings some changes and supports new features.
Features:
:throughis fully supported.:whereis supported onhas_oneandhas_many.Changes:
{EctoSync, {schema, event, identifiers, ref}}. This allows them to be distinguished from other events that are in the form of tuples.Future work:
Zurga
Version 0.5.0 has been released!
It now features support for reading the WAL in Postgres and publishing sync events from there. There is a Repo module that can be
used as well that will prevent the process making the changes to the database from receiving a message about that change. To supportinsertyou will need to usebinary_idfor the primary key.