Skip to content

Commit 1fe3f1f

Browse files
committed
first version
mostly api-complete, but lacking docs and a bit rough around the edges
1 parent d9bef76 commit 1fe3f1f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+5409
-25
lines changed

.formatter.exs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
locals_without_parens = [
2+
# Electric.Phoenix.Router
3+
sync: 1,
4+
sync: 2,
5+
sync: 3
6+
]
7+
8+
[
9+
locals_without_parens: locals_without_parens,
10+
export: [locals_without_parens: locals_without_parens],
11+
import_deps: [:plug, :phoenix, :ecto],
12+
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"]
13+
]

.github/workflows/elixir_tests.yml

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
name: Elixir CI
2+
3+
on:
4+
push:
5+
branches: ["main"]
6+
paths-ignore:
7+
- "**/README.md"
8+
pull_request:
9+
paths-ignore:
10+
- "**/README.md"
11+
12+
permissions:
13+
contents: read
14+
15+
jobs:
16+
test:
17+
name: mix test
18+
runs-on: ubuntu-latest
19+
env:
20+
MIX_ENV: test
21+
steps:
22+
- uses: actions/checkout@v4
23+
24+
- uses: erlef/setup-beam@v1
25+
with:
26+
version-type: strict
27+
version-file: ".tool-versions"
28+
29+
- name: Cache dependencies
30+
uses: actions/cache@v4
31+
with:
32+
path: deps
33+
key: ${{ runner.os }}-deps-${{ hashFiles('mix.lock') }}
34+
restore-keys: |
35+
${{ runner.os }}-deps-${{ hashFiles('mix.lock') }}
36+
${{ runner.os }}-deps-
37+
38+
- name: Cache build
39+
uses: actions/cache@v4
40+
with:
41+
path: |
42+
_build/*/lib
43+
!_build/*/lib/electric_phoenix
44+
key: ${{ runner.os }}-build-${{ env.MIX_ENV }}-[${{ github.ref_name }}]-${{ github.sha }}
45+
restore-keys: |
46+
${{ runner.os }}-build-${{ env.MIX_ENV }}-[${{ github.ref_name }}]-${{ github.sha }}
47+
${{ runner.os }}-build-${{ env.MIX_ENV }}-[${{ github.ref_name }}]-
48+
${{ runner.os }}-build-${{ env.MIX_ENV }}-
49+
${{ runner.os }}-build-
50+
51+
- name: Install dependencies
52+
run: mix deps.get && mix deps.compile
53+
54+
- name: Compiles without warnings
55+
run: mix compile --force --all-warnings --warnings-as-errors
56+
57+
- name: Run tests
58+
run: mix test --trace
59+
60+
formatting:
61+
name: mix format --check-formatted
62+
runs-on: ubuntu-latest
63+
env:
64+
MIX_ENV: test
65+
steps:
66+
- uses: actions/checkout@v4
67+
- uses: erlef/setup-beam@v1
68+
with:
69+
version-type: strict
70+
version-file: ".tool-versions"
71+
- name: Restore dependencies cache
72+
uses: actions/cache/restore@v4
73+
with:
74+
path: deps
75+
key: ${{ runner.os }}-deps-${{ hashFiles('mix.lock') }}
76+
restore-keys: |
77+
${{ runner.os }}-deps-${{ hashFiles('mix.lock') }}
78+
${{ runner.os }}-deps-
79+
- run: mix deps.get
80+
- run: mix format --check-formatted

.gitignore

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# The directory Mix will write compiled artifacts to.
2+
/_build/
3+
4+
# If you run "mix test --cover", coverage assets end up here.
5+
/cover/
6+
7+
# The directory Mix downloads your dependencies sources to.
8+
/deps/
9+
10+
# Where third-party dependencies like ExDoc output generated docs.
11+
/doc/
12+
13+
# Ignore .fetch files in case you like to edit your project deps locally.
14+
/.fetch
15+
16+
# If the VM crashes, it generates a dump, let's ignore it too.
17+
erl_crash.dump
18+
19+
# Also ignore archive artifacts (built via "mix archive.build").
20+
*.ez
21+
22+
# Ignore package tarball (built via "mix hex.build").
23+
electric_phoenix-*.tar
24+
25+
# Temporary files, for example, from tests.
26+
/tmp/

.tool-versions

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
elixir 1.18.1-otp-27
2+
erlang 27.2

LICENSE

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
Apache License
23
Version 2.0, January 2004
34
http://www.apache.org/licenses/
@@ -174,28 +175,3 @@
174175
of your accepting any such warranty or additional liability.
175176

