Class: JDBCHelper::MySQLConnector

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

Overview

Shortcut connector for MySQL

Constant Summary

Constants included from Constants::Connector

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

Constants included from Constants

Constants::DEFAULT_LOGIN_TIMEOUT

Class Method Summary collapse

Class Method Details

.connect(host, user, password, db, timeout = DEFAULT_LOGIN_TIMEOUT, extra_params = DEFAULT_PARAMETERS[:mysql], &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[:mysql])

Returns:



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

def self.connect(host, user, password, db,
				 timeout = DEFAULT_LOGIN_TIMEOUT, 
				 extra_params = DEFAULT_PARAMETERS[:mysql], &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[:mysql],
			:url      => "jdbc:mysql://#{host}/#{db}",
			:user     => user,
			:password => password,
			:timeout  => timeout))

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