Skip to content

Instantly share code, notes, and snippets.

@mazz mazz/iex.log
Created May 21, 2019

Embed
What would you like to do?
iex(2)> import Ecto.Query
Ecto.Query
iex(3)> Video |> select([v], v.id)
#Ecto.Query<from v0 in DB.Schema.Video, select: v0.id>
iex(4)> Video |> select([v], v.id) |> DB.Repo.all()
[debug] QUERY OK source="videos" db=1.9ms decode=2.6ms queue=6.5ms
SELECT v0."id" FROM "videos" AS v0 []
[1]
iex(5)> Video |> select([v], v.id) |> DB.Repo.all() |> Enum.map(&Video.changeset_generate_hash_id/1)
[debug] QUERY OK source="videos" db=0.3ms
SELECT v0."id" FROM "videos" AS v0 []
** (FunctionClauseError) no function clause matching in DB.Schema.Video.changeset_generate_hash_id/1
The following arguments were given to DB.Schema.Video.changeset_generate_hash_id/1:
# 1
1
Attempted function clauses (showing 1 out of 1):
def changeset_generate_hash_id(video = %{id: id})
(db) lib/db_schema/video.ex:157: DB.Schema.Video.changeset_generate_hash_id/1
(elixir) lib/enum.ex:1327: Enum."-map/2-lists^map/1-0-"/2
iex(5)> DB.Schema.Video.changeset_generate_hash_id(%DB.Schema.Video{id: 42, hash_id: nil})
#Ecto.Changeset<
action: nil,
changes: %{hash_id: "GMAA"},
errors: [],
data: #DB.Schema.Video<>,
valid?: true
>
iex(6)>
def changeset_generate_hash_id(video = %{id: id}) do
change(video, hash_id: VideoHashId.encode(id))
end
@mazz

This comment has been minimized.

Copy link
Owner Author

commented May 21, 2019

Video |> select([v], map(v, [:id])) |> DB.Repo.all()

[debug] QUERY OK source="videos" db=2.0ms queue=1.8ms
SELECT v0."id" FROM "videos" AS v0 []
[%{id: 1}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.