diff --git a/doc/opening_databases.rdoc b/doc/opening_databases.rdoc index 49eb7064d4..c431a17e02 100644 --- a/doc/opening_databases.rdoc +++ b/doc/opening_databases.rdoc @@ -342,6 +342,8 @@ The following additional options are supported: :charset :: Same as :encoding, :encoding takes precedence :encoding :: Set the client_encoding to the given string +:connect_timeout :: Set the number of seconds to wait for a connection (default 20, only respected + if using the pg library). === sqlite diff --git a/lib/sequel/adapters/postgres.rb b/lib/sequel/adapters/postgres.rb index 74880a64a3..ae4b4be516 100644 --- a/lib/sequel/adapters/postgres.rb +++ b/lib/sequel/adapters/postgres.rb @@ -218,16 +218,27 @@ def initialize(*args) # client encoding for the connection. def connect(server) opts = server_opts(server) - connection_params = { - :host => opts[:host], - :port => opts[:port] || 5432, - :tty => '', - :dbname => opts[:database], - :user => opts[:user], - :password => opts[:password], - :connect_timeout => opts[:connect_timeout] || 20 - }.delete_if { |key, value| blank_object?(value) } - conn = Adapter.connect(connection_params) + conn = if SEQUEL_POSTGRES_USES_PG + connection_params = { + :host => opts[:host], + :port => opts[:port] || 5432, + :tty => '', + :dbname => opts[:database], + :user => opts[:user], + :password => opts[:password], + :connect_timeout => opts[:connect_timeout] || 20 + }.delete_if { |key, value| blank_object?(value) } + Adapter.connect(connection_params) + else + Adapter.connect( + (opts[:host] unless blank_object?(opts[:host])), + opts[:port] || 5432, + nil, '', + opts[:database], + opts[:user], + opts[:password] + ) + end if encoding = opts[:encoding] || opts[:charset] if conn.respond_to?(:set_client_encoding) conn.set_client_encoding(encoding)