class Sequel::SingleConnectionPool

  1. lib/sequel/connection_pool/single.rb
Superclass: ConnectionPool

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.

Methods

Public Class

  1. new

Public Instance

  1. all_connections
  2. disconnect
  3. hold
  4. max_size
  5. pool_type
  6. size

Public Class methods

new (db, opts=OPTS)
[show source]
# File lib/sequel/connection_pool/single.rb, line 6
def initialize(db, opts=OPTS)
  super
  @conn = []
end

Public Instance methods

all_connections ()

Yield the connection if one has been made.

[show source]
# File lib/sequel/connection_pool/single.rb, line 12
def all_connections
  yield @conn.first if @conn
end
disconnect (opts=nil)

Disconnect the connection from the database.

[show source]
# File lib/sequel/connection_pool/single.rb, line 17
def disconnect(opts=nil)
  return unless c = @conn.first
  disconnect_connection(c)
  @conn.clear
  nil
end
hold (server=nil)

Yield the connection to the block.

[show source]
# File lib/sequel/connection_pool/single.rb, line 25
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
max_size ()

The SingleConnectionPool always has a maximum size of 1.

[show source]
# File lib/sequel/connection_pool/single.rb, line 38
def max_size
  1
end
pool_type ()
[show source]
# File lib/sequel/connection_pool/single.rb, line 42
def pool_type
  :single
end
size ()

The SingleConnectionPool always has a size of 1 if connected and 0 if not.

[show source]
# File lib/sequel/connection_pool/single.rb, line 48
def size
  @conn.empty? ? 0 : 1
end