2016-01-28 22:41:12 +00:00
|
|
|
module DB
|
2016-01-31 22:40:02 +00:00
|
|
|
# Database driver implementors must subclass `Driver`,
|
|
|
|
# register with a driver_name using `DB#register_driver` and
|
|
|
|
# override the factory method `#build_connection`.
|
|
|
|
#
|
|
|
|
# ```
|
|
|
|
# require "db"
|
|
|
|
#
|
|
|
|
# class FakeDriver < Driver
|
2016-02-03 22:30:51 +00:00
|
|
|
# def build_connection(db)
|
|
|
|
# FakeConnection.new db
|
2016-01-31 22:40:02 +00:00
|
|
|
# end
|
|
|
|
# end
|
|
|
|
#
|
|
|
|
# DB.register_driver "fake", FakeDriver
|
|
|
|
# ```
|
|
|
|
#
|
|
|
|
# Access to this fake datbase will be available with
|
|
|
|
#
|
|
|
|
# ```
|
2016-02-03 22:30:51 +00:00
|
|
|
# DB.open "fake://..." do |db|
|
2016-01-31 22:40:02 +00:00
|
|
|
# # ... use db ...
|
|
|
|
# end
|
|
|
|
# ```
|
|
|
|
#
|
|
|
|
# Refer to `Connection`, `Statement` and `ResultSet` for further
|
|
|
|
# driver implementation instructions.
|
2016-01-28 22:41:12 +00:00
|
|
|
abstract class Driver
|
2016-02-03 22:30:51 +00:00
|
|
|
abstract def build_connection(db : Database) : Connection
|
2016-07-07 18:50:09 +00:00
|
|
|
|
|
|
|
def connection_pool_options(params : HTTP::Params)
|
|
|
|
{
|
|
|
|
initial_pool_size: params.fetch("initial_pool_size", 1).to_i,
|
2016-10-22 00:49:16 +00:00
|
|
|
max_pool_size: params.fetch("max_pool_size", 0).to_i,
|
2016-07-07 18:50:09 +00:00
|
|
|
max_idle_pool_size: params.fetch("max_idle_pool_size", 1).to_i,
|
|
|
|
checkout_timeout: params.fetch("checkout_timeout", 5.0).to_f,
|
2016-08-31 20:32:01 +00:00
|
|
|
retry_attempts: params.fetch("retry_attempts", 1).to_i,
|
|
|
|
retry_delay: params.fetch("retry_delay", 1.0).to_f,
|
2016-07-07 18:50:09 +00:00
|
|
|
}
|
|
|
|
end
|
2016-01-28 22:41:12 +00:00
|
|
|
end
|
|
|
|
end
|