Browse files

Adds ExQL.Query.accessor macro to simplify query accessors definition

  • Loading branch information...
1 parent 69b4717 commit 832c43ebde033e8f4d2edae4fe4755d170d81812 Yurii Rashkovskii committed Jul 9, 2012
Showing with 11 additions and 5 deletions.
  1. +3 −4 lib/queries/select.ex
  2. +7 −0 lib/query.ex
  3. +1 −1 rebar.config
View
7 lib/queries/select.ex
@@ -1,10 +1,9 @@
defrecord ExQL.Select, dict: [fields: :*] do
use ExQL.Query
- def fields(v, query), do: query.dict Keyword.put(query.dict, :fields, v)
- def from(v, query), do: query.dict Keyword.put(query.dict, :from, v)
-
- def where(v, query), do: query.dict Keyword.put(query.dict, :where, v)
+ accessor :fields
+ accessor :from
+ accessor :where
def statement(:modifiers, query) do
ExQL.Expression.join(dict(query)[:modifiers], :raw, " ")
View
7 lib/query.ex
@@ -5,6 +5,13 @@ defmodule ExQL.Query do
end
end
+ defmacro accessor(name) do
+ quote do
+ def unquote(name).(v, query), do: query.dict Keyword.put(query.dict, unquote(name), v)
+ def unquote(name).(query), do: query.dict[unquote(name)]
+ end
+ end
+
def statement(_query), do: ""
defoverridable [statement: 1]
View
2 rebar.config
@@ -1,4 +1,4 @@
{plugins, [rebar_elixir_compiler]}.
{lib_dirs, ["deps","deps/elixir/lib/elixir/ebin"]}.
-{ex_first_files, ["lib/exql.ex","lib/expr.ex"]}.
+{ex_first_files, ["lib/exql.ex","lib/expr.ex","lib/query.ex"]}.
{deps, [{elixir, ".*", {git, "https://github.com/elixir-lang/elixir", {tag, "b7bd24c"}}}]}.

0 comments on commit 832c43e

Please sign in to comment.