cheerfulstoic

cheerfulstoic

I’ve created a library that allows you to get notified about PostgeSQL inserts, updates, and deletes as Phoenix PubSub messages in your Elixir app. You might find this useful, for example, when updating caches or sending notifications about record updates.

See the README for more details and examples:

https://github.com/cheerfulstoic/ecto_watch

Showing Posts 1 to 10

c4710n

c4710n

Thank you for providing a more general and complete solution for pg_notify. The DX is good. Really like it.

akramic

akramic

This is really useful - well done and thanks for making this available to the community.

apoorv-2204

apoorv-2204

Can we use this in production?

cheerfulstoic

cheerfulstoic OP

As far as I know it’s been working stably for people. It has a pretty thorough test suite. So overall, it should be fine to use in production.

The method of database notifications that ecto_watch uses should scale quite a ways, but if you have a really large amount of activity or if you have big bursts, you should understand it’s performance characteristics (as with anything).

I have one PR that I hope to be merging soon to protect people from database trigger/function names being too long. Before that is merged, I’d suggest checking out this issue and using the label option if you experience a similar issue on startup.

apoorv-2204

apoorv-2204

is it possible to have brief overview of it works as diagram if otp used?

cheerfulstoic

cheerfulstoic OP

Not sure that I understand, but the structure that is used is pretty simple. If you add EctoWatch into your application, a Supervisor is created. For every EctoWatch watcher that you add, a GenServer is created which listens for messages from the database.

When the Supervisor is started, it runs these queries for each watcher:

  • CREATE OR REPLACE FUNCTION ...
  • DROP TRIGGER IF EXISTS ...
  • CREATE TRIGGER ...

The trigger calls the function which sends a notification to your application/the watcher GenServer.

And then each GenServer does a Phoenix.PubSub.broadcast for each message from the database so that you can get application updates (as described in the README)

If that’s not clear I’m happy to answer other questions.

Bodhert

Bodhert

Great library! thanks for creating this!
I did find and issues (there was no clear way) trying to test. I did create an issue on GitHub to clarify how I managed to test it with the core logic, or if maybe I am missing another easy way to test it.
https://github.com/cheerfulstoic/ecto_watch/issues/43

cheerfulstoic

cheerfulstoic OP

Thanks very much! I left a comment there and perhaps that’s the best place to continue the discussion :+1:

StandardMikeBenza

StandardMikeBenza

Do you have any advice for using this in conjunction with Ecto.Adapters.SQL.Sandbox in tests? I’d like to build a test that triggers a SQL change and verify that a side-effect event happens. When trying to start EctoWatch, Ecto.Adapters.SQL.Sandbox complains. I haven’t dug too deep into it yet – I just wanted to see if you have any advice before I go in.

cheerfulstoic

cheerfulstoic OP

Yeah, that’s actually the thing that @Bodhert was suggesting in his issue that he linked to. Basically his approach is to disable the sandbox for tests which require verifying your ecto_watch configuration/setup. He was suggesting that we could have a guide in the docs to discuss it.

— All posts loaded —

Where Next? Top

Trending in Announcing Top

type1fool
WebAuthnLiveComponent WebAuthnComponents See this post about renaming the package. Passwordless authentication for Phoenix LiveView app...
New
GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
woylie
I released Doggo, a collection of unstyled Phoenix components. https://github.com/woylie/doggo Features Unstyled Phoenix components....
New
ahamez
Hi everyone, I’ve been working on this protobuf library for 3 years. We use it in the company I work for, EasyMile, to communicate with ...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
kip
I’ll shortly be launching Text, a nascent text analysis library. Current functionality In this early version (not ready for prime time) ...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
budgie
A little off-topic, but I feel like people here have a good head on their shoulders. I used to be quite good at making software. Was luc...
New
KristerV
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
webofbits
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself. My main conc...
#ai
New
budgie
I love Elixir. It’s one of 2 programming languages I’ve ever fallen in love with. But I don’t use it anymore. Serverless was the promis...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews