/ecto_extras

Ecto helper functions.

Primary LanguageElixirMIT LicenseMIT

Ecto Extras Hex.pm Hex.pm CI

Simple helper functions for Ecto.Repo and Ecto.Query that I find missing from the default implementation.

Ecto.Repo helpers (API docs)

first first! last last! count min max avg sum

Setup:

defmodule YourApp.Repo do
  use EctoExtras.Repo
  # ...
end

Example usage:

Repo.count(User)

# instead of

Repo.one(from u in User, select: count(u.id))

Ecto.Query helpers (API docs)

lower upper

Example usage:

import EctoExtras.Query

Repo.one(from u in User, where: lower(u.email) == "email@example.com")

# instead of

Repo.one(from u in User, where: fragment("lower(?)", u.email) == "email@example.com")