database

Composing dynamic queries with ecto

published on
I was recently working on a project where I needed to compose a dynamic query for filtering a table using ecto. The filter parameters are coming from a graphql resolver. # ~/query.ex #A sample filter input filter_input = %{status: "AVAILABLE", genre: "Comedy", last_update_gte: "2018-10-18 00:00:00", last_update_lte: "2018-10-18 23:59:59" } #The schema I will be querying defmodule Movies do use Ecto.Schema schema "movies" do field(:genre, :string) field(:status, :string) timestamps() end end #My resolver function defmodule MovieFilter do import Ecto. Read More...