Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
# ** (Ecto.Query.CompileError) Tuples can only be used in comparisons with literal tuples of the same size
def search(query_string, offset \\ 0, limit \\ 0,
media_category,
playlist_uuid,
channel_uuid,
published_after
) do
conditions = false
conditions =
if media_category do
dynamic([mi], mi.media_category == ^media_category or ^conditions)
else
conditions
end
conditions =
if published_after do
{:ok, datetime} = DateTime.from_unix(published_after, :second)
erl_datetime = NaiveDateTime.to_erl(datetime)
Logger.info("published_after: #{published_after}")
Logger.info("datetime: #{datetime}")
Logger.info("erl_datetime: #{erl_datetime}")
dynamic([mi], where: mi.updated_at >= ^erl_datetime or ^conditions)
else
conditions
end
Logger.info("media_category: #{media_category}")
query = if conditions do
Ecto.Query.from(mi in MediaItem,
where: ^conditions
)
else
Ecto.Query.from(mi in MediaItem)
end
MediaItemsSearch.run(query, query_string)
|> Repo.paginate(page: offset, page_size: limit)
end
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.