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

get_pool(db, opts = OPTS) click to toggle source

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.

# File lib/sequel/connection_pool.rb, line 47
def get_pool(db, opts = OPTS)
  connection_pool_class(opts).new(db, opts)
end

Private Instance Methods

connection_pool_class(opts) click to toggle source

Return a connection pool class based on the given options.

# File lib/sequel/connection_pool.rb, line 54
def connection_pool_class(opts)
  if pc = opts[:pool_class]
    unless pc.is_a?(Class)
      unless name = POOL_CLASS_MAP[pc]
        raise Sequel::Error, "unsupported connection pool type, please pass appropriate class as the :pool_class option"
      end

      require_relative "connection_pool/#{pc}"
      pc = Sequel.const_get(name)
    end

    pc
  elsif pc = ENV['SEQUEL_DEFAULT_CONNECTION_POOL']
    pc = "sharded_#{pc}" if opts[:servers] && !pc.start_with?('sharded_')
    connection_pool_class(:pool_class=>pc)
  else
    pc = if opts[:single_threaded]
      opts[:servers] ? :sharded_single : :single
    # :nocov:
    elsif RUBY_VERSION >= '3.4' # SEQUEL6 or maybe earlier switch to 3.2
      opts[:servers] ? :sharded_timed_queue : :timed_queue
    # :nocov:
    else
      opts[:servers] ? :sharded_threaded : :threaded
    end

    connection_pool_class(:pool_class=>pc)
  end
end