-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Use MariaEx typed binary and string if supported #2183
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
Closed
Closed
Changes from all commits
Commits
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
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 |
|---|---|---|
|
|
@@ -110,6 +110,32 @@ defmodule Ecto.Adapters.MySQL do | |
| @behaviour Ecto.Adapter.Storage | ||
| @behaviour Ecto.Adapter.Structure | ||
|
|
||
| # Add dumpers functions if tagged values are supported by the driver | ||
| try do | ||
| DBConnection.Query.encode( | ||
| %Mariaex.Query{type: :binary, num_params: 1}, | ||
| [%{__struct__: Mariaex.TypedValue, type: :binary, value: <<3, 2, 1>>}], []) | ||
|
|
||
| @doc false | ||
| def dumpers(:binary, type), do: [type, &encode_binary/1] | ||
| def dumpers(:string, type), do: [type, &encode_string/1] | ||
| def dumpers(type_a, type_b), do: super(type_a, type_b) | ||
|
|
||
| defp additional_loaders(:binary, type), do: [&decode_binary/1, type] | ||
| defp additional_loaders(:string, type), do: [&decode_binary/1, type] | ||
| defp additional_loaders(_, type), do: [type] | ||
|
|
||
| defp encode_binary(bin), do: {:ok, encode_typed(:binary, bin)} | ||
| defp encode_string(bin), do: {:ok, encode_typed(:string, bin)} | ||
| defp encode_typed(type, val), do: %Mariaex.TypedValue{type: type, value: val} | ||
|
|
||
| defp decode_binary(%{"value" => val}) when is_binary(val), do: {:ok, val} | ||
| defp decode_binary(val) when is_binary(val), do: {:ok, val} | ||
| catch | ||
| _, _ -> | ||
| defp additional_loaders(_, type), do: [type] | ||
| end | ||
|
|
||
| ## Custom MySQL types | ||
|
|
||
| @doc false | ||
|
|
@@ -119,7 +145,7 @@ defmodule Ecto.Adapters.MySQL do | |
| def loaders(:float, type), do: [&float_decode/1, type] | ||
| def loaders(:binary_id, type), do: [Ecto.UUID, type] | ||
| def loaders({:embed, _} = type, _), do: [&json_decode/1, &Ecto.Adapters.SQL.load_embed(type, &1)] | ||
| def loaders(_, type), do: [type] | ||
| def loaders(type_a, type_b), do: additional_loaders(type_a, type_b) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All the loaders are inlined for the reasons of efficiency. This code is called very often, even a function call is a big overhead here - we should avoid it, if we can. |
||
|
|
||
| defp bool_decode(<<0>>), do: {:ok, false} | ||
| defp bool_decode(<<1>>), do: {:ok, true} | ||
|
|
||
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need the conditional here, instead we should change "mix.exs" to the minimum Mariaex version that supports this feature.