Skip to content

Commit

Permalink
Create connection with PG.connect
Browse files Browse the repository at this point in the history
  • Loading branch information
teeparham committed Aug 20, 2019
1 parent c9d4b48 commit 1f8142d
Showing 1 changed file with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,18 @@ def postgis_connection(config)
conn_params[:user] = conn_params.delete(:username) if conn_params[:username]
conn_params[:dbname] = conn_params.delete(:database) if conn_params[:database]

# Forward only valid config params to PGconn.connect.
# Forward only valid config params to PG.connect
valid_conn_param_keys = PG::Connection.conndefaults_hash.keys + [:requiressl]
conn_params.slice!(*valid_conn_param_keys)

# The postgres drivers don't allow the creation of an unconnected PGconn object,
# so just pass a nil connection object for the time being.
ConnectionAdapters::PostGISAdapter.new(nil, logger, conn_params, config)
conn = PG.connect(conn_params)
ConnectionAdapters::PostGISAdapter.new(conn, logger, conn_params, config)
rescue ::PG::Error => error
if error.message.include?(conn_params[:dbname])
raise ActiveRecord::NoDatabaseError
else
raise
end
end

end
Expand Down

0 comments on commit 1f8142d

Please sign in to comment.