Sha256: 4b48bfdd3bbd36da26b6244f42fd651ced0549cc8daa4610a5a504fa05a8d4ae

Contents?: true

Size: 1.24 KB

Versions: 51

Compression:

Stored size: 1.24 KB

Contents

# frozen-string-literal: true

# This is the fastest connection pool, since it isn't a connection pool at all.
# It is just a wrapper around a single connection that uses the connection pool
# API.
class Sequel::SingleConnectionPool < Sequel::ConnectionPool  
  def initialize(db, opts=OPTS)
    super
    @conn = []
  end

  # Yield the connection if one has been made.
  def all_connections
    yield @conn.first if @conn
  end

  # Disconnect the connection from the database.
  def disconnect(opts=nil)
    return unless c = @conn.first
    disconnect_connection(c)
    @conn.clear
    nil
  end

  # Yield the connection to the block.
  def hold(server=nil)
    begin
      unless c = @conn.first
        @conn.replace([c = make_new(:default)])
      end
      yield c
    rescue Sequel::DatabaseDisconnectError, *@error_classes => e
      disconnect if disconnect_error?(e)
      raise
    end
  end

  # The SingleConnectionPool always has a maximum size of 1.
  def max_size
    1
  end
  
  def pool_type
    :single
  end
  
  # The SingleConnectionPool always has a size of 1 if connected
  # and 0 if not.
  def size
    @conn.empty? ? 0 : 1
  end

  private

  # Make sure there is a valid connection.
  def preconnect(concurrent = nil)
    hold{}
  end
end

Version data entries

51 entries across 46 versions & 2 rubygems

Version Path
tdiary-5.1.3 vendor/bundle/ruby/2.6.0/gems/sequel-5.32.0/lib/sequel/connection_pool/single.rb
sequel-5.33.0 lib/sequel/connection_pool/single.rb
tdiary-5.1.2 vendor/bundle/ruby/2.7.0/gems/sequel-5.32.0/lib/sequel/connection_pool/single.rb
tdiary-5.1.2 vendor/bundle/ruby/2.6.0/gems/sequel-5.26.0/lib/sequel/connection_pool/single.rb
sequel-5.32.0 lib/sequel/connection_pool/single.rb
sequel-5.31.0 lib/sequel/connection_pool/single.rb
sequel-5.30.0 lib/sequel/connection_pool/single.rb
tdiary-5.1.1 vendor/bundle/ruby/2.6.0/gems/sequel-5.26.0/lib/sequel/connection_pool/single.rb
tdiary-5.1.1 vendor/bundle/ruby/2.7.0/gems/sequel-5.29.0/lib/sequel/connection_pool/single.rb
sequel-5.29.0 lib/sequel/connection_pool/single.rb
sequel-5.28.0 lib/sequel/connection_pool/single.rb
sequel-5.27.0 lib/sequel/connection_pool/single.rb
tdiary-5.1.0 vendor/bundle/gems/sequel-5.26.0/lib/sequel/connection_pool/single.rb
sequel-5.26.0 lib/sequel/connection_pool/single.rb
sequel-5.25.0 lib/sequel/connection_pool/single.rb
sequel-5.24.0 lib/sequel/connection_pool/single.rb
sequel-5.23.0 lib/sequel/connection_pool/single.rb
sequel-5.22.0 lib/sequel/connection_pool/single.rb
sequel-5.21.0 lib/sequel/connection_pool/single.rb
sequel-5.20.0 lib/sequel/connection_pool/single.rb