Skip to content

Commit

Permalink
update elixir client docs
Browse files Browse the repository at this point in the history
  • Loading branch information
magnetised committed Oct 15, 2024
1 parent 04476b4 commit 03226a2
Showing 1 changed file with 25 additions and 9 deletions.
34 changes: 25 additions & 9 deletions website/docs/api/clients/elixir.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,38 @@ outline: deep

# Elixir Client

The Elixir client is being developed in [electric-sql/electric-next/pull/38](https://github.com/electric-sql/electric-next/pull/38). At the moment it provides a GenStage producer that can be used to stream a Shape as per:
We [maintain an Elixir
client](https://github.com/electric-sql/electric/tree/main/packages/elixir-client)
that will stream messages from an Electric server.

## Install

You can install it from [Hex](https://hex.pm/electric_client).

## How to use

The client exposes a
[`stream/3`](https://hexdocs.pm/electric_client/Electric.Client.html#stream/3)
function that returns an
[`Enumerable`](https://hexdocs.pm/elixir/Enumerable.html).

```elixir
opts = [
base_url: "http://...",
shape_definition: %Electric.Client.ShapeDefinition{
table: "..."
}
]
Mix.install([:electric_client])

{:ok, pid, stream} = Electric.Client.ShapeStream.stream(opts)
{: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()
```

See the [shape_stream_test.exs](https://github.com/electric-sql/electric-next/blob/thruflo/elixir-client/elixir_client/test/electric/client/shape_stream_test.exs) for more details.
It also has an [`Ecto`](https://hexdocs.pm/ecto) integration that will generate
updates based on an `Ecto` query:

```elixir
stream = Electric.Client.stream(client, from(t in MyTable, where: t.something == true))
```

See the [client documentation](https://hexdocs.pm/electric_client) for more details.

0 comments on commit 03226a2

Please sign in to comment.