module Sequel::ConnectionPool::ClassMethods
Class methods used to return an appropriate pool subclass, separated into a module for easier overridding by extensions.
Public Instance Methods
Source
# File lib/sequel/connection_pool.rb 48 def get_pool(db, opts = OPTS) 49 connection_pool_class(opts).new(db, opts) 50 end
Return a pool subclass instance based on the given options. If a :pool_class
option is provided is provided, use that pool class, otherwise use a new instance of an appropriate pool subclass based on the SEQUEL_DEFAULT_CONNECTION_POOL
environment variable if set, or the :single_threaded
and :servers
options, otherwise.
Private Instance Methods
Source
# File lib/sequel/connection_pool.rb 55 def connection_pool_class(opts) 56 if pc = opts[:pool_class] 57 unless pc.is_a?(Class) 58 unless name = POOL_CLASS_MAP[pc] 59 raise Sequel::Error, "unsupported connection pool type, please pass appropriate class as the :pool_class option" 60 end 61 62 require_relative "connection_pool/#{pc}" 63 pc = Sequel.const_get(name) 64 end 65 66 pc 67 elsif pc = ENV['SEQUEL_DEFAULT_CONNECTION_POOL'] 68 pc = "sharded_#{pc}" if opts[:servers] && !pc.start_with?('sharded_') 69 connection_pool_class(:pool_class=>pc) 70 else 71 pc = if opts[:single_threaded] 72 opts[:servers] ? :sharded_single : :single 73 elsif RUBY_VERSION >= '3.2' 74 opts[:servers] ? :sharded_timed_queue : :timed_queue 75 # :nocov: 76 else 77 opts[:servers] ? :sharded_threaded : :threaded 78 end 79 # :nocov: 80 81 connection_pool_class(:pool_class=>pc) 82 end 83 end
Return a connection pool class based on the given options.