Get value from ecto result

I am trying to get value from ecto result

can anybody help me to get an email from this


[%Hello.Comman.Users{__meta__: #Ecto.Schema.Metadata<:loaded, "users">,
  email: "test@email.com", id: 10, inserted_at: ~N[2018-01-16 17:14:57.000000],
  name: "john", password: "qwerty", status: "D",
  updated_at: ~N[2018-01-16 17:14:57.000000]}]

Maybe

iex> [head|tail] = [%Hello.Comman.Users{__meta__: #Ecto.Schema.Metadata<:loaded, "users">,
  email: "test@email.com", id: 10, inserted_at: ~N[2018-01-16 17:14:57.000000],
  name: "john", password: "qwerty", status: "D",
  updated_at: ~N[2018-01-16 17:14:57.000000]}]
iex> head.email

Perhaps if you only expect a single record to be returned you can use Repo.one to get back just a single record instead of a list.

1 Like