expose database in connection

get/return from pool while result set is been used. still single connection pool
This commit is contained in:
Brian J. Cardiff 2016-02-03 19:30:51 -03:00
parent fa111fd698
commit d45427dfdd
8 changed files with 59 additions and 31 deletions

View file

@ -13,20 +13,18 @@ describe DB do
it "should instantiate driver with connection uri" do
db = DB.open "dummy://localhost:1027"
db.driver_class.should eq(DummyDriver)
db.driver.should be_a(DummyDriver)
db.uri.scheme.should eq("dummy")
db.uri.host.should eq("localhost")
db.uri.port.should eq(1027)
end
it "should create a connection and close it" do
cnn = nil
DummyDriver::DummyConnection.clear_connections
DB.open "dummy://localhost" do |db|
cnn = db.connection
end
cnn.should be_a(DummyDriver::DummyConnection)
cnn.not_nil!.closed?.should be_true
connections.size.should eq(1)
connections.first.closed?.should be_true
end
it "query should close result_set" do
@ -61,4 +59,14 @@ describe DB do
end
connections.first.closed?.should be_true
end
it "should raise if the sole connection is been used" do
with_dummy do |db|
db.query "1" do |rs|
expect_raises Exception, /DB Pool Exhausted/ do
db.scalar "2"
end
end
end
end
end

View file

@ -1,14 +1,13 @@
require "spec"
class DummyDriver < DB::Driver
def build_connection
DummyConnection.new(uri)
def build_connection(db : DB::Database) : DB::Connection
DummyConnection.new(db)
end
class DummyConnection < DB::Connection
getter uri
def initialize(@uri)
def initialize(db)
super(db)
@@connections ||= [] of DummyConnection
@@connections.not_nil! << self
end
@ -60,6 +59,7 @@ class DummyDriver < DB::Driver
end
protected def do_close
super
end
end
@ -74,6 +74,7 @@ class DummyDriver < DB::Driver
end
protected def do_close
super
end
def self.last_result_set