Skip to content

Instantly share code, notes, and snippets.

@Ninigi
Created June 27, 2018 01:50
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/ad2e7869385ef8166d3eb3b32de64fa7 to your computer and use it in GitHub Desktop.
Save Ninigi/ad2e7869385ef8166d3eb3b32de64fa7 to your computer and use it in GitHub Desktop.
# Without EctoDripper
defmodule QueryModule do
def query_status(query, args)
def query_status(query, %{username: username}) do
# Create query when username key is in args
# Since we have the key already in the function name,
# I find this quite pointless in terms of readability
from(
thing in query,
where: thing.username == ^username
)
end
def query_status(query, _args) do
# Let the query "fall through" if no username key in args
query
end
end
# With EctoDripper
defmodule QueryModule do
use EctoDripper,
composable_queries: [
[:username, :my_username_func]
]
def my_username_func(queryable, args) do
# args only include username, because I specified that in my queries.
# No need to pattern match
from(
thing in query,
where: thing.username == ^username
)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment