Filtering in the Database
Let’s start with adding filters to our meerkat data by extending our Meerkat context. We want to add filters for the id and the name fields of a meerkat. The id filter will be a distinct filter that matches only the meerkat with the exact id. The name filter will be a fuzzy filter that matches any meerkat whose name contains a certain string.
So, when we filter by an ID like 123, only the meerkat with the ID 123 will match our query. However, when we filter by name with, for example, the search term big, we want to find meerkats that have names like Mr. Big, Bigly Tickly, or Overbig Snouty. As you can see, we want to match names that contain the string big regardless of its position in the name or its case. Ecto.Query ...
Get Building Table Views with Phoenix LiveView now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.