Class: Sequel::SingleConnectionPool
- Inherits:
-
ConnectionPool
- Object
- ConnectionPool
- Sequel::SingleConnectionPool
- 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
Instance Method Summary collapse
-
#all_connections {|@conn.first| ... } ⇒ Object
Yield the connection if one has been made.
-
#disconnect(opts = nil) ⇒ Object
Disconnect the connection from the database.
-
#hold(server = nil) ⇒ Object
Yield the connection to the block.
-
#initialize(db, opts = OPTS) ⇒ SingleConnectionPool
constructor
A new instance of SingleConnectionPool.
-
#max_size ⇒ Object
The SingleConnectionPool always has a maximum size of 1.
- #pool_type ⇒ Object
-
#size ⇒ Object
The SingleConnectionPool always has a size of 1 if connected and 0 if not.
Methods inherited from ConnectionPool
Methods included from ConnectionPool::ClassMethods
Constructor Details
#initialize(db, opts = OPTS) ⇒ SingleConnectionPool
Returns a new instance of SingleConnectionPool.
7 8 9 10 |
# File 'lib/sequel/connection_pool/single.rb', line 7 def initialize(db, opts=OPTS) super @conn = [] end |
Instance Method Details
#all_connections {|@conn.first| ... } ⇒ Object
Yield the connection if one has been made.
13 14 15 |
# File 'lib/sequel/connection_pool/single.rb', line 13 def all_connections yield @conn.first if @conn end |
#disconnect(opts = nil) ⇒ Object
Disconnect the connection from the database.
18 19 20 21 22 23 |
# File 'lib/sequel/connection_pool/single.rb', line 18 def disconnect(opts=nil) return unless c = @conn.first disconnect_connection(c) @conn.clear nil end |
#hold(server = nil) ⇒ Object
Yield the connection to the block.
26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/sequel/connection_pool/single.rb', line 26 def hold(server=nil) begin unless c = @conn.first @conn.replace([c = make_new(DEFAULT_SERVER)]) end yield c rescue Sequel::DatabaseDisconnectError, *@error_classes => e disconnect if disconnect_error?(e) raise end end |
#max_size ⇒ Object
The SingleConnectionPool always has a maximum size of 1.
39 40 41 |
# File 'lib/sequel/connection_pool/single.rb', line 39 def max_size 1 end |
#pool_type ⇒ Object
43 44 45 |
# File 'lib/sequel/connection_pool/single.rb', line 43 def pool_type :single end |
#size ⇒ Object
The SingleConnectionPool always has a size of 1 if connected and 0 if not.
49 50 51 |
# File 'lib/sequel/connection_pool/single.rb', line 49 def size @conn.empty? ? 0 : 1 end |