Class: JDBCHelper::PostgresConnector

Inherits:
Connector
  • Object
show all
Includes:
Constants, Constants::Connector
Defined in:
lib/jdbc-helper/connector/postgres_connector.rb

Overview

Shortcut connector for PostgreSQL

Constant Summary

Constants included from Constants::Connector

Constants::Connector::DEFAULT_PARAMETERS, Constants::Connector::JDBC_DRIVER

Constants included from Constants

Constants::DEFAULT_LOGIN_TIMEOUT, Constants::MAX_STATEMENT_NESTING_LEVEL

Class Method Summary collapse

Class Method Details

.connect(host, user, password, db, timeout = DEFAULT_LOGIN_TIMEOUT, extra_params = DEFAULT_PARAMETERS[:postgres], &block) ⇒ JDBCHelper::Connection

Parameters:

  • host (String)
  • user (String)
  • password (String)
  • db (String)
  • timeout (Fixnum) (defaults to: DEFAULT_LOGIN_TIMEOUT)
  • extra_params (Hash) (defaults to: DEFAULT_PARAMETERS[:postgres])

Returns:



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/jdbc-helper/connector/postgres_connector.rb', line 17

def self.connect(host, user, password, db,
         timeout = DEFAULT_LOGIN_TIMEOUT, 
         extra_params = DEFAULT_PARAMETERS[:postgres], &block)

  if extra_params && extra_params.is_a?(Hash) == false
    raise ArgumentError.new('extra_params must be a hash')
  end

  conn = Connection.new(
    (extra_params || {}).merge(
      :driver   => JDBC_DRIVER[:postgres],
      :url      => "jdbc:postgresql://#{host}/#{db}",
      :user     => user,
      :password => password,
      :timeout  => timeout))

  block_given? ? ensure_close(conn, &block) : conn
end