lib/dexter/indexer.rb in pgdexter-0.1.6 vs lib/dexter/indexer.rb in pgdexter-0.2.0
- old
+ new
@@ -1,18 +1,18 @@
module Dexter
class Indexer
include Logging
- def initialize(database_url, options)
- @database_url = database_url
+ def initialize(options)
@create = options[:create]
@log_level = options[:log_level]
@exclude_tables = options[:exclude]
@include_tables = Array(options[:include].split(",")) if options[:include]
@log_sql = options[:log_sql]
@log_explain = options[:log_explain]
@min_time = options[:min_time] || 0
+ @options = options
create_extension unless extension_exists?
execute("SET lock_timeout = '5s'")
end
@@ -309,22 +309,24 @@
new_indexes
end
def conn
@conn ||= begin
- uri = URI.parse(@database_url)
- config = {
- host: uri.host,
- port: uri.port,
- dbname: uri.path.sub(/\A\//, ""),
- user: uri.user,
- password: uri.password,
- connect_timeout: 3
- }.reject { |_, value| value.to_s.empty? }
+ if @options[:dbname] =~ /\Apostgres(ql)?:\/\//
+ config = @options[:dbname]
+ else
+ config = {
+ host: @options[:host],
+ port: @options[:port],
+ dbname: @options[:dbname],
+ user: @options[:user]
+ }.reject { |_, value| value.to_s.empty? }
+ config = config[:dbname] if config.keys == [:dbname] && config[:dbname].include?("=")
+ end
PG::Connection.new(config)
end
- rescue PG::ConnectionBad
- abort "Can't connect to database"
+ rescue PG::ConnectionBad => e
+ abort e.message
end
def execute(query)
# use exec_params instead of exec for security
#