You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Query support is currently limited to only `where` conditions. Support for more complex queries, including `JOIN`s is planned.
173
-
174
-
**Note:** The static shapes defined using the `sync/2` or `sync/3` router macros do not accept `Ecto.Query` structs as a shape definition. This is to avoid excessive recompilation caused by having your router having a compile-time dependency on your `Ecto` schemas.
175
-
176
-
If you want to add a where-clause filter to a static shape in your router, you must add an explicit [`where` clause](https://electric-sql.com/docs/guides/shapes#where-clause) alongside your `Ecto.Schema` module:
At minimum a shape requires a `table`. You can think of shapes defined with
193
-
just a table name as the sync-equivalent of `SELECT * FROM table`.
194
-
195
-
The available options are:
196
-
197
-
-`table` (required). The Postgres table name. Be aware of casing and [Postgres's handling of unquoted upper-case names](https://wiki.postgresql.org/wiki/Don%27t_Do_This#Don.27t_use_upper_case_table_or_column_names).
198
-
-`namespace` (optional). The Postgres namespace that the table belongs to. Defaults to `public`.
199
-
-`where` (optional). Filter to apply to the synced data in SQL syntax, e.g. `where: "amount < 1.23 AND colour in ('red', 'green')`.
200
-
-`columns` (optional). The columns to include in the synced data. By default Electric will include all columns in the table. The column list **must** include all primary keys. E.g. `columns: ["id", "title", "amount"]`.
201
-
-`replica` (optional). By default Electric will only send primary keys + changed columns on updates. Set `replica: :full` to receive the full row, not just the changed columns.
202
-
203
155
## Installation and configuration
204
156
205
157
`Phoenix.Sync` can be used in two modes:
@@ -363,5 +315,60 @@ Phoenix.Sync uses Electric to handle the core concerns of partial replication, f
363
315
364
316
Electric defines partial replication using [Shapes](https://electric-sql.com/docs/guides/shapes).
365
317
318
+
### Shape definitions
319
+
320
+
Phoenix.Sync allows shapes to be defined in two ways:
321
+
322
+
1. using an `Ecto.Query` (or `Ecto.Schema` module)
323
+
2. using a keyword list
324
+
325
+
### Using an `Ecto.Query`
326
+
366
327
Phoenix.Sync maps Ecto queries to shape definitions. This allows you to control what data syncs where using Ecto.Schema and Ecto.Query.
Or using a schema (equivalent to `from(t in Todos.Todo)`):
336
+
337
+
```elixir
338
+
sync_render(conn, params, Todos.Todo)
339
+
```
340
+
341
+
Query support is currently limited to `where` conditions. Support for more complex queries using `join`, `order_by`, `limit` and preloaded association graphs is planned and will be added in Q2 2025.
342
+
343
+
The static shapes defined using the `sync/2` or `sync/3` router macros do not accept `Ecto.Query` structs as a shape definition. This is to avoid excessive recompilation caused by your router having a compile-time dependency on your `Ecto` schemas.
344
+
345
+
If you want to add a where-clause filter to a static shape in your router, you can add an explicit [`where` clause](https://electric-sql.com/docs/guides/shapes#where-clause) alongside your `Ecto.Schema` module:
For anything else more dyanamic, or to use Ecto queries, you should switch from using the `sync` macros in your router to using `sync_render/3` in a controller.
360
+
361
+
### Using a keyword list
362
+
363
+
At minimum a shape requires a `table`. You can think of shapes defined with
364
+
just a table name as the sync-equivalent of `SELECT * FROM table`.
365
+
366
+
The available options are:
367
+
368
+
-`table` (required). The Postgres table name. Be aware of casing and [Postgres's handling of unquoted upper-case names](https://wiki.postgresql.org/wiki/Don%27t_Do_This#Don.27t_use_upper_case_table_or_column_names).
369
+
-`namespace` (optional). The Postgres namespace that the table belongs to. Defaults to `public`.
370
+
-`where` (optional). Filter to apply to the synced data in SQL format, e.g. `where: "amount < 1.23 AND colour in ('red', 'green')`.
371
+
-`columns` (optional). The columns to include in the synced data. By default Electric will include all columns in the table. The column list **must** include all primary keys. E.g. `columns: ["id", "title", "amount"]`.
372
+
-`replica` (optional). By default Electric will only send primary keys + changed columns on updates. Set `replica: :full` to receive the full row, not just the changed columns.
373
+
374
+
See the [Electric Shapes guide](https://electric-sql.com/docs/guides/shapes) for more information.
0 commit comments