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 :single_threaded and :servers options.

# File lib/sequel/connection_pool.rb, line 43
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 50
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
  else
    pc = if opts[:single_threaded]
      opts[:servers] ? :sharded_single : :single
    else
      opts[:servers] ? :sharded_threaded : :threaded
    end

    connection_pool_class(:pool_class=>pc)
  end
end