electric
electric copied to clipboard
Support mapping change stream to an Ecto.Schema embedded struct
Currently we only support db-backed ecto.schemas, but we can leverage the type casting powers of ecto by supporting embedded schemas and mapping any data to ecto schema structs
defmodule MyModel do
use Ecto.Schema
embedded_schema do
field :name, :string
field :value, :integer
end
end
{:ok, client} = Electric.Client.new(base_url: "http://localhost:3000")
stream = Electric.Client.stream(client, "model", schema: MyModel)
This separates the pg table from the local data structures, which may not have a pg connection or any db-backed ecto schemas but allows for receiving nice %MyModel{} structs from the stream.