View Source Bind (bind v0.1.1)
Bind
provides functionality to build dynamic Ecto queries based on given parameters.
It allows developers to retrieve data flexibly without writing custom queries for each use case.
Examples
Given an Ecto schema module MyApp.User
and a map of query parameters, you can build and run a query like this:
> params = %{ "name[eq]" => "Alice", "age[gte]" => 30, "sort" => "-age", "limit" => "10" }
> query = Bind.query(MyApp.User, params)
> results = Repo.all(query)
> IO.inspect(results)
Summary
Functions
Builds an Ecto query for the given schema based on the provided query string.
Functions
Builds an Ecto query for the given schema based on the provided query string.
Parameters
schema
: The Ecto schema module (e.g.,MyApp.User
).query_string
: The query string from a URL.
Examples
> query_string = "?name[eq]=Alice&age[gte]=30&sort=-age&limit=10"
> Bind.query(MyApp.User, query_string)
#Ecto.Query<from u0 in MyApp.User, where: u0.name == ^"Alice", where: u0.age >= ^30, order_by: [desc: u0.age]>