Call setup/teardown of io_provider

This commit is contained in:
Brian J. Cardiff 2023-04-10 16:51:26 -03:00
parent 7817f52b5b
commit 105d7d1ab4
3 changed files with 10 additions and 0 deletions

View file

@ -29,9 +29,11 @@ module DB
def initialize(@uri : URI, @io_provider : IOProvider?)
params = HTTP::Params.parse(uri.query || "")
@prepared_statements = DB.fetch_bool(params, "prepared_statements", true)
@io_provider.try &.setup
end
def discard(connection : Connection)
@io_provider.try &.teardown
end
def release(connection : Connection)

View file

@ -54,6 +54,8 @@ module DB
@prepared_statements = DB.fetch_bool(params, "prepared_statements", true)
pool_options = @driver.connection_pool_options(params)
@io_provider.try &.setup
@setup_connection = ->(conn : Connection) {}
@pool = uninitialized Pool(Connection) # in order to use self in the factory proc
@pool = Pool.new(**pool_options) {
@ -86,6 +88,8 @@ module DB
@statements_cache.clear
@pool.close
@io_provider.try &.teardown
end
# :nodoc:

View file

@ -2,6 +2,10 @@ module DB
# An `IOProvider` can be used to customize
# how underlying IO for connections are created.
# Not all drivers are backed by IO.
#
# The setup and teardown methods will be called once
# per Database Connection Pool when DB.open is used,
# and once for the single connection when DB.connect is used.
abstract class IOProvider
abstract def setup : Void