cpursley

cpursley

WalEx - Listen to Postgres change events and do stuff with the data directly in Elixir

Just added some DSL magic :magic_wand: to WalEx. WalEx allows you to listen to change events on your Postgres tables then perform callback-like actions with the data. It includes a diff of the data as well so that you can match on specific changes.

The codebase was originally based off of Supabase’s excellent realtime library which I then later refactored to use Postgrex’s new Replication capabilities. The reason I pulled it out into it’s own library is I wanted to work with the data directly in Elixir as well as track diffs.

So now you can set up an event listener like this:

defmodule MyApp.UserEvent do
  use WalEx.Event, name: MyApp

  # any event
  on_event(:user, fn {:ok, user} ->
    IO.inspect(on_event: user)
    # do something with user data (Event Struct)
  end)

  on_insert(:user, fn {:ok, user} ->
    IO.inspect(on_insert: user)
  end)

  on_update(:user, fn {:ok, user} ->
    IO.inspect(on_update: user)
  end)

  on_delete(:user, fn {:ok, user} ->
    IO.inspect(on_delete: user)
  end)

I’m also considering adding a configuration-only option so that non-Elixir folks can use the library to listen to Postgres changes and send them wherever they need. Feedback and ideas on how I can improve WalEx is much appreciated!

Most Liked

cpursley

cpursley

Now all end user needs to do is add their setting to a yaml config to send database change events to EventRelay (via WalEx): https://github.com/eventrelay/eventsql/blob/master/config.yaml

Where Next?

Popular in Libraries Top

blatyo
https://www.conduitframework.com/ The best overview for how things are tied together is this presentation. Modules and functions are pre...
New
devonestes
Introducing assertions, the library that helps you write really great test assertions! GitHub: https://github.com/devonestes/assertions ...
New
riverrun
I’ve just released version 3 of Comeonin, a password hashing library. The following small changes have been made: changes to the NIF c...
New
treble37
Just looking for a little feedback on a tiny helper library I built - Sometimes I find the need to convert maps with atom keys to maps...
New
wfgilman
I’ve cleaned up and open sourced three financial libraries I was using for my company. They are bindings for the APIs of these three comp...
New
tmbb
PhoenixWS - Websockets over Phoenix Channels Source code on Github here: https://github.com/tmbb/phoenix_ws Phoenix channels are a great...
New
Crowdhailer
Experimenting with this code. OK.try do user <- fetch_user(1) cart <- fetch_cart(1) order = checkout(cart, user) save_or...
New
mtrudel
Bandit is an HTTP server for Plug and WebSock apps. Bandit is written entirely in Elixir and is built atop Thousand Island. It can serve...
New
mischov
import Meeseeks.CSS html = HTTPoison.get!("https://news.ycombinator.com/").body for story <- Meeseeks.all(html, css("tr.athing")) do...
New
nikokozak
Hello all, I’ve been working on Svonix - a library for quickly integrating Svelte components into Phoenix views. It’s a much-needed succ...
New

Other popular topics Top

fireproofsocks
I’m working on defining a simple Ecto schema for a table (in PostGres), but I don’t see where I can define a column as NOT NULL. Conside...
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod -- where is this set? Thanks.
New
William
I would like to know that is there any online source for learning Phoenix Framework for building E-Commerce Store? Any advantage on build...
New
ycv005
I have followed this StackOverflow post to install the specific version of Erlang. And When I am running mix ecto.setup then getting fol...
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? https://hexdocs.pm/ecto/Ecto.Repo.h...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New

Sub Categories:

We're in Beta

About us Mission Statement