Created
May 21, 2019 14:14
-
-
Save mazz/b7380242faf8defba6e5a5101fcd8491 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def changeset_generate_hash_id(video = %{id: id}) do | |
change(video, hash_id: VideoHashId.encode(id)) | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Video |> select([v], map(v, [:id])) |> DB.Repo.all()