Permalink
Browse files

Adds keyword API for queries

  • Loading branch information...
1 parent 59af847 commit 6c6886feeeac004da1db3643150684f8b6ec0fc2 @yrashk committed Jul 10, 2012
Showing with 10 additions and 1 deletion.
  1. +10 −1 lib/exql.ex
View
11 lib/exql.ex
@@ -15,10 +15,19 @@ defmodule ExQL do
end
end
- defmacro select(block // [do: nil]) do
+ defmacro select do
+ body((quote do: import ExQL.Select),ExQL.Select.new, [do: nil])
+ end
+
+ defmacro select([do: block]) do
body((quote do: import ExQL.Select),ExQL.Select.new, block)
end
+ defmacro select(keywords) when is_list(keywords) do
+ block = {:__block__, 0, (lc {k,v} inlist keywords, do: {k, 0, [v]})}
+ body((quote do: import ExQL.Select),ExQL.Select.new, [do: block])
+ end
+
defp body(prologue, query, block) do
case block[:do] do
{:__block__, _, body} -> :ok

0 comments on commit 6c6886f

Please sign in to comment.