Created
September 22, 2020 16:24
-
-
Save Ch4s3/7c718eee8134f4f820c2a67d8f6e4359 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
@doc """ | |
You can pipe queries into this build_where/3 | |
fn and match on operators like :in, :==, | |
:ilike, etc and handle the particular | |
where semantics in each function case. | |
Pay attention to the positional binding | |
[...,e] which will capture the last | |
binding added to the piped in query. | |
See also: https://hexdocs.pm/ecto/Ecto.Query.html#module-positional-bindings | |
and. https://hexdocs.pm/ecto/Ecto.Query.API.html#field/2 | |
""" | |
def build_where(query, :in, from_api) do | |
query | |
|> where([..., e], | |
field(e, ^from_api.field) | |
in ^from_api.values) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment