mirror of
https://gitea.invidious.io/iv-org/shard-crystal-db.git
synced 2024-08-15 00:53:32 +00:00
Call setup/teardown of io_provider
This commit is contained in:
parent
7817f52b5b
commit
105d7d1ab4
3 changed files with 10 additions and 0 deletions
|
@ -29,9 +29,11 @@ module DB
|
||||||
def initialize(@uri : URI, @io_provider : IOProvider?)
|
def initialize(@uri : URI, @io_provider : IOProvider?)
|
||||||
params = HTTP::Params.parse(uri.query || "")
|
params = HTTP::Params.parse(uri.query || "")
|
||||||
@prepared_statements = DB.fetch_bool(params, "prepared_statements", true)
|
@prepared_statements = DB.fetch_bool(params, "prepared_statements", true)
|
||||||
|
@io_provider.try &.setup
|
||||||
end
|
end
|
||||||
|
|
||||||
def discard(connection : Connection)
|
def discard(connection : Connection)
|
||||||
|
@io_provider.try &.teardown
|
||||||
end
|
end
|
||||||
|
|
||||||
def release(connection : Connection)
|
def release(connection : Connection)
|
||||||
|
|
|
@ -54,6 +54,8 @@ module DB
|
||||||
@prepared_statements = DB.fetch_bool(params, "prepared_statements", true)
|
@prepared_statements = DB.fetch_bool(params, "prepared_statements", true)
|
||||||
pool_options = @driver.connection_pool_options(params)
|
pool_options = @driver.connection_pool_options(params)
|
||||||
|
|
||||||
|
@io_provider.try &.setup
|
||||||
|
|
||||||
@setup_connection = ->(conn : Connection) {}
|
@setup_connection = ->(conn : Connection) {}
|
||||||
@pool = uninitialized Pool(Connection) # in order to use self in the factory proc
|
@pool = uninitialized Pool(Connection) # in order to use self in the factory proc
|
||||||
@pool = Pool.new(**pool_options) {
|
@pool = Pool.new(**pool_options) {
|
||||||
|
@ -86,6 +88,8 @@ module DB
|
||||||
@statements_cache.clear
|
@statements_cache.clear
|
||||||
|
|
||||||
@pool.close
|
@pool.close
|
||||||
|
|
||||||
|
@io_provider.try &.teardown
|
||||||
end
|
end
|
||||||
|
|
||||||
# :nodoc:
|
# :nodoc:
|
||||||
|
|
|
@ -2,6 +2,10 @@ module DB
|
||||||
# An `IOProvider` can be used to customize
|
# An `IOProvider` can be used to customize
|
||||||
# how underlying IO for connections are created.
|
# how underlying IO for connections are created.
|
||||||
# Not all drivers are backed by IO.
|
# 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 class IOProvider
|
||||||
abstract def setup : Void
|
abstract def setup : Void
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue