mirror of
https://gitea.invidious.io/iv-org/shard-crystal-db.git
synced 2024-08-15 00:53:32 +00:00
use URI as connection string
This commit is contained in:
parent
b92d08bf74
commit
562d5076bf
5 changed files with 37 additions and 24 deletions
|
@ -11,15 +11,17 @@ describe DB do
|
|||
DB.driver_class("dummy").should eq(DummyDriver)
|
||||
end
|
||||
|
||||
it "should instantiate driver with connection_string" do
|
||||
db = DB.open "dummy", "localhost:1027"
|
||||
it "should instantiate driver with connection uri" do
|
||||
db = DB.open "dummy://localhost:1027"
|
||||
db.driver_class.should eq(DummyDriver)
|
||||
db.connection_string.should eq("localhost:1027")
|
||||
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
|
||||
DB.open "dummy", "localhost" do |db|
|
||||
DB.open "dummy://localhost" do |db|
|
||||
cnn = db.connection
|
||||
end
|
||||
|
||||
|
|
|
@ -2,13 +2,13 @@ require "spec"
|
|||
|
||||
class DummyDriver < DB::Driver
|
||||
def build_connection
|
||||
DummyConnection.new(connection_string)
|
||||
DummyConnection.new(uri)
|
||||
end
|
||||
|
||||
class DummyConnection < DB::Connection
|
||||
getter connection_string
|
||||
getter uri
|
||||
|
||||
def initialize(@connection_string)
|
||||
def initialize(@uri)
|
||||
@@connections ||= [] of DummyConnection
|
||||
@@connections.not_nil! << self
|
||||
end
|
||||
|
@ -173,7 +173,7 @@ end
|
|||
def with_dummy
|
||||
DummyDriver::DummyConnection.clear_connections
|
||||
|
||||
DB.open "dummy", "" do |db|
|
||||
DB.open "dummy://host" do |db|
|
||||
yield db
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue