In the @spec of query shows that it can return: %{rows: [binary()]}
but I did not found no example returning something similar, in which cases can I receive this kind of return?
Where?
@spec query(Ecto.Repo.t | Ecto.Adapter.adapter_meta, String.t, [term], Keyword.t) ::
{:ok, %{:rows => nil | [[term] | binary],
:num_rows => non_neg_integer,
optional(atom) => any}}
| {:error, Exception.t}
Example:
$ iex -S mix
Erlang/OTP 21 [erts-10.3.4] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [hipe] [dtrace]
Interactive Elixir (1.8.1) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> {:ok, ecto_result} = Ecto.Adapters.SQL.query(Repo, "select * from artists where id=1")
08:39:49.463 [debug] QUERY OK db=6.3ms decode=0.9ms queue=1.0ms
select * from artists where id=1 []
{:ok, %Postgrex.Result{
columns: ["id", "name", "birth_date", "death_date", "inserted_at", "updated_at"],
command: :select,
connection_id: 3304,
messages: [],
num_rows: 1,
rows: [
[
1,
"Miles Davis",
nil,
nil,
~N[2019-05-03 00:16:32.000000],
~N[2019-05-03 00:16:32.000000]
]
]
}}
iex(2)> result = Map.take(ecto_result, [:rows])
%{
rows: [
[
1,
"Miles Davis",
nil,
nil,
~N[2019-05-03 00:16:32.000000],
~N[2019-05-03 00:16:32.000000]
]
]
}
iex(3)>
@peerreynders in your example you received: rows: [list()]
, my question is how I can obtain: rows: [binary()]
In @spec %{:rows => nil | [[term] | binary]
how that can return rows: [binary]
You stated that the spec specified %{rows: [binary()]}
- that is incorrect.
My example just extracted the %{:rows => nil | [[term] | binary]}
that is part of the spec.
Is your question:
Under what circumstances will %{rows: [binary]}
be returned?
(i.e. a binary
instead of the typical [term]
)
Edit: updated topic title
I did not say it is incorrect, but I did not find any place returning or explaining how to return rows: [binary]
Under what circumstances will %{rows: [binary]}
be returned? Yes, this is my question, Sorry if I was not clear.