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

tompave
Hello there, I would like to share a feature toggles library (AKA feature flags) I’ve been working on. The main package is FunWithFlags...
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
New
blatyo
https://www.conduitframework.com/ The best overview for how things are tied together is this presentation. Modules and functions are pre...
New
Jskalc
Hi! Today, after a couple weeks of development I’ve released v0.1 of LiveVue. It’s a seamless integration of Vue and Phoenix LiveView, i...
New
Crowdhailer
Experimenting with this code. OK.try do user <- fetch_user(1) cart <- fetch_cart(1) order = checkout(cart, user) save_or...
New
vic
Expat is a tiny experiment I did for extracting patterns and being able to reuse them (compose and share patterns between elixir librarie...
New
handnot2
Samly can be used to enable SAML 2.0 Single Sign On in a Plug/Phoenix application. This library uses Erlang esaml to provide plug enabl...
New
mischov
import Meeseeks.CSS html = HTTPoison.get!("https://news.ycombinator.com/").body for story <- Meeseeks.all(html, css("tr.athing")) do...
New
wojtekmach
Hey everyone! Req is an HTTP client for Elixir that I’ve been working on for quite some time. There is already a lot of HTTP clients out...
New

Other popular topics Top

shahryarjb
Hello, I get Persian date from my client and convert it to normal calendar like this: def jalali_string_to_miladi_english_number(persi...
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
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
chrismccord
This release brings a number of exciting features, including integration with the new Phoenix LiveDashboard and Phoenix LiveView. There h...
New
script
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this "1000" What is the ...
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
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