Class: AtlConfig::JDBCURL

Inherits:
Object
  • Object
show all
Defined in:
lib/atl_config/jdbcurl.rb

Overview

TODO:

The mysql case doesn’t yet handle a blank hostname (‘jdbc:mysql:///dbname’), and certainly doesn’t handle multiple replication hosts.

Parses a JDBC URL in MySQL or Postgres formats.

Current status: postgres parsing works 100% mysql parsing works if the url looks like postgres’s, but with the support for properties.

Class Method Summary collapse

Class Method Details

.parse(jdbcurl) ⇒ Hash{:dbtype => String, :host => String, :port => Integer, :database => String, :props => {:propkey => String, :propval => String}]

Given a JDBC URL, returns its constituent parts.

Parameters:

  • jdbcurl

    String E.g. jdbc:mysql://localhost/wombles?foo=bar or jdbc:postgresql://dbserver:5432/mydb

Returns:

  • (Hash{:dbtype => String, :host => String, :port => Integer, :database => String, :props => {:propkey => String, :propval => String}])

    Hash=> String, :host => String, :port => Integer, :database => String, :props => {:propkey => String, :propval => String]



15
16
17
18
19
20
21
22
# File 'lib/atl_config/jdbcurl.rb', line 15

def self.parse(jdbcurl)
	# first we get a hash with Parslet values, then we to_s each value to prevent our user seeing Parslet stuff.
	begin
	stringify(JDBCURLParser.new.parse(jdbcurl))
	rescue Parslet::ParseFailed => failure
		raise failure.cause.ascii_tree
	end
end