0
に私はこのエクトクエリを持っている:ビルダイナミック断片は、エクト
def sum(query) do
from aggregate in query,
select: %{
ones: fragment("coalesce(sum(ones), 0)"),
twos: fragment("coalesce(sum(twos), 0)"),
threes: fragment("coalesce(sum(threes), 0)"),
fours: fragment("coalesce(sum(fours), 0)"),
fives: fragment("coalesce(sum(fives), 0)"),
unanswered: fragment("coalesce(sum(unanswered), 0)"),
n_size: fragment("coalesce(sum(n_size), 0)"),
comment_count: fragment("coalesce(sum(comment_count), 0)")
}
end
私はここで、各ライン上のfragment
、3210とsum
の重複が心配です。それを私自身の機能に移して、このように呼び出せる方法はありますか?
def sum(query) do
from aggregate in query,
select: %{
ones: sum.("ones"),
twos: sum.("twos"),
...