Add query_decorator to builder (#15)

Add query_decorator to builder (#15)

diff --git a/lib/mini_sql/builder.rb b/lib/mini_sql/builder.rb
index 4bea8fa..b39c0aa 100644
--- a/lib/mini_sql/builder.rb
+++ b/lib/mini_sql/builder.rb
@@ -66,4 +66,14 @@ class MiniSql::Builder
     RUBY
   end
 
+  def query_decorator(decorator, hash_args = nil)
+    hash_args = @args.merge(hash_args) if hash_args && @args
+    hash_args ||= @args
+    if hash_args
+      @connection.query_decorator(decorator, to_sql, hash_args)
+    else
+      @connection.query_decorator(decorator, to_sql)
+    end
+  end
+
 end
diff --git a/test/mini_sql/builder_tests.rb b/test/mini_sql/builder_tests.rb
index 63c51bf..6a1edc3 100644
--- a/test/mini_sql/builder_tests.rb
+++ b/test/mini_sql/builder_tests.rb
@@ -69,12 +69,6 @@ module MiniSql::BuilderTests
   end
 
   def test_accepts_params_at_end
-    builder = @connection.build("select :bob as a")
-    r = builder.query_hash(bob: 1)
-    assert_equal([{ "a" => 1 }], r)
-  end
-
-  def test_accepts_params_at_end
     builder = @connection.build("select :bob as a /*where*/")
     builder.where('1 = :one', one: 1)
     r = builder.query_hash(bob: 1)
@@ -93,4 +87,17 @@ module MiniSql::BuilderTests
     builder.offset(1)
     assert_equal([2], builder.query_single)
   end
+
+  module ProductDecorator
+    def amount_price
+      price * quantity
+    end
+  end
+
+  def test_query_decorator
+    builder = @connection.build("select 20 price, 3 quantity")
+
+    r = builder.query_decorator(ProductDecorator).first
+    assert_equal(60, r.amount_price)
+  end
 end

GitHub sha: 877b35c0

This commit appears in #15 which was merged by SamSaffron.