ArangoXEcto.raw_to_struct
You're seeing just the function
raw_to_struct
, go back to ArangoXEcto module for more information.
Specs
raw_to_struct(map() | [map()], Ecto.Schema.t()) :: struct()
Converts raw output of a query into a struct
Transforms string map arguments into atom key map, adds id key and drops _id
, _key
and _rev
keys.
Then it creates a struct from filtered arguments using module.
If a list of maps are passed then the maps are enumerated over.
Parameters
maps
- List of maps or singular map to convert to a structmodule
- Module to use for the struct
Example
iex> {:ok, users} = ArangoXEcto.aql_query(
Repo,
"FOR user IN users RETURN user"
)
{:ok,
[
%{
"_id" => "users/12345",
"_key" => "12345",
"_rev" => "_bHZ8PAK---",
"first_name" => "John",
"last_name" => "Smith"
}
]}
iex> ArangoXEcto.raw_to_struct(users, User)
[
%User{
id: "12345",
first_name: "John",
last_name: "Smith"
}
]