View Source Ecto.DevLogger.PrintableParameter protocol (ecto_dev_logger v0.10.0)
A protocol to print various data structures as valid SQL expressions.
to_expression/1
is the main function and to_string_literal/1
is an optional helper for it.
Ecto.DevLogger
tries to represent complex terms, like arrays (lists) and composite types (tuples)
as string literal first. Not all terms are easy/efficient/whatever to represent as strings, so if
to_string_literal/1
returns a string for all elements inside the array,
then array will be represented as string as well. Otherwise, array will be represented using ARRAY
constructor:
iex> Ecto.DevLogger.PrintableParameter.to_expression(["Elixir", "Ecto"])
"'{Elixir,Ecto}'"
iex> Ecto.DevLogger.PrintableParameter.to_expression(["Elixir", "Ecto", <<153>>])
"ARRAY['Elixir','Ecto',DECODE('mQ==','BASE64')]"
The same is true for composite types (tuples):
iex> Ecto.DevLogger.PrintableParameter.to_expression({"Elixir", "Ecto"})
"'(Elixir,Ecto)'"
iex> Ecto.DevLogger.PrintableParameter.to_expression({"Elixir", "Ecto", <<153>>})
"ROW('Elixir','Ecto',DECODE('mQ==','BASE64'))"
Link to this section Summary
Link to this section Types
@type t() :: term()
Link to this section Functions
Converts term to a valid SQL expression.
Converts term to a string literal.