Created
June 26, 2018 10:51
-
-
Save Ninigi/f3c1a10b5df6e87c2e66f32ab75a0e3b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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