marcojulian

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

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

Where Next?

Popular in Questions Top

openscript
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
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 record...
New
itssasanka
Hi all, Trying to get some more clarity over utc_datetime and naive_datetime for Ecto: https://hexdocs.pm/ecto/Ecto.Schema.html#module-...
New
_russellb
I want to try my hand at web scraping. What tools/libraries do I need to use. I’m hoping to turn this into something professional so don’...
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
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
LegitStack
I’m trying to make a websocket server in Phoenix or raw Elixir. I heard about gun, I think I could use cowboy, but since I’m not that sma...
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

Other popular topics Top

JDanielMartinez
Hi! May someone helps me, please! I have two apps into an umbrella project: the first one is Database, which manages queries, and the se...
New
sergio
In Ruby, I can go: User.find_by(email: "foobar@email.com").update(email: "hello@email.com") How can I do something similar in Elixir? ...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
jerry
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
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
chrismccord
As promised, the first release candidate of Phoenix 1.3.0 is out! This release focuses on code generators with improved project structure...
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
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
josevalim
Hi everyone, One of the features added to Elixir early on to help integration with Erlang code was the idea of overridable function defi...
New
Nvim
Elixir appears to be a superior language to Python. I don’t see any advantage of Python over Elixir. Are there any?
New

We're in Beta

About us Mission Statement