Created
March 20, 2022 00:18
-
-
Save danhawkins/5beb49495f15c8eedc6d8788826a8106 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
| def list_groups(region \\ nil, search \\ nil) do | |
| query = | |
| from(g in Group) | |
| |> filter_region(region) | |
| |> add_rank(region) | |
| |> search(search) | |
| query |> Repo.all() | |
| end | |
| defp search(query, nil), do: query | |
| # Make sure to use a subquery to we don't lose the correct ordering | |
| defp search(query, search) do | |
| from(g in subquery(query), where: ilike(g.name, ^"%#{search}%")) | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment