Skip to content

Instantly share code, notes, and snippets.

@Ninigi
Created June 26, 2018 10:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ninigi/f3c1a10b5df6e87c2e66f32ab75a0e3b to your computer and use it in GitHub Desktop.
Save Ninigi/f3c1a10b5df6e87c2e66f32ab75a0e3b to your computer and use it in GitHub Desktop.
defmodule DripperExample.AccountUsers do
alias DripperExample.{
Repo,
Accounts,
UserQuery
}
def find_user(args) do
Accounts.User
|> UserQuery.query_username(args)
|> UserQuery.query_email(args)
|> Repo.one()
end
end
defmodule DripperExample.UserQuery do
use EctoDripper,
composable_queries: [
[:username, :==],
[:email, :do_email]
]
@doc """
This querys a user based on his credential.email
"""
def do_email(queryable, args) do
from(
u in queryable,
join: c in assoc(u, :credential),
where: c.email == ^args.email
)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment