marcojulian
Looking for a Change Data Capture (CDC) lib for MySQL
My Elixir application needs to connect with a MySQL database and listen for insert and updates in certain tables, does anyone know about a library that makes this easier? I would use WalEx or Cainophile but they are intended for PostgreSQL DBs.
Marked As Solved
joerichsen
Hi
You could use Port — Elixir v1.16.3 with the stdout option of https://maxwells-daemon.io/
I have this proof of concept code that might get you started
defmodule MaxwellListener do
use GenServer
# Adjust the command to include the full executable path if necessary
@command "maxwell"
@args [
"--user='maxwell'",
"--password='XXXXXX'",
"--host='127.0.0.1'",
"--filter='exclude: *.*, include: holdsport.users, include: holdsport.teams_users'",
"--producer=stdout"
]
def start_link(opts \\ []) do
GenServer.start_link(__MODULE__, :ok, opts)
end
def init(:ok) do
command_with_args = Enum.join([@command | @args], " ")
options = [:binary, :exit_status]
port = Port.open({:spawn, command_with_args}, options)
{:ok, %{port: port}}
end
def handle_info({port, {:data, data}}, state) do
process_output(data)
{:noreply, state}
end
def handle_info({:EXIT, _port, _reason}, state) do
# Handle port exit
{:stop, :normal, state}
end
defp process_output(data) do
data
|> String.trim_trailing()
|> Jason.decode!(keys: :atoms)
|> handle()
end
defp handle(%{table: "teams_users", data: %{users_id: user_id}}) do
IO.inspect(user_id, label: "User ID")
end
defp handle(d) do
IO.inspect(d, limit: :infinity)
end
end
1
Popular in Questions
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
I’m hoping you guys can give me some general advice and perhaps code examples if you’re feeling up to it.
I’m very interested in Elixir,...
New
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
I have an umbrella app.
Some of the apps inside depend on other apps in the umbrella, unsurprisingly.
I'm writing a test for one of t...
New
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
The Elixir Typespec docs show the following syntax for keyword lists in typespecs:
# ...
| [key: type] # keyword lis...
New
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
Hi,
I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
Can someone explain the settings of pool_size of Ecto in config file? and what is the recommend size?
Thanks
New
Mix format works fine if run from the cmd. I’ve followed this to facilitate the implementation into VSC which involves downloading an ext...
New
Other popular topics
Phoenix 1.4.0 released
Phoenix 1.4 is out! This release ships with exciting new features, most notably
with HTTP2 support, improved deve...
New
Okay, I'm having a heck of a time trying to figure out how to best handle the validation of belongs_to associations in Ecto. I'm sure I'...
New
Hello!
Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
Good day to you all.
I have been struggling to get a query involving like and ilike to work.
Can anyone assist me on this, please?
pro...
New
Hi, this is for people who, like me, have had some friction using .html.heex templates in VSCode.
The solution seems to be, in a hyphena...
New
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
New
I am trying to run a deploy with docker and I successfully runned with this command:
docker build -t romenigld/blog-prod .
but when I t...
New
Elixir appears to be a superior language to Python. I don’t see any advantage of Python over Elixir. Are there any?
New
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New







