ElectricSQL logo

License - Apache 2.0Status - AlphaChat - Discord

Elixir client for ElectricSQL

Real-time Postgres sync for modern apps.

Electric provides an HTTP interface to Postgres to enable a massive number of clients to query and get real-time updates to subsets of the database, called Shapes. In this way, Electric turns Postgres into a real-time database.

The Elixir client helps ease reading Shapes from the HTTP API in Elixir applications.

Installation

def deps do
  [
    {:electric_client, "~> 0.1.0"}
  ]
end

Usage

{:ok, client} = Electric.Client.new(base_url: "http://localhost:3000")

incomplete_todos = Electric.Client.shape("todos", where: "completed = false")

# Passing `live: false` means the stream will terminate once it's reached
# the head of the update log from Electric.
#
# Without `live: false` the stream is infinite.
stream = Electric.Client.stream(client, incomplete_todos, live: false)

messages = Enum.into(stream, [])

See the Documentation.

Testing

Run Electric and Postgres.

Define DATABASE_URL and ELECTRIC_URL as env vars. Or see the defaults in config/runtime.exs.

Then run:

mix test