class Perpetuity::Postgres::ConnectionPool

Attributes

connections[R]
size[R]

Public Class Methods

new(options={}) click to toggle source
# File lib/perpetuity/postgres/connection_pool.rb, line 9
def initialize options={}
  @connections = Queue.new
  @size = options.delete(:pool_size) { 5 }
  @size.times do
    connections << Connection.new(options)
  end
end

Public Instance Methods

execute(sql) click to toggle source
# File lib/perpetuity/postgres/connection_pool.rb, line 26
def execute sql
  lend_connection do |connection|
    connection.execute sql
  end
end
lend_connection() { |connection| ... } click to toggle source
# File lib/perpetuity/postgres/connection_pool.rb, line 17
def lend_connection
  if block_given?
    connection = connections.pop
    yield connection
  end
ensure
  connections << connection
end
tables() click to toggle source
# File lib/perpetuity/postgres/connection_pool.rb, line 32
def tables
  lend_connection do |connection|
    connection.tables
  end
end