ElixirExtensions.Ecto.QueryExt (elixir_extentions v0.1.0)

Extend Ecto.Query with some useful functions. Add this line to your Context module:

import Ecto.Query, warn: false
alias ElixirExtensions.Ecto.QueryExt

Summary

Functions

Limit a the number of results from a query. Can be compined with other queryables UserQuery.text_search("Kyle") |> QueryExt.limit(query, 5)

order_by(query, [:name, :population]) order_by(query, [asc: :name, desc_nulls_first: :population])

Order by newest first

Order by oldest first

Preload associations. UserQuery.text_search("Kyle") |> QueryExt.preload(:posts) |> Repo.all()

Construct a where query on the fly. Only works when use QueryBuilder is added to the schema file eg QueryExt.where(Log, %{post_id: 1814, user_id: 24688, user_type: "user"}) |> Repo.all()

Functions

Link to this function

limit(query, limit)

Limit a the number of results from a query. Can be compined with other queryables UserQuery.text_search("Kyle") |> QueryExt.limit(query, 5)

Link to this function

order_by(query, order)

order_by(query, [:name, :population]) order_by(query, [asc: :name, desc_nulls_first: :population])

Link to this function

order_newest_first(query)

Order by newest first

Link to this function

order_oldest_first(query)

Order by oldest first

Link to this function

preload(query, preloads)

Preload associations. UserQuery.text_search("Kyle") |> QueryExt.preload(:posts) |> Repo.all()

Link to this function

where(query, params)

Construct a where query on the fly. Only works when use QueryBuilder is added to the schema file eg QueryExt.where(Log, %{post_id: 1814, user_id: 24688, user_type: "user"}) |> Repo.all()