From d4b2046a65af175f7ee61b419701d278367dba80 Mon Sep 17 00:00:00 2001 From: "Brian J. Cardiff" Date: Thu, 14 Apr 2016 18:50:44 -0300 Subject: [PATCH] refactor and add specs for query without blocks --- spec/custom_drivers_types_spec.cr | 14 ++++++++++++++ src/db/statement.cr | 24 +----------------------- 2 files changed, 15 insertions(+), 23 deletions(-) diff --git a/spec/custom_drivers_types_spec.cr b/spec/custom_drivers_types_spec.cr index 6adc60c..761f073 100644 --- a/spec/custom_drivers_types_spec.cr +++ b/spec/custom_drivers_types_spec.cr @@ -167,6 +167,13 @@ describe DB do db.query("query", Slice(UInt8).new(4)) { } db.query("query", 1, "string", FooValue.new(5)) { } db.query "query", [1, "string", FooValue.new(5)] { } + + db.query("query").close + db.query("query", 1).close + db.query("query", 1, "string").close + db.query("query", Slice(UInt8).new(4)).close + db.query("query", 1, "string", FooValue.new(5)).close + db.query("query", [1, "string", FooValue.new(5)]).close end DB.open("bar://host") do |db| @@ -177,6 +184,13 @@ describe DB do db.query("query", Slice(UInt8).new(4)) { } db.query("query", 1, "string", BarValue.new(5)) { } db.query "query", [1, "string", FooValue.new(5)] { } + + db.query("query").close + db.query("query", 1).close + db.query("query", 1, "string").close + db.query("query", Slice(UInt8).new(4)).close + db.query("query", 1, "string", BarValue.new(5)).close + db.query("query", [1, "string", BarValue.new(5)]).close end end end diff --git a/src/db/statement.cr b/src/db/statement.cr index 0ad66ea..207e352 100644 --- a/src/db/statement.cr +++ b/src/db/statement.cr @@ -75,33 +75,11 @@ module DB perform_query Slice(Any).new(0) end - # See `QueryMethods#query` - def query - perform_query(Slice(Any).new(0)).tap do |rs| - begin - yield rs - ensure - rs.close - end - end - end - # See `QueryMethods#query` def query(args : Array) perform_query args end - # See `QueryMethods#query` - def query(args : Array) - perform_query(args).tap do |rs| - begin - yield rs - ensure - rs.close - end - end - end - # See `QueryMethods#query` def query(*args) perform_query args @@ -109,7 +87,7 @@ module DB # See `QueryMethods#query` def query(*args) - perform_query(args).tap do |rs| + query(*args).tap do |rs| begin yield rs ensure