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
Copy file name to clipboardExpand all lines: README.md
+67-23Lines changed: 67 additions & 23 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -69,9 +69,9 @@ defmodule MyWeb.MyLive do
69
69
end
70
70
```
71
71
72
-
LiveView takes care of automatically keeping the front-end up-to-date with the assigned stream. What Phoenix.Sync does is automatically keep the *stream* up-to-date with the state of the database.
72
+
LiveView takes care of automatically keeping the front-end up-to-date with the assigned stream. What Phoenix.Sync does is automatically keep the _stream_ up-to-date with the state of the database.
73
73
74
-
This means you can build fully end-to-end real-time multi-user applications without writing Javascript *and* without worrying about message delivery, reconnections, cache invalidation or polling the database for changes.
74
+
This means you can build fully end-to-end real-time multi-user applications without writing Javascript _and_ without worrying about message delivery, reconnections, cache invalidation or polling the database for changes.
75
75
76
76
### Sync shapes through your Router
77
77
@@ -94,7 +94,7 @@ defmodule MyWeb.Router do
94
94
end
95
95
```
96
96
97
-
Because the shapes are exposed through your Router, the client connects through your existing Plug middleware. This allows you to do real-time sync straight out of Postgres *without* having to translate your auth logic into complex/fragile database rules.
97
+
Because the shapes are exposed through your Router, the client connects through your existing Plug middleware. This allows you to do real-time sync straight out of Postgres _without_ having to translate your auth logic into complex/fragile database rules.
98
98
99
99
### Sync dynamic shapes from a Controller
100
100
@@ -120,46 +120,92 @@ This allows you to define and personalise the shape definition at runtime using
120
120
121
121
### Consume shapes in the frontend
122
122
123
-
You can sync *into* any client in any language that [speaks HTTP and JSON](https://electric-sql.com/docs/api/http).
123
+
You can sync _into_ any client in any language that [speaks HTTP and JSON](https://electric-sql.com/docs/api/http).
124
124
125
-
For example, using the Electric [Typescript client](https://electric-sql.com/docs/api/clients/typescript):
125
+
For example, using the Electric [sync_stream_updatescript client](https://electric-sql.com/docs/api/clients/typescript):
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 format, 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
+
157
203
## Installation and configuration
158
204
159
205
`Phoenix.Sync` can be used in two modes:
160
206
161
207
1.`:embedded` where Electric is included as an application dependency and Phoenix.Sync consumes data internally using Elixir APIs
162
-
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)
208
+
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)
0 commit comments