Class | Sequel::SingleConnectionPool |
In: |
lib/sequel/connection_pool/single.rb
|
Parent: | Sequel::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.
# File lib/sequel/connection_pool/single.rb, line 7 7: def initialize(db, opts=OPTS) 8: super 9: @conn = [] 10: end
Yield the connection if one has been made.
# File lib/sequel/connection_pool/single.rb, line 13 13: def all_connections 14: yield @conn.first if @conn 15: end
Disconnect the connection from the database.
# File lib/sequel/connection_pool/single.rb, line 18 18: def disconnect(opts=nil) 19: return unless c = @conn.first 20: disconnect_connection(c) 21: @conn.clear 22: nil 23: end
Yield the connection to the block.
# File lib/sequel/connection_pool/single.rb, line 26 26: def hold(server=nil) 27: begin 28: unless c = @conn.first 29: @conn.replace([c = make_new(:default)]) 30: end 31: yield c 32: rescue Sequel::DatabaseDisconnectError, *@error_classes => e 33: disconnect if disconnect_error?(e) 34: raise 35: end 36: end
The SingleConnectionPool always has a maximum size of 1.
# File lib/sequel/connection_pool/single.rb, line 39 39: def max_size 40: 1 41: end
The SingleConnectionPool always has a size of 1 if connected and 0 if not.
# File lib/sequel/connection_pool/single.rb, line 49 49: def size 50: @conn.empty? ? 0 : 1 51: end