Skip to content

Commit 33a9af0

Browse files
authored
feat: Add phoenix_sync.install igniter task (#93)
1 parent 827b0b8 commit 33a9af0

File tree

6 files changed

+1104
-8
lines changed

6 files changed

+1104
-8
lines changed

.github/workflows/elixir_tests.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ jobs:
6868
${{ runner.os }}-build-${{ env.MIX_ENV }}-
6969
${{ runner.os }}-build-
7070
71+
# needed for the igniter tests
72+
- name: Install phx.new task
73+
run: mix archive.install hex phx_new --force
74+
7175
- name: Install dependencies
7276
run: mix deps.get && mix deps.compile
7377

README.md

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -203,11 +203,44 @@ See the `Phoenix.Sync.Writer` module docs for more information.
203203
`Phoenix.Sync` can be used in two modes:
204204

205205
1. `:embedded` where Electric is included as an application dependency and Phoenix.Sync consumes data internally using Elixir APIs
206-
2. `:http` where Electric does _not_ need to be included as an application dependency and Phoenix.Sync consumes data from an external Electric service using it's [HTTP API](https://electric-sql.com/docs/api/http)
207206

208-
### Embedded mode
207+
In `:embedded` mode, Electric does not expose an HTTP API (internally or externally). Messages are streamed internally between Electric and Phoenix.Sync using Elixir function APIs. The only HTTP API for sync is that exposed via your Phoenix Router using the `sync/2` macro and `sync_render/3` function.
209208

210-
In `:embedded` mode, Electric must be included an application dependency but does not expose an HTTP API (internally or externally). Messages are streamed internally between Electric and Phoenix.Sync using Elixir function APIs. The only HTTP API for sync is that exposed via your Phoenix Router using the `sync/2` macro and `sync_render/3` function.
209+
2. `:http` where Electric does _not_ need to be included as an application dependency and Phoenix.Sync consumes data from an external Electric service using it's [HTTP API](https://electric-sql.com/docs/api/http). As for `embedded` mode, the only HTTP API for sync is that exposed via `Phoenix.Sync.Router.sync/2` and `Phoenix.Sync.Controller.sync_render/3`.
210+
211+
### Using Igniter
212+
213+
`Phoenix.Sync` supports [`Igniter`](https://hexdocs.pm/igniter/readme.html) for automatic configuration of your application.
214+
215+
Add Igniter to an existing Elixir project by adding it to your dependencies in mix.exs:
216+
217+
```elixir
218+
{:igniter, "~> 0.6", only: [:dev, :test]}
219+
```
220+
221+
Then use it to install `Phoenix.Sync` in `embedded` mode:
222+
223+
```elixir
224+
mix igniter.install phoenix_sync --sync-mode embedded
225+
```
226+
227+
This will install `Phoenix.Sync` into your application and also set up your `Ecto.Repo` with the [sandbox test adapter](`Phoenix.Sync.Sandbox`).
228+
229+
If you don't want the sandbox support then pass `--no-sync-sandbox`:
230+
231+
```elixir
232+
mix igniter.install phoenix_sync --sync-mode embedded --no-sync-sandbox
233+
```
234+
235+
For `http` mode:
236+
237+
```elixir
238+
mix igniter.install phoenix_sync --sync-mode http --sync-url "https://api.electric-sql.cloud"
239+
```
240+
241+
### Manual installation
242+
243+
#### Embedded mode
211244

212245
Example config:
213246

@@ -234,9 +267,7 @@ children = [
234267
]
235268
```
236269

237-
### HTTP
238-
239-
In `:http` mode, Electric does not need to be included as an application dependency. Instead, Phoenix.Sync consumes data from an external Electric service over HTTP.
270+
#### HTTP mode
240271

241272
```elixir
242273
# mix.exs

0 commit comments

Comments
 (0)