176177
END OF TERMS AND CONDITIONS
177-
178-
APPENDIX: How to apply the Apache License to your work.
179-
180-
To apply the Apache License to your work, attach the following
181-
boilerplate notice, with the fields enclosed by brackets "[]"
182-
replaced with your own identifying information. (Don't include
183-
the brackets!) The text should be enclosed in the appropriate
184-
comment syntax for the file format. We also recommend that a
185-
file or class name and description of purpose be included on the
186-
same "printed page" as the copyright notice for easier
187-
identification within third-party archives.
188-
189-
Copyright [yyyy] [name of copyright owner]
190-
191-
Licensed under the Apache License, Version 2.0 (the "License");
192-
you may not use this file except in compliance with the License.
193-
You may obtain a copy of the License at
194-
195-
http://www.apache.org/licenses/LICENSE-2.0
196-
197-
Unless required by applicable law or agreed to in writing, software
198-
distributed under the License is distributed on an "AS IS" BASIS,
199-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200-
See the License for the specific language governing permissions and
201-
limitations under the License.

README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<p align="center">
2+
<a href="https://electric-sql.com" target="_blank">
3+
<picture>
4+
<source media="(prefers-color-scheme: dark)"
5+
srcset="https://raw.githubusercontent.com/electric-sql/meta/main/identity/ElectricSQL-logo-next.svg"
6+
/>
7+
<source media="(prefers-color-scheme: light)"
8+
srcset="https://raw.githubusercontent.com/electric-sql/meta/main/identity/ElectricSQL-logo-black.svg"
9+
/>
10+
<img alt="ElectricSQL logo"
11+
src="https://raw.githubusercontent.com/electric-sql/meta/main/identity/ElectricSQL-logo-black.svg"
12+
/>
13+
</picture>
14+
</a>
15+
</p>
16+
17+
# Phoenix.Sync
18+
19+
An adapter to integrate [Electric SQL's sync engine](https://electric-sql.com)
20+
into [Phoenix web applications](https://www.phoenixframework.org/).
21+
22+
Documentation available at <https://hexdocs.pm/phoenix_sync/>.
23+
24+
## Installation
25+
26+
Install by adding `phoenix_sync` to your list of dependencies in `mix.exs`:
27+
28+
```elixir
29+
def deps do
30+
[
31+
{:phoenix_sync, "~> 0.1.0"}
32+
]
33+
end
34+
```

config/config.exs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import Config
2+
3+
import_config "#{config_env()}.exs"

config/dev.exs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import Config

config/runtime.exs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import Config
2+
3+
config :logger, level: :warning
4+
5+
if config_env() == :test do
6+
# port = 3333
7+
default_database_url = "postgresql://postgres:password@localhost:54321/electric?sslmode=disable"
8+
database_url = System.get_env("DATABASE_URL", default_database_url)
9+
10+
connection_opts = Electric.Config.parse_postgresql_uri!(database_url)
11+
12+
# default_electric_url = "http://localhost:#{port}"
13+
14+
# config :electric_client,
15+
# database_config: connection_opts,
16+
# electric_url: electric_url
17+
18+
# config :electric_client, Support.Repo, url: database_url
19+
20+
config :electric,
21+
start_in_library_mode: true,
22+
connection_opts: Electric.Utils.obfuscate_password(connection_opts),
23+
# enable the http api so that the client tests against a real endpoint can
24+
# run against our embedded electric instance.
25+
# enable_http_api: true,
26+
# service_port: port,
27+
allow_shape_deletion?: false,
28+
# use a non-default replication stream id so we can run the client
29+
# tests at the same time as an active electric instance
30+
replication_stream_id: "phoenix_sync_tests",
31+
storage_dir: Path.join(System.tmp_dir!(), "electric/client-tests#{System.monotonic_time()}")
32+
end

config/test.exs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import Config
2+
3+
config :logger, level: :critical
4+
5+
config :phoenix_sync, mode: :disabled
6+
7+
config :phoenix_sync, Phoenix.Sync.LiveViewTest.Endpoint, []
8+
9+
config :phoenix_sync, Electric.Client, base_url: "http://localhost:3000"
10+
11+
# configure the support repo with random options so we can validate them in Phoenix.Sync.ConfigTest
12+
config :phoenix_sync, Support.Repo,
13+
username: "postgres",
14+
password: "password",
15+
hostname: "localhost",
16+
database: "electric",
17+
port: 54321,
18+
stacktrace: true,
19+
show_sensitive_data_on_connection_error: true,
20+
pool_size: 10
21+
22+
config :phoenix_sync, Support.ConfigTestRepo,
23+
username: "postgres",
24+
password: "password",
25+
hostname: "localhost",
26+
database: "electric",
27+
port: 54321,
28+
stacktrace: true,
29+
show_sensitive_data_on_connection_error: true,
30+
ssl: true,
31+
socket_options: [:inet6],
32+
pool_size: 10

0 commit comments

Comments
 (0)