A collection of custom functions for PostgreSQL features in Ecto
def deps do
[{:ecto_pg_extras, "~> 0.1.0"}]
end
Import ecto_pg_extras
in any module where you want access to the custom
functions for use with Ecto queries.
import EctoPgExtras
Then use any of the functions as part of a query as you would anything else
defined in Ecto.Query.API
. For example, here is the coalesce
function in
action:
from(posts in Posts,
where: posts.id == 1,
select: {
posts.title,
coalesce(posts.description, posts.short_description, "N/A")
})
EctoPgExtras is supported by the team at Hashrocket, a multidisciplinary design & development consultancy. If you'd like to work with us or join our team, don't hesitate to get in touch.