website/docs/api/clients/elixir.md
Electric has an Elixir client and deep Phoenix integration.
The Electric.Client library allows you to stream Shapes into your Elixir application. It's published to Hex as the electric_client package.
The client exposes a stream/3 that streams a Shape Log into an Enumerable:
Mix.install([:electric_client])
{:ok, client} = Electric.Client.new(base_url: "http://localhost:3000")
stream = Electric.Client.stream(client, "my_table", where: "something = true")
stream
|> Stream.each(&IO.inspect/1)
|> Stream.run()
You can materialise the shape stream into a variety of data structures. For example by matching on insert, update and delete operations and applying them to a Map or an Ecto struct. (See the Redis example example and Typescript Shape class for reference).
The stream/3 function also supports deriving the shape definition from an Ecto.Query:
import Ecto.Query, only: [from: 2]
query = from(t in MyTable, where: t.something == true)
stream = Electric.Client.stream(client, query)
See the documentation at hexdocs.pm/electric_client for more details.
Electric has deep integration into the Phoenix framework via the official Phoenix.Sync library.
See the Phoenix integration page for more details.