Skip to content

Conversation

@kzemek
Copy link

@kzemek kzemek commented Aug 25, 2017

By default, MariaEx doesn't distinguish between raw binaries and text strings. MariaEx query features an option binary_as that makes the library either treat all Elixir strings as raw binaries or as text. This option, however, is not easily accessible from Ecto and is not a solution when a query features both a raw binary and text string.

I've created a pull request xerions/mariaex#198 that allows passing Elixir string parameters wrapped in %Mariaex.TypedValue with an explicit type field (with a value of either :binary or :string) to remove ambiguity.

This PR leverages Ecto's knowledge of the model to inform MariaEx of the exact types of Elixir string parameters. The change is made in a backward-compatible way; Travis tests using updated MariaEx can be found here.

@sourcelevel-bot
Copy link

Hello, @kzemek! This is your first Pull Request that will be reviewed by Ebert, an automatic Code Review service. It will leave comments on this diff with potential issues and style violations found in the code as you push new commits. You can also see all the issues found on this Pull Request on its review page. Please check our documentation for more information.


## Custom MySQL types


Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be no more than 1 consecutive blank lines.

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)
Copy link
Member

Choose a reason for hiding this comment

The 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.

@behaviour Ecto.Adapter.Storage
@behaviour Ecto.Adapter.Structure

# Add dumpers functions if tagged values are supported by the driver
Copy link
Member

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.

@josevalim
Copy link
Member

We have added some comments, thank you!

@josevalim josevalim changed the title Use MariaEx typed binary and string if supported. Use MariaEx typed binary and string if supported Aug 25, 2017
@fishcakez
Copy link
Member

Please see my comment in the Mariaex issue, we should be using the type information sent back by the database to encode parameters instead of doing implicit casting. This should mean we can remove the binary_as option in Mariaex.

@fishcakez fishcakez closed this Aug 27, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants