Class: Sequel::SingleConnectionPool

Inherits:
ConnectionPool show all
Defined in:
lib/sequel/connection_pool/single.rb

Overview

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.

Constant Summary

Constants inherited from ConnectionPool

ConnectionPool::CONNECTION_POOL_MAP, ConnectionPool::DEFAULT_SERVER, ConnectionPool::OPTS

Instance Attribute Summary

Attributes inherited from ConnectionPool

#after_connect, #db

Instance Method Summary collapse

Methods inherited from ConnectionPool

#created_count, #initialize, #servers

Methods included from ConnectionPool::ClassMethods

#get_pool

Constructor Details

This class inherits a constructor from Sequel::ConnectionPool

Instance Method Details

#all_connections {|@conn| ... } ⇒ Object

Yield the connection if one has been made.

Yields:

  • (@conn)


12
13
14
# File 'lib/sequel/connection_pool/single.rb', line 12

def all_connections
  yield @conn if @conn
end

#disconnect(opts = nil) ⇒ Object

Disconnect the connection from the database.



17
18
19
20
21
# File 'lib/sequel/connection_pool/single.rb', line 17

def disconnect(opts=nil)
  return unless @conn
  db.disconnect_connection(@conn)
  @conn = nil
end

#hold(server = nil) ⇒ Object

Yield the connection to the block.



24
25
26
27
28
29
30
31
# File 'lib/sequel/connection_pool/single.rb', line 24

def hold(server=nil)
  begin
    yield(@conn ||= make_new(DEFAULT_SERVER))
  rescue Sequel::DatabaseDisconnectError
    disconnect
    raise
  end
end

#pool_typeObject



33
34
35
# File 'lib/sequel/connection_pool/single.rb', line 33

def pool_type
  :single
end

#sizeObject

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



7
8
9
# File 'lib/sequel/connection_pool/single.rb', line 7

def size
  @conn ? 1 : 0
end