Can count records by genre

This commit is contained in:
Claudio Ortolina
2025-02-22 10:34:56 +00:00
parent 36d0d29316
commit 570ce4b145
+10
View File
@@ -71,6 +71,16 @@ defmodule MusicLibrary.Collection do
q |> Repo.all()
end
def count_records_by_genre do
q =
from r in fragment("records, json_each(records.genres)"),
group_by: r.value,
order_by: [desc: count(r.value)],
select: %{genre: r.value, count: count(r.value)}
q |> Repo.all()
end
defp base_search do
from r in SearchIndex,
where: not is_nil(r.purchased_at)