Drop driver getter from database

This commit is contained in:
Brian J. Cardiff 2023-05-29 13:40:58 -03:00
parent 0a08eace7a
commit 33a5b2b78b
3 changed files with 8 additions and 13 deletions

View file

@ -160,8 +160,8 @@ DB.register_driver "bar", BarDriver
describe DB do
it "should be able to register multiple drivers" do
DB.open("foo://host").driver.should be_a(FooDriver)
DB.open("bar://host").driver.should be_a(BarDriver)
DB.open("foo://host").checkout.should be_a(FooDriver::FooConnection)
DB.open("bar://host").checkout.should be_a(BarDriver::BarConnection)
end
it "Foo and Bar drivers should return fake_row" do

View file

@ -9,12 +9,9 @@ describe DB do
DB.driver_class("dummy").should eq(DummyDriver)
end
it "should instantiate driver with connection uri" do
it "should create dummy connection" do
db = DB.open "dummy://localhost:1027"
db.driver.should be_a(DummyDriver)
db.uri.scheme.should eq("dummy")
db.uri.host.should eq("localhost")
db.uri.port.should eq(1027)
db.checkout.should be_a(DummyDriver::DummyConnection)
end
it "should create a connection and close it" do

View file

@ -31,8 +31,6 @@ module DB
include SessionMethods(Database, PoolStatement)
include ConnectionContext
# :nodoc:
getter driver
# :nodoc:
getter pool
@ -45,13 +43,13 @@ module DB
@statements_cache = StringKeyCache(PoolPreparedStatement).new
# :nodoc:
def initialize(@driver : Driver, @uri : URI)
def initialize(driver : Driver, @uri : URI)
params = HTTP::Params.parse(uri.query || "")
@connection_options = @driver.connection_options(params)
pool_options = @driver.pool_options(params)
@connection_options = driver.connection_options(params)
pool_options = driver.pool_options(params)
@setup_connection = ->(conn : Connection) {}
factory = @driver.connection_builder(@uri)
factory = driver.connection_builder(@uri)
@pool = uninitialized Pool(Connection) # in order to use self in the factory proc
@pool = Pool.new(pool_options) {
conn = factory.call