Phoenix.Sync (Phoenix.Sync v0.4.3)
View SourceReal-time sync for Postgres-backed Phoenix applications.
See the docs for more information.
Summary
Functions
Returns the required adapter configuration for your Phoenix Endpoint or
Plug.Router
.
Types
@type param_overrides() :: [param_override()]
@type shape_definition() :: String.t() | Ecto.Queryable.t() | shape_specification()
Functions
Returns the required adapter configuration for your Phoenix Endpoint or
Plug.Router
.
Phoenix
Configure your endpoint with the configuration at runtime by passing the
phoenix_sync
configuration to your endpoint in the Application.start/2
callback:
def start(_type, _args) do
children = [
# ...
{MyAppWeb.Endpoint, phoenix_sync: Phoenix.Sync.plug_opts()}
]
end
Plug
Add the configuration to the Plug opts in your server configuration:
children = [
{Bandit, plug: {MyApp.Router, phoenix_sync: Phoenix.Sync.plug_opts()}}
]
Your Plug.Router
must be configured with
copy_opts_to_assign
and you should use
the rele
defmodule MyApp.Router do
use Plug.Router, copy_opts_to_assign: :options
use Phoenix.Sync.Controller
use Phoenix.Sync.Router
plug :match
plug :dispatch
sync "/shapes/todos", Todos.Todo
get "/shapes/user-todos" do
%{"user_id" => user_id} = conn.params
sync_render(conn, from(t in Todos.Todo, where: t.owner_id == ^user_id)
end
end