-
Notifications
You must be signed in to change notification settings - Fork 306
feat(elixir-client): Add Move-In/Out Support for Subqueries in Elixir Client #3699
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
dd58340
Fix empty error array handling in stream
robacourt a635505
Fix resume to use live requests for long-polling
robacourt 0bf0f39
Increase Postgres max_connections for tests
robacourt 6943438
Reduce default connection pool size and add override tags
robacourt fa890fa
Add integration test infrastructure and basic streaming tests
robacourt e40b491
Guard Ecto-dependent code with Code.ensure_loaded?
robacourt 0631be3
Implement move-out support for subqueries in Elixir client
robacourt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| '@core/elixir-client': patch | ||
| '@core/sync-service': patch | ||
| --- | ||
|
|
||
| Add Move-Out Support for Subqueries in Elixir Client |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
132 changes: 67 additions & 65 deletions
132
packages/elixir-client/lib/electric/client/ecto_adapter/array_decoder.ex
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,92 +1,94 @@ | ||
| defmodule Electric.Client.EctoAdapter.ArrayDecoder do | ||
| alias Electric.Client.EctoAdapter | ||
| if Code.ensure_loaded?(Ecto) do | ||
| defmodule Electric.Client.EctoAdapter.ArrayDecoder do | ||
| alias Electric.Client.EctoAdapter | ||
|
|
||
| def decode!("{}", _type), do: [] | ||
| def decode!("{}", _type), do: [] | ||
|
|
||
| def decode!(encoded_array, type) when is_binary(encoded_array) do | ||
| {"", [result]} = | ||
| decode_array(encoded_array, [], {EctoAdapter.cast_to(type), type, encoded_array}) | ||
| def decode!(encoded_array, type) when is_binary(encoded_array) do | ||
| {"", [result]} = | ||
| decode_array(encoded_array, [], {EctoAdapter.cast_to(type), type, encoded_array}) | ||
|
|
||
| result | ||
| end | ||
| result | ||
| end | ||
|
|
||
| ############################## | ||
| ############################## | ||
|
|
||
| defp decode_array("", acc, _state) do | ||
| {"", :lists.reverse(acc)} | ||
| end | ||
| defp decode_array("", acc, _state) do | ||
| {"", :lists.reverse(acc)} | ||
| end | ||
|
|
||
| defp decode_array(<<"{}", rest::bitstring>>, acc, state) do | ||
| decode_array(rest, [[] | acc], state) | ||
| end | ||
| defp decode_array(<<"{}", rest::bitstring>>, acc, state) do | ||
| decode_array(rest, [[] | acc], state) | ||
| end | ||
|
|
||
| defp decode_array(<<"{", rest::bitstring>>, acc, state) do | ||
| {rest, array} = decode_array(rest, [], state) | ||
| decode_array(rest, [array | acc], state) | ||
| end | ||
| defp decode_array(<<"{", rest::bitstring>>, acc, state) do | ||
| {rest, array} = decode_array(rest, [], state) | ||
| decode_array(rest, [array | acc], state) | ||
| end | ||
|
|
||
| defp decode_array(<<"}", rest::bitstring>>, acc, _state) do | ||
| {rest, :lists.reverse(acc)} | ||
| end | ||
| defp decode_array(<<"}", rest::bitstring>>, acc, _state) do | ||
| {rest, :lists.reverse(acc)} | ||
| end | ||
|
|
||
| defp decode_array(<<?,, rest::bitstring>>, acc, state) do | ||
| decode_array(rest, acc, state) | ||
| end | ||
| defp decode_array(<<?,, rest::bitstring>>, acc, state) do | ||
| decode_array(rest, acc, state) | ||
| end | ||
|
|
||
| defp decode_array(<<?", rest::bitstring>>, acc, state) do | ||
| {rest, elem} = decode_quoted_elem(rest, [], state) | ||
| decode_array(rest, [elem | acc], state) | ||
| end | ||
| defp decode_array(<<?", rest::bitstring>>, acc, state) do | ||
| {rest, elem} = decode_quoted_elem(rest, [], state) | ||
| decode_array(rest, [elem | acc], state) | ||
| end | ||
|
|
||
| defp decode_array(rest, acc, state) do | ||
| {rest, elem} = decode_elem(rest, [], state) | ||
| decode_array(rest, [elem | acc], state) | ||
| end | ||
| defp decode_array(rest, acc, state) do | ||
| {rest, elem} = decode_elem(rest, [], state) | ||
| decode_array(rest, [elem | acc], state) | ||
| end | ||
|
|
||
| ############################## | ||
| ############################## | ||
|
|
||
| defp decode_elem(<<",", _::bitstring>> = rest, acc, state), | ||
| do: {rest, cast(acc, state)} | ||
| defp decode_elem(<<",", _::bitstring>> = rest, acc, state), | ||
| do: {rest, cast(acc, state)} | ||
|
|
||
| defp decode_elem(<<"}", _::bitstring>> = rest, acc, state), | ||
| do: {rest, cast(acc, state)} | ||
| defp decode_elem(<<"}", _::bitstring>> = rest, acc, state), | ||
| do: {rest, cast(acc, state)} | ||
|
|
||
| defp decode_elem(<<c::utf8, rest::bitstring>>, acc, state), | ||
| do: decode_elem(rest, [acc | <<c::utf8>>], state) | ||
| defp decode_elem(<<c::utf8, rest::bitstring>>, acc, state), | ||
| do: decode_elem(rest, [acc | <<c::utf8>>], state) | ||
|
|
||
| defp decode_elem("", _acc, {_cast_fun, type, source}) do | ||
| raise Ecto.CastError, type: {:array, type}, value: source | ||
| end | ||
| defp decode_elem("", _acc, {_cast_fun, type, source}) do | ||
| raise Ecto.CastError, type: {:array, type}, value: source | ||
| end | ||
|
|
||
| ############################## | ||
| ############################## | ||
|
|
||
| defp decode_quoted_elem(<<?", rest::bitstring>>, acc, state), | ||
| do: {rest, cast_quoted(acc, state)} | ||
| defp decode_quoted_elem(<<?", rest::bitstring>>, acc, state), | ||
| do: {rest, cast_quoted(acc, state)} | ||
|
|
||
| defp decode_quoted_elem(<<"\\\"", rest::bitstring>>, acc, state), | ||
| do: decode_quoted_elem(rest, [acc | [?"]], state) | ||
| defp decode_quoted_elem(<<"\\\"", rest::bitstring>>, acc, state), | ||
| do: decode_quoted_elem(rest, [acc | [?"]], state) | ||
|
|
||
| defp decode_quoted_elem(<<c::utf8, rest::bitstring>>, acc, state), | ||
| do: decode_quoted_elem(rest, [acc | <<c::utf8>>], state) | ||
| defp decode_quoted_elem(<<c::utf8, rest::bitstring>>, acc, state), | ||
| do: decode_quoted_elem(rest, [acc | <<c::utf8>>], state) | ||
|
|
||
| defp decode_quoted_elem("", _acc, {_cast_fun, type, source}) do | ||
| raise Ecto.CastError, type: {:array, type}, value: source | ||
| end | ||
| defp decode_quoted_elem("", _acc, {_cast_fun, type, source}) do | ||
| raise Ecto.CastError, type: {:array, type}, value: source | ||
| end | ||
robacourt marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| ############################## | ||
| ############################## | ||
|
|
||
| defp cast(iodata, {cast_fun, _type, _source}) do | ||
| iodata | ||
| |> IO.iodata_to_binary() | ||
| |> case do | ||
| "NULL" -> nil | ||
| value -> cast_fun.(value) | ||
| defp cast(iodata, {cast_fun, _type, _source}) do | ||
| iodata | ||
| |> IO.iodata_to_binary() | ||
| |> case do | ||
| "NULL" -> nil | ||
| value -> cast_fun.(value) | ||
| end | ||
| end | ||
| end | ||
|
|
||
| defp cast_quoted(iodata, {cast_fun, _type, _source}) do | ||
| iodata | ||
| |> IO.iodata_to_binary() | ||
| |> cast_fun.() | ||
| defp cast_quoted(iodata, {cast_fun, _type, _source}) do | ||
| iodata | ||
| |> IO.iodata_to_binary() | ||
| |> cast_fun.() | ||
| end | ||
| end | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.