Permalink
Browse files

Refactors ExQL.select

  • Loading branch information...
1 parent 832c43e commit 59af8478d34041983446bb4381296f5663563ed9 Yurii Rashkovskii committed Jul 9, 2012
Showing with 6 additions and 3 deletions.
  1. +6 −3 lib/exql.ex
View
@@ -16,7 +16,10 @@ defmodule ExQL do
end
defmacro select(block // [do: nil]) do
- query = ExQL.Select.new
+ body((quote do: import ExQL.Select),ExQL.Select.new, block)
+ end
+
+ defp body(prologue, query, block) do
case block[:do] do
{:__block__, _, body} -> :ok
nil -> body = []
@@ -35,15 +38,15 @@ defmodule ExQL do
[expr] ->
quote do
try do
- import ExQL.Select
+ unquote(prologue)
require ExQL.Utils
ExQL.Utils.back_pipeline(unquote(query), unquote(expr))
end
end
[l,r] ->
quote do
try do
- import ExQL.Select
+ unquote(prologue)
require ExQL.Utils
ExQL.Utils.back_pipeline(unquote(query), ExQL.Utils.back_pipeline(unquote(l), unquote(r)))
end

0 comments on commit 59af847

Please sign in to comment.