Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

configure database if passed via uri.

  • Loading branch information...
commit 1fcee71ba33471be58f8cb4b58b83a0fbd5449dc 1 parent b4bd795
@wayneeseguin authored
Showing with 6 additions and 4 deletions.
  1. +6 −4 lib/psql-cm/database.rb
View
10 lib/psql-cm/database.rb
@@ -4,7 +4,7 @@ class Connection < Delegator
def initialize(options = {})
@config = ::PSQLCM.config.connection.merge(options)
- @config[:dbname] = options[:dbname] || 'postgres'
+ @config[:dbname] = options[:dbname] if options[:dbname]
super # For delegator pattern:
@delegated_object = db
@@ -84,15 +84,17 @@ def configure!
timeout = query.detect { |k| k.match /connect_timeout=/ }.to_s.sub(/.*=/,'')
sslmode = query.detect { |k| k.match /sslmode=/ }.to_s.sub(/.*=/,'')
- database = uri.path.split('/').first
- if database && ! @config.databases.detect { |name| name == database }
+ database = uri.path.split('/').first.to_s
+ database = @config[:dbname] if database.empty?
+
+ unless @config.databases.detect { |name| name == database }
@config.databases << database
end
@config.connection = {
:host => uri.host,
:port => uri.port || 5432,
- :dbname => "postgres", # uri.path.sub('/',''),
+ :dbname => database,
:user => uri.user || ENV['USER'],
:password => uri.password,
:connect_timeout => timeout.empty? ? 20 : timeout.to_i,
Please sign in to comment.
Something went wrong with that request. Please try again.