mirror of
https://gitea.invidious.io/iv-org/shard-crystal-db.git
synced 2024-08-15 00:53:32 +00:00
use connection_string as database configuration instead of a hash
This commit is contained in:
parent
8c0313a306
commit
a96776e336
6 changed files with 17 additions and 18 deletions
|
@ -1,8 +1,8 @@
|
|||
module DB
|
||||
abstract class Connection
|
||||
getter options
|
||||
getter connection_string
|
||||
|
||||
def initialize(@options)
|
||||
def initialize(@connection_string)
|
||||
@closed = false
|
||||
end
|
||||
|
||||
|
|
|
@ -6,10 +6,10 @@ module DB
|
|||
# It should be created from DB module. See `DB.open`.
|
||||
class Database
|
||||
getter driver_class
|
||||
getter options
|
||||
getter connection_string
|
||||
|
||||
def initialize(@driver_class, @options)
|
||||
@driver = @driver_class.new(@options)
|
||||
def initialize(@driver_class, @connection_string)
|
||||
@driver = @driver_class.new(@connection_string)
|
||||
@connection = @driver.build_connection
|
||||
end
|
||||
|
||||
|
|
|
@ -12,12 +12,12 @@ module DB
|
|||
@@drivers.not_nil![name] = klass
|
||||
end
|
||||
|
||||
def self.open(name, options)
|
||||
Database.new(driver_class(name), options)
|
||||
def self.open(name, connection_string)
|
||||
Database.new(driver_class(name), connection_string)
|
||||
end
|
||||
|
||||
def self.open(name, options, &block)
|
||||
open(name, options).tap do |db|
|
||||
def self.open(name, connection_string, &block)
|
||||
open(name, connection_string).tap do |db|
|
||||
yield db
|
||||
db.close
|
||||
end
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
module DB
|
||||
abstract class Driver
|
||||
getter options
|
||||
getter connection_string
|
||||
|
||||
def initialize(@options)
|
||||
def initialize(@connection_string : String)
|
||||
end
|
||||
|
||||
abstract def build_connection : Connection
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue