Sha256: 5c55c621f90ab0329cb0513b6c4847a83d97063f303d45fae29cff5d3bb35f0a

Contents?: true

Size: 1.25 KB

Versions: 35

Compression:

Stored size: 1.25 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 unless @conn.empty?
  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

35 entries across 24 versions & 2 rubygems

Version Path
sequel-5.51.0 lib/sequel/connection_pool/single.rb
tdiary-5.2.0 vendor/bundle/ruby/3.0.0/gems/sequel-5.50.0/lib/sequel/connection_pool/single.rb
tdiary-5.2.0 vendor/bundle/ruby/2.7.0/gems/sequel-5.44.0/lib/sequel/connection_pool/single.rb
sequel-5.50.0 lib/sequel/connection_pool/single.rb
sequel-5.49.0 lib/sequel/connection_pool/single.rb
sequel-5.48.0 lib/sequel/connection_pool/single.rb
tdiary-5.1.7 vendor/bundle/ruby/2.7.0/gems/sequel-5.44.0/lib/sequel/connection_pool/single.rb
tdiary-5.1.7 vendor/bundle/ruby/3.0.0/gems/sequel-5.47.0/lib/sequel/connection_pool/single.rb
sequel-5.47.0 lib/sequel/connection_pool/single.rb
sequel-5.46.0 lib/sequel/connection_pool/single.rb
sequel-5.45.0 lib/sequel/connection_pool/single.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/sequel-5.43.0/lib/sequel/connection_pool/single.rb
tdiary-5.1.6 vendor/bundle/ruby/3.0.0/gems/sequel-5.44.0/lib/sequel/connection_pool/single.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/tdiary-5.1.5/vendor/bundle/ruby/3.0.0/gems/tdiary-5.1.4/vendor/bundle/ruby/2.7.0/gems/sequel-5.38.0/lib/sequel/connection_pool/single.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/tdiary-5.1.5/vendor/bundle/ruby/2.7.0/gems/sequel-5.41.0/lib/sequel/connection_pool/single.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/tdiary-5.1.5/vendor/bundle/ruby/3.0.0/gems/sequel-5.39.0/lib/sequel/connection_pool/single.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/tdiary-5.1.5/vendor/bundle/ruby/3.0.0/gems/sequel-5.41.0/lib/sequel/connection_pool/single.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/sequel-5.44.0/lib/sequel/connection_pool/single.rb
sequel-5.44.0 lib/sequel/connection_pool/single.rb
sequel-5.43.0 lib/sequel/connection_pool/single.rb