mirror of
https://gitea.invidious.io/iv-org/shard-crystal-db.git
synced 2024-08-15 00:53:32 +00:00
Add public Database#initialize method
This commit is contained in:
parent
52f725c1c6
commit
5515b78a53
1 changed files with 9 additions and 3 deletions
|
@ -42,11 +42,17 @@ module DB
|
|||
# :nodoc:
|
||||
def initialize(driver : Driver, uri : URI)
|
||||
params = HTTP::Params.parse(uri.query || "")
|
||||
@connection_options = driver.connection_options(params)
|
||||
connection_options = driver.connection_options(params)
|
||||
pool_options = driver.pool_options(params)
|
||||
|
||||
@setup_connection = ->(conn : Connection) {}
|
||||
factory = driver.connection_builder(uri)
|
||||
initialize(connection_options, pool_options, &factory)
|
||||
end
|
||||
|
||||
# Initialize a database with the specified options and connection factory.
|
||||
# This covers more advanced use cases that might not be supported by an URI connection string such as tunneling connection.
|
||||
def initialize(connection_options : Connection::Options, pool_options : Pool::Options, &factory : -> Connection)
|
||||
@connection_options = connection_options
|
||||
@setup_connection = ->(conn : Connection) {}
|
||||
@pool = uninitialized Pool(Connection) # in order to use self in the factory proc
|
||||
@pool = Pool.new(pool_options) {
|
||||
conn = factory.call
|
||||
|
|
Loading…
Reference in a new issue