Support filtering by type

This commit is contained in:
Claudio Ortolina
2024-10-14 22:30:14 +01:00
parent 5e7280176f
commit 7a0d017965
3 changed files with 53 additions and 1 deletions
+12
View File
@@ -60,6 +60,9 @@ defmodule MusicLibrary.Records do
{:format, format}, search ->
search |> where([r], r.format == ^format)
{:type, type}, search ->
search |> where([r], r.type == ^type)
{:query, raw_query}, search ->
search
|> where(
@@ -82,6 +85,15 @@ defmodule MusicLibrary.Records do
Repo.all(q)
end
def count_records_by_type do
q =
from r in Record,
group_by: r.type,
select: {r.type, count(r.id)}
Repo.all(q)
end
def get_record!(id), do: Repo.get!(Record, id)
def get_latest_record! do