Permalink
Browse files

Implements Binary.Inspect for ExQL.Select

  • Loading branch information...
1 parent 6ffa355 commit 4edd0bbcd121cd4e4789896528c830c9dc14e82d @yrashk committed Jul 7, 2012
Showing with 17 additions and 0 deletions.
  1. +17 −0 lib/queries/select.ex
View
@@ -34,3 +34,20 @@ defrecord ExQL.Select, dict: [fields: :*] do
statement(:from, query), statement(:where, query), statement(:group, query)] /> ExQL.Utils.space
end
end
+
+defimpl Binary.Inspect, for: ExQL.Select do
+ def inspect(thing), do: statement(thing.statement, [])
+
+ defp statement([], acc), do: iolist_to_binary(List.reverse(acc))
+ defp statement([{:value, value}|rest], acc) do
+ statement(rest, [Binary.Inspect.inspect(value)|acc])
+ end
+ defp statement([list|rest], acc) when is_list(list) do
+ new_acc = statement(list, [])
+ statement(rest, [new_acc|acc])
+ end
+ defp statement([head|rest], acc) do
+ statement(rest, [head|acc])
+ end
+
+end

0 comments on commit 4edd0bb

Please sign in to comment